home *** CD-ROM | disk | FTP | other *** search
- 2nd September 1992
-
- Some more examples of Macros , again for the 8051
-
-
- ; --------------------------------------------------
- ; Macros for PROD Programs.
- ;
- ;
- #MACRO V_PLUG ID,TAG
- MOV ID,TAG
- RETI
- NOP
- NOP
- NOP
- NOP
- #MEND
- ;
- ;
- #MACRO UPDATE src,dest
- MOV C,src
- MOV dest,C
- #MEND
- ;
- ; Test option switch values stored in Ram
- ; jump if bit in mask is UNSET
- ;
- #MACRO INVERT bit
- MOV C,bit
- CPL C
- MOV bit,C
- #MEND
- ;
- ;
- ; --------------------------------------------------
- ; Short delay using R1 & R2
- ; Processer speed is 4MHz.
- ; 12 clocks / instruction.
- ; Delay time is given (approx) by:
- ;
- ; T(sec) = (9*Tdly)*3*10^-6
- ;
- #MACRO DELAY Tdly
- MOV R1,#(Tdly >>8) ; x1 Not counted
- MOV R2,#(Tdly &255) ; x1 Not counted
- ; L1
- MOV A,R2 ; x1
- ANL A,#03FH
- JNZ $+6 ; x1
- MOV DPTR,#DOG_ADDR
- MOVX @DPTR,A
- ; L2
- MOV A,R2
- CLR C ; x1
- SUBB A,#1 ; x1
- MOV R2,A ; x1
- MOV A,R1 ; x1
- SUBB A,#0 ; x1
- MOV R1,A ; x1
- JNC $-18 ; x1 Count was > 1
- #MEND
- ;
- ; add literal 16 to 16 bit number in 2 bytes.
- ; *Note assumed byte position...
- ;
- #MACRO ADD16 Kword,val
- MOV A,(Kword+0) ; add 1 to 16 bit number
- ADD A,#(val & 255 ) ;Lower byte
- MOV (Kword+0),A
- MOV A,#(val >> 8)
- ADDC A,(Kword+1) ;Upper byte
- MOV (Kword+1),A
- #MEND
- ;
- #MACRO SUB16 Kword,val
- MOV A,(Kword+0)
- CLR C
- SUBB A,#(val & 255 )
- MOV (Kword+0),A
- MOV A,(Kword+1)
- SUBB A,#(val >> 8)
- MOV (Kword+1),A
- #MEND
- ;
- #MACRO CJNE16 Kword,val,lab
- MOV A,(Kword+0) ; Test low Byte.
- CJNE A,#(val & 255),lab
- MOV A,(Kword+1)
- CJNE A,#(val >> 8),lab ; High byte.
- #MEND
- ;
- ; Load literal 16 bit constant to variable.
- ;
- #MACRO LIT16 dest,val
- MOV (dest+0),#(val & 255)
- MOV (dest+1),#(val >> 8)
- #MEND
- ;
- ; Jump if 16 bit var != 0
- ;
- #MACRO JNZ16 var,lab
- MOV A,(var+0)
- ORL A,(var+1)
- JNZ lab
- #MEND
- ;
- ; Jump if 16 bit var == 0
- ;
- #MACRO JZ16 var,lab
- MOV A,(var+0)
- ORL A,(var+1)
- JZ lab
- #MEND
- ;
- #MACRO JLT16 val,Tval,lab
- CLR C
- MOV A,(val+0)
- SUBB A,#( Tval & 255 )
- MOV A,(val+1)
- SUBB A,#( Tval >> 8 )
- JC lab
- #MEND
- ;
- #MACRO JGE16 val,Tval,lab
- CLR C
- MOV A,(val+0)
- SUBB A,#( Tval &255 )
- MOV A,(val+1)
- SUBB A,#( Tval >> 8 )
- JNC lab
- #MEND
- ;
- #MACRO JGT16 val,Tval,lab
- CLR C
- MOV A,(val+0)
- SUBB A,#( (Tval+1) &255 )
- MOV A,(val+1)
- SUBB A,#( (Tval+1) >> 8 )
- JNC lab
- #MEND
- ;
- ; Filter raw input data.
- ;
- ; inv : Flag 0 => normal 1==TRUE 1=> inverse 0==TRUE
- ; iput : input bit port address.
- ; icnt : Filter average counter.
- ; kval : Target after which input deemed TRUE.
- ; ibit : Soft input indicator bit used as input indicator
- ; by higher level code.
- ;
- ; The filter works by counting up to kval whilst the raw input
- ; is TRUE, and counting down to zero when it is FALSE.
- ; The input must be fairly consistently either TRUE or FALSE
- ; to reach either limit. It is a sort of average to eliminate
- ; the effect od switch bounce and possible vibration.
- ;
- #MACRO I_FILTER inv,iput,icnt,kval,ibit
- #IF (inv)
- JB iput,$+23
- #ELSE
- JNB iput,$+23
- #ENDIF
- ;
- ; Counting Up Because Input is TRUE...
- ;
- MOV A,icnt ; x2 Counter to Accumulator.
- CLR C ; x1 No borrow in subtract.
- SUBB A,#kval ; x2 carry bit set if A less
- JC $+9 ; x1 Still counting up..
- MOV icnt,#kval ; x2 Hold count at top.
- SETB ibit ; x1 Flag counted out.
- SJMP $+26 ; x2 OUT
- ; I1:
- NOP ; x1 Balance timings.
- NOP ; x1
- INC icnt ; x1
- SJMP $+20 ; x2
- ;
- ; Count up uses 11 cycles...
- ; Count down uses 5, so compensate with 6 NOPs
- ; code is always 21 cycles .
- ; Counting down because input is false.
- ;
- ; O1:
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- ;
- MOV A,icnt ; x1 Load counter
- JZ $+6 ; x1 miss if not active
- DEC icnt ; x1 correct back
- SJMP $+6 ; x2 miss flag
- ; O2:
- NOP ; x1
- NOP ; x1
- CLR ibit ; x1 remove flag set
- ; IOEX:
- #MEND
- ;
- #MACRO INCBRA cnt,kval,jlb
- MOV A,cnt
- JZ jlb
- INC cnt
- INC A
- CJNE A,#kval,jlb
- #MEND
- ;
- ; --------------------------------------------------
- ;
- #MACRO LIMCLR cnt,kval,ibit
- MOV A,cnt
- JZ $+13
- INC cnt
- INC A
- CJNE A,#kval,$+8
- CLR ibit
- MOV cnt,#0
- ; L1:
- #MEND
-
- ;
- ; --------------------------------------------------
- ;
- #MACRO NOTSWJMP swbit,Lab
- JNB swbit,Lab ; Jump if UNSET
- #MEND
- ;
- ; Test option switch values stored in Ram
- ; jump if bit in mask is SET
- ;
- #MACRO SWJMP swbit,Lab
- JB swbit,Lab ; Jump if SET
- #MEND
- ;
- ; Filter raw input data with optional signal inversion.
- ;
- ; inv : Flag 0 => normal 1==TRUE 1=> inverse 0==TRUE
- ; opt : option switch mask.
- ; iput : input bit port address.
- ; icnt : Filter average counter.
- ; kval : Target after which input deemed TRUE.
- ; ibit : Soft input indicator bit used as input indicator
- ; by higher level code.
- ;
- #MACRO I_O_FILTER inv,opt,iput,icnt,kval,ibit
- #IF inv
- ; Declared Normal.
- JNB opt,$+8 ; E1 x1 Jump if installed
- #ELSE
- ; Declared Inverted.
- JB opt,$+8 ; E1 x1 Jump if not installed
- #ENDIF
- JNB iput,$+30 ; x1
- SJMP $+7 ; E2 x2
- ;; E1:
- JB iput,$+25 ; O1 x1
- NOP ; x1
- NOP ; x1
- ;; E2:
- ; above always uses 6 cycles..
- ;
- ; Counting Up Because Input is TRUE...
- ;
- MOV A,icnt ; x2 Counter to Accumulator.
- CLR C ; x1 No borrow in subtract.
- SUBB A,#kval ; x2 carry bit set if A less
- JC $+9 ; I1 x1 Still counting up..
- MOV icnt,#kval ; x2 Hold count at top.
- SETB ibit ; x1 Flag counted out.
- SJMP $+26 ; x2 OUT
- ;; I1:
- NOP ; x1 Balance timings.
- NOP ; x1
- INC icnt ; x1
- SJMP $+20 ; IOEX x2
- ;; O1:
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- ;
- MOV A,icnt ; x1 Load counter
- JZ $+6 ; x1 miss if not active
- DEC icnt ; x1 correct back
- SJMP $+6 ; x2 miss flag
- ;;O2:
- NOP ; x1
- NOP ; x1
- CLR ibit ; x1 remove flag set
- ;;IOEX:
- #MEND
- ;
- ; --------------------------------------------------
- ;
-
- #MACRO FRONT_ACTION ibit,oibit,time,Abit,LAbit
- #IFDEF FD_LEAVE_OPEN
- JNB ibit,$+33
- JB Ign,$+30
- JB oibit,$+27
- #ELSE
- JNB ibit,$+30
- JB Ign,$+27
- #ENDIF
- JBC Exit,$+14
- JB Access,$+21
- MOV A,DRd0cnt
- JNZ $+17
- ;
- SETB Abit
- SJMP $+12
- MOV A,#time
- MOV Acccnt,A
- SETB Access
- #IFDEF TWO_BEEP_EX
- MOV W2BCnt,A
- CLR W2BFlg
- #ELSE
- NOP
- NOP
- NOP
- NOP
- #ENDIF
- #MEND
-
-
-
-