Programme Flow Priority ?


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103

    Default Programme Flow Priority ?

    Hi ;

    This may be a very strange question but I need to ask this ;

    While we start over coding on PBP , should we first write the "define" parameters and then set the "registers" such as port , tris , ansel etc .

    I mean a code should be like exactly as below ? or the second one ?

    Code:
    #config
     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF 
     __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
    #ENDCONFIG
    
    
    define OSC 4
    
    
    OSCCON=%01101010
    PORTA=%00010000     :      TRISA=%00000000
    PORTB=%00000000     :      TRISB=%00001001
    OPTION_REG=%11111111
    ADCON0=%00000001    :      ADCON1=%10110000
    ANSELA=%00000       :      ANSELB=%00001000
    T1CON=%00110000      
    INTCON=%00000000
    
    
    DEFINE LCD_DREG PORTA 'LCD data port 
    DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4 
    DEFINE LCD_RSREG PORTA 'LCD register select port 
    DEFINE LCD_RSBIT 6 'LCD register select bit
    DEFINE LCD_RWREG PORTB   ' LCD read/write port
    DEFINE LCD_RWBIT 7   ' LCD read/write pin bit  
    DEFINE LCD_EREG PORTA 'LCD enable port 
    DEFINE LCD_EBIT 7 'LCD enable bit
    DEFINE LCD_BITS 4 'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2 'Number lines on LCD
    
    
    DEFINE ADC_BITS 10   ' Set number of bits in result
    DEFINE ADC_SAMPLEUS 100  ' Set sampling time in uS
    DEFINE ADC_CLOCK 3


    or just like this ?

    Code:
    #config
     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF 
     __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
    #ENDCONFIG
    
    
    define OSC 4
    
    
    
    
    
    
    DEFINE LCD_DREG PORTA 'LCD data port 
    DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4 
    DEFINE LCD_RSREG PORTA 'LCD register select port 
    DEFINE LCD_RSBIT 6 'LCD register select bit
    DEFINE LCD_RWREG PORTB   ' LCD read/write port
    DEFINE LCD_RWBIT 7   ' LCD read/write pin bit  
    DEFINE LCD_EREG PORTA 'LCD enable port 
    DEFINE LCD_EBIT 7 'LCD enable bit
    DEFINE LCD_BITS 4 'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2 'Number lines on LCD
    
    
    DEFINE ADC_BITS 10   ' Set number of bits in result
    DEFINE ADC_SAMPLEUS 100  ' Set sampling time in uS
    DEFINE ADC_CLOCK 3
    
    OSCCON=%01101010
    PORTA=%00010000     :      TRISA=%00000000
    PORTB=%00000000     :      TRISB=%00001001
    OPTION_REG=%11111111
    ADCON0=%00000001    :      ADCON1=%10110000
    ANSELA=%00000       :      ANSELB=%00001000
    T1CON=%00110000      
    INTCON=%00000000
    Thanks ..

  2. #2
    Join Date
    Sep 2009
    Posts
    678

    Default Re: Programme Flow Priority ?

    I's same...

  3. #3
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103

    Default Re: Programme Flow Priority ?

    Quote Originally Posted by pedja089 View Post
    I's same...
    An extra few words with an explanation would be so nice though ...

  4. #4
    Join Date
    Sep 2009
    Posts
    678

    Default Re: Programme Flow Priority ?

    Defines are just passed to ASM, so macros in lbr can include needed code to get all functions to work. And that is at beginning of program memory. User code is translated to asm, and put at end of function.
    If you look at disassembled code(eg in MPLAB), there is CLRF FLAGS(FLAGS is internal PBP variable used in LCDOUT, I2C etc functions), if is used. Then there is GOTO INIT. INIT is label at end of functions and user code starts from there.
    So PBP takes care to always put code affected by DEFINES at top, and then your code.
    I thing that PBP in first pass deal with defines, lib, variable allocation, etc, then in second pass deal with user code.

  5. #5
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103

    Default Re: Programme Flow Priority ?

    Thanks .. That was such a great explanation

Similar Threads

  1. PIC16F877 I2C programme
    By cooqo in forum mel PIC BASIC
    Replies: 3
    Last Post: - 21st April 2008, 10:02
  2. Terminal Programme
    By Adrian in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th December 2007, 18:15
  3. Priority interrupt?
    By Qacer in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th October 2006, 16:47
  4. Can you give varied levels of priority to blocks of code?
    By Archangel in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th August 2006, 01:58
  5. Blink Programme for 16F876
    By banjaxxed in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 13th April 2006, 00:03

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts