Proton BASIC Compiler - How a program should look

  • PicŪ Basic

  • How a program should look

    This is an example of how a program should look and the basic format it should have. There are variations but this should be a place to start. This is not a complete setup, but should act as a guide only. Keep your code neat and organised, it makes it easy to work with. Look at other code examples.


    Device = 16F684 ' Define the Pic processor
    Xtal = 4 ' Define the clock speed so timing works out in the program
    Config_Start ' Define the pic fuses configuration here
    ' This tells the pic how it is configured to start up
    ' See the Fuse Configurator Plugin
    TRISA = 011011 ' Configure I/O on port A
    TRISB = 011111 ' Configure I/O on port B
    TRISC = 000000 ' Configure I/O on port C or however many ports there are
    ' All ports must be configured otherwise the default setting
    ' will apply and they may not be what you want them to be
    ' 0 = Output, and a 1 = Input. Define unused pins as Outputs
    CMCON = 000111 ' disable comparators if the pic have them and they are not used
    ' They are ENABLED by default
    ' Define peripheral and other registers here.
    ' If you are not going to use it, don't define it
    ADCON0 = 001101
    ' Alias the pins you are going to use on the ports.
    ' Anywhere in the code where you refer to Pot1 the pic will now know it is PortA.0
    Symbol Pot1 = PORTA.0 ' Pot 1 A/D Input
    Symbol Pot2 = PORTA.1 ' Pot 2 A/D Input
    Symbol NC01 = PORTA.2 ' Not Used Output
    'Define other aliasses for bits in registers you intend to use
    Symbol GIE = INTCON.7 ' Global Int En Bit
    Symbol Go_Done = ADCON0.1
    ' Define the variables you use in the program.
    ' These can be added as you develop a need for them during programming
    Dim Coun As Dword '
    Dim Revs As Word
    Dim Temp As Byte ' temp genl use reg
    Dim A As Bit ' A = flag to check
    'If interrupts are not used then omit the following -
    '************************************************* *********************
    '* Set up interrupts
    '************************************************* *********************
    On Interrupt GoTo Label
    Goto Start 'jump over the Interrupt subroutine to program start
    '************************************************* **************************
    '* Interrupt Handler When an interrupt occurs the code will jump to here
    '************************************************* **************************
    Label: ' This is a program label or marker
    ' Do NOT execute part of the program here
    ' The idea is only to see what interrupted you
    ' Set a flag ie A = 1 or BSF Temp.1 or BSF Temp.5
    ' Then handle the required action elsewhere ie in the main loop.
    ' Interrupt code is here
    '************************************************* *********************
    '* Set up Preprocessor
    '************************************************* *********************
    ' The following code will be placed in the code whenever you use Flash
    $define Flash '
    LED = 1 '
    Delayms 200 '
    LED = 0 '
    Delayms 300
    '************************************************* ********************
    '* Main Program Starts Here
    '************************************************* ********************
    Start: ' It is important to use labels so the code has references where to jump to
    LED = 1
    Gosub Timer1 ' Call a subroutine
    Led = 0 ' Subroutine will return to this line
    goto Start1 ' Code jumps to label Start1
    ' Fast Flash here
    Flash ' The pre-processor code is inseted here
    If A = 1 then LED = 1 : A = 0 ' Interrupt occurred, LED On, reset flag
    Goto Start ' Jump to label Start
    '************************************************* ********************
    '* Sub Routines are Here -
    '************************************************* ********************
    ' A Subroutine is code you use over and over by jumping to it and back from within the program
    ' Timer Delay
    Delayms 2000
    Return ' Return to the next line from where the subroutine was calledEnd ' End of program statement
  • Recent Activity


    18F47K40 Port B issue

    Thread Starter: geoff_c

    Im having a problem with Port B on the 18F47K40. This is the first time Ive used a micro with the PPS so im guessing i missed something simple. Port...

    geoff_c Today, 07:35 Go to last post

    Migrating a monitored alarm from copper to GSM.

    Thread Starter: david

    Hi All, I need to migrate a monitored house alarm from the present copper line to GSM so we can eventually adopt a fiber system that the telcos are...

    david Today, 07:23 Go to last post

    Baud rate problem

    Thread Starter: charliecoultas

    I am trying to run one of the USARTs on a 24HJ128GP502 at 115,200 bits/second. I thought I had defined the clock frequency wrong but Delayms gives...

    charliecoultas Today, 09:07 Go to last post