• 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.

    Please note that 'ALL_DIGITAL = TRUE' is NOT A SUBSTITUTE FOR SETTING YOUR PIC UP !!




    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
    Config_End
    TRISA = %11011011 ' Configure I/O on port A
    TRISB = %00011111 ' Configure I/O on port B
    TRISC = %00000000 ' 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 = %00000111 ' 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
    OSCCON.6=1
    ADCON0 = %00001101
    ' 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
    Resume
    Enable
    '************************************************* *********************
    '* 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
    Start1:
    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
    Timer1:
    Delayms 2000
    Return ' Return to the next line from where the subroutine was calledEnd ' End of program statement
  • Recent Activity

    teo-16018

    Microsoft security essentials blues

    Thread Starter: shantanu@india

    Hi, A strange thing happened just now.My Windows 7 Micrsoft Sercurity Essentials suddenly gave a warning that prplus.exe(Compiler) is a potential...

    teo Today, 19:23 Go to last post
    barak-1433

    SPI mssp

    Thread Starter: picprotonguy

    Just ordered Digital to Analog IC MCP4822 with SPI interface and immediately opened proton manual. I'm very disappointed, it looks like Proton...

    barak Today, 22:50 Go to last post
    David Barker-251

    UMC bootloader 18F46K22

    Thread Starter: shunt010

    Hi all. I am trying to build a UMC bootloader file for the 18F46K22, and it doesn't appear to work. It returns (in the error log) Error ...

    David Barker Today, 11:20 Go to last post