PDA

View Full Version : Programme Flow Priority ?



gunayburak
- 9th August 2014, 13:56
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 ?



#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 ?



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

pedja089
- 9th August 2014, 17:00
I's same...

gunayburak
- 9th August 2014, 17:30
I's same...

An extra few words with an explanation would be so nice though ...

pedja089
- 9th August 2014, 18:42
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.

gunayburak
- 9th August 2014, 23:20
Thanks .. That was such a great explanation