Hello Alan & PIC.ers,
----- Original Message -----
From: "alan smith" <micro_eng2
KILLspamyahoo.com>
To: "Microcontroller discussion list - Public." <.....piclistKILLspam
.....mit.edu>
Sent: Monday, May 09, 2005 3:14 PM
Subject: [PIC] : 18F, Macros and reusing labels inside
{Quote hidden}> I thought I read somewhere...here or elsewhere, that
> with the 18F series you can reuse labels inside a
> macro?
>
> I built and tested some macros then went to implement
> them in a few places and came up with duplicate labels
> upon building the file.
>
> So, can you do this, and if so, whats the trick?
>
> example as follows...on a 18F4680
>
> min_value macro cMSB,compMSB,cLSB,compLSB
>
> movf cMSB,w
> cpfsgt compMSB
> bra _minTstLsb
> movff cMSB,compMSB
> movff cLSB,compLSB
> bra _minDone
> _minTstLsb
> movf cLSB,w
> cpfsgt compLSB
> bra _minDone
> movff cMSB,compMSB
> movff cLSB,compLSB
> _minDone
> endm
>
>
>
This is quite easy, by declaring the labels as `local' within each macro
they don't fight each other.
e.g.:-
start_i2c MACRO ;[S]
local humf_01, humf_02
bcf PIR1,SSPIF
bsf SSPCON2,SEN ;send i2c START [S] bit
clrf isr_scratch_B1 ;`stuck-loop' error trap freg
humf_02
btfsC SSPCON2,SEN ;Wait for the Start condition to end,
bra humf_01 ;ie endm
decfsz isr_scratch_B1
bra humf_02 ;ie test again
bsf i2c_corrupt_S_flag ;causes i2c reset
humf_01
endm
stop_i2c MACRO ;[P]
local humf_01, humf_02
bcf PIR1,SSPIF
bsf SSPCON2,PEN ;send i2c STOP [P] bit
clrf isr_scratch_B0
humf_02
btfsC PIR1,SSPIF ;stop bit cycle completed
bra humf_01 ;ie endm
decfsz isr_scratch_B0
bra humf_02 ;ie test again
bsf i2c_corrupt_P_flag
humf_01
endm
bestos, John
email from the desk of John Sanderson.
web: http://www.jscontrols.co.za
email: EraseMEjohnspam_OUT
TakeThisOuTjscontrols.co.za
Tel: (027) 11 893 4154
Cell: 082 741 6275
Manufacturer and purveyor of force testing machines
and apparatus.