home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / tasm / expand_ex / 3p_MAC < prev    next >
Encoding:
Text File  |  1992-09-02  |  8.1 KB  |  333 lines

  1.          2nd September 1992
  2.          
  3.          Some more examples of Macros , again for the 8051
  4.  
  5.  
  6. ;         --------------------------------------------------
  7. ;         Macros for PROD Programs.
  8. ;
  9. ;
  10. #MACRO  V_PLUG  ID,TAG
  11.            MOV  ID,TAG
  12.            RETI
  13.            NOP
  14.            NOP
  15.            NOP
  16.            NOP
  17. #MEND
  18. ;
  19. ;
  20. #MACRO  UPDATE  src,dest
  21.            MOV  C,src
  22.            MOV  dest,C
  23. #MEND
  24. ;
  25. ;         Test option switch values stored in Ram
  26. ;         jump if bit in mask is UNSET
  27. ;
  28. #MACRO  INVERT  bit
  29.            MOV  C,bit
  30.            CPL  C
  31.            MOV  bit,C
  32. #MEND
  33. ;
  34. ;
  35. ;         --------------------------------------------------
  36. ;         Short delay using R1 & R2
  37. ;         Processer speed is 4MHz.
  38. ;         12 clocks / instruction.
  39. ;         Delay time is given (approx) by:
  40. ;
  41. ;         T(sec) = (9*Tdly)*3*10^-6
  42. ;
  43. #MACRO  DELAY   Tdly
  44.            MOV  R1,#(Tdly >>8)  ; x1 Not counted
  45.            MOV  R2,#(Tdly &255) ; x1 Not counted
  46. ; L1
  47.            MOV  A,R2    ; x1
  48.            ANL  A,#03FH
  49.            JNZ  $+6     ; x1
  50.            MOV  DPTR,#DOG_ADDR
  51.            MOVX    @DPTR,A
  52. ; L2
  53.            MOV  A,R2
  54.            CLR  C         ; x1
  55.            SUBB    A,#1    ; x1
  56.            MOV  R2,A    ; x1
  57.            MOV  A,R1    ; x1
  58.            SUBB    A,#0    ; x1
  59.            MOV  R1,A    ; x1
  60.            JNC  $-18    ; x1 Count was > 1
  61. #MEND
  62. ;
  63. ;         add literal 16 to 16 bit number in 2 bytes.
  64. ;         *Note assumed byte position...
  65. ;
  66. #MACRO  ADD16   Kword,val
  67.            MOV  A,(Kword+0)     ; add 1 to 16 bit number
  68.            ADD  A,#(val & 255 ) ;Lower byte
  69.            MOV  (Kword+0),A
  70.            MOV  A,#(val >> 8)
  71.            ADDC    A,(Kword+1)  ;Upper byte
  72.            MOV  (Kword+1),A
  73. #MEND
  74. ;
  75. #MACRO  SUB16   Kword,val
  76.            MOV  A,(Kword+0)
  77.            CLR  C
  78.            SUBB    A,#(val & 255 )
  79.            MOV  (Kword+0),A
  80.            MOV  A,(Kword+1)
  81.            SUBB    A,#(val >> 8)
  82.            MOV  (Kword+1),A
  83. #MEND
  84. ;
  85. #MACRO  CJNE16  Kword,val,lab
  86.            MOV  A,(Kword+0)     ; Test low Byte.
  87.            CJNE    A,#(val & 255),lab
  88.            MOV  A,(Kword+1)
  89.            CJNE    A,#(val >> 8),lab ; High byte.
  90. #MEND
  91. ;
  92. ;         Load literal 16 bit constant to variable.
  93. ;
  94. #MACRO  LIT16   dest,val
  95.            MOV  (dest+0),#(val & 255)
  96.            MOV  (dest+1),#(val >> 8)
  97. #MEND
  98. ;
  99. ;         Jump if 16 bit var != 0
  100. ;
  101. #MACRO  JNZ16   var,lab
  102.            MOV  A,(var+0)
  103.            ORL  A,(var+1)
  104.            JNZ  lab
  105. #MEND
  106. ;
  107. ;         Jump if 16 bit var == 0
  108. ;
  109. #MACRO  JZ16    var,lab
  110.            MOV  A,(var+0)
  111.            ORL  A,(var+1)
  112.            JZ    lab
  113. #MEND
  114. ;
  115. #MACRO  JLT16   val,Tval,lab
  116.            CLR  C
  117.            MOV  A,(val+0)
  118.            SUBB    A,#( Tval & 255 )
  119.            MOV  A,(val+1)
  120.            SUBB    A,#( Tval >> 8 )
  121.            JC    lab
  122. #MEND
  123. ;
  124. #MACRO  JGE16   val,Tval,lab
  125.            CLR  C
  126.            MOV  A,(val+0)
  127.            SUBB    A,#(  Tval &255 )
  128.            MOV  A,(val+1)
  129.            SUBB    A,#( Tval >> 8 )
  130.            JNC  lab
  131. #MEND
  132. ;
  133. #MACRO  JGT16   val,Tval,lab
  134.            CLR  C
  135.            MOV  A,(val+0)
  136.            SUBB    A,#( (Tval+1) &255 )
  137.            MOV  A,(val+1)
  138.            SUBB    A,#( (Tval+1) >> 8 )
  139.            JNC  lab
  140. #MEND
  141. ;
  142. ;         Filter raw input data.
  143. ;
  144. ;         inv   : Flag 0 => normal 1==TRUE  1=> inverse 0==TRUE
  145. ;         iput    : input bit port address.
  146. ;         icnt    : Filter average counter.
  147. ;         kval    : Target after which input deemed TRUE.
  148. ;         ibit    : Soft input indicator bit used as input indicator
  149. ;         by higher level code.
  150. ;
  151. ;         The filter works by counting up to kval whilst the raw input
  152. ;         is TRUE, and counting down to zero when it is FALSE.
  153. ;         The input must be fairly consistently either TRUE or FALSE
  154. ;         to reach either limit. It is a sort of average to eliminate
  155. ;         the effect od switch bounce and possible vibration.
  156. ;
  157. #MACRO  I_FILTER           inv,iput,icnt,kval,ibit
  158. #IF     (inv)
  159.            JB    iput,$+23
  160. #ELSE
  161.            JNB  iput,$+23
  162. #ENDIF
  163. ;
  164. ;         Counting Up Because Input is TRUE...
  165. ;
  166.            MOV  A,icnt  ; x2 Counter to Accumulator.
  167.            CLR  C         ; x1 No borrow in subtract.
  168.            SUBB    A,#kval  ; x2 carry bit set if A less
  169.            JC    $+9    ; x1 Still counting up..
  170.            MOV  icnt,#kval       ; x2 Hold count at top.
  171.            SETB    ibit    ; x1 Flag counted out.
  172.            SJMP    $+26    ; x2 OUT
  173. ; I1:
  174.            NOP  ; x1 Balance timings.
  175.            NOP  ; x1
  176.            INC  icnt    ; x1
  177.            SJMP    $+20    ; x2
  178. ;
  179. ;         Count up uses 11 cycles...
  180. ;         Count down uses 5, so compensate with 6 NOPs
  181. ;         code is always 21 cycles .
  182. ;         Counting down because input is false.
  183. ;
  184. ;  O1:
  185.            NOP
  186.            NOP
  187.            NOP
  188.            NOP
  189.            NOP
  190.            NOP
  191. ;
  192.            MOV  A,icnt  ; x1 Load counter
  193.            JZ    $+6    ; x1 miss if not active
  194.            DEC  icnt    ; x1 correct back
  195.            SJMP    $+6  ; x2 miss flag
  196. ; O2:
  197.            NOP  ; x1
  198.            NOP  ; x1
  199.            CLR  ibit    ; x1 remove flag set
  200. ; IOEX:
  201. #MEND
  202. ;
  203. #MACRO  INCBRA  cnt,kval,jlb
  204.            MOV  A,cnt
  205.            JZ    jlb
  206.            INC  cnt
  207.            INC  A
  208.            CJNE    A,#kval,jlb
  209. #MEND
  210. ;
  211. ;         --------------------------------------------------
  212. ;
  213. #MACRO  LIMCLR  cnt,kval,ibit
  214.            MOV  A,cnt
  215.            JZ    $+13
  216.            INC  cnt
  217.            INC  A
  218.            CJNE    A,#kval,$+8
  219.            CLR  ibit
  220.            MOV  cnt,#0
  221. ;  L1:
  222. #MEND
  223.  
  224. ;
  225. ;         --------------------------------------------------
  226. ;
  227. #MACRO  NOTSWJMP           swbit,Lab
  228.            JNB  swbit,Lab         ; Jump if UNSET
  229. #MEND
  230. ;
  231. ;         Test option switch values stored in Ram
  232. ;         jump if bit in mask is SET
  233. ;
  234. #MACRO  SWJMP   swbit,Lab
  235.            JB    swbit,Lab        ; Jump if SET
  236. #MEND
  237. ;
  238. ;         Filter raw input data with optional signal inversion.
  239. ;
  240. ;         inv   : Flag 0 => normal 1==TRUE  1=> inverse 0==TRUE
  241. ;         opt   : option switch mask.
  242. ;         iput    : input bit port address.
  243. ;         icnt    : Filter average counter.
  244. ;         kval    : Target after which input deemed TRUE.
  245. ;         ibit    : Soft input indicator bit used as input indicator
  246. ;         by higher level code.
  247. ;
  248. #MACRO  I_O_FILTER       inv,opt,iput,icnt,kval,ibit
  249. #IF     inv
  250. ;         Declared Normal.
  251.            JNB  opt,$+8 ; E1 x1 Jump if installed
  252.            #ELSE
  253. ;         Declared Inverted.
  254.            JB    opt,$+8 ; E1 x1 Jump if not installed
  255. #ENDIF
  256.            JNB  iput,$+30         ; x1
  257.            SJMP    $+7  ;  E2 x2
  258. ;; E1:
  259.            JB    iput,$+25        ; O1 x1
  260.            NOP  ; x1
  261.            NOP  ; x1
  262. ;; E2:
  263. ;         above always uses 6 cycles..
  264. ;
  265. ;         Counting Up Because Input is TRUE...
  266. ;
  267.            MOV  A,icnt  ; x2 Counter to Accumulator.
  268.            CLR  C         ; x1 No borrow in subtract.
  269.            SUBB    A,#kval ; x2 carry bit set if A less
  270.            JC    $+9    ; I1  x1 Still counting up..
  271.            MOV  icnt,#kval       ; x2 Hold count at top.
  272.            SETB    ibit    ; x1 Flag counted out.
  273.            SJMP    $+26    ; x2 OUT
  274. ;; I1:
  275.            NOP  ; x1 Balance timings.
  276.            NOP  ; x1
  277.            INC  icnt    ; x1
  278.            SJMP    $+20    ; IOEX x2
  279. ;; O1:
  280.            NOP
  281.            NOP
  282.            NOP
  283.            NOP
  284.            NOP
  285.            NOP
  286. ;
  287.            MOV  A,icnt  ; x1 Load counter
  288.            JZ    $+6    ; x1 miss if not active
  289.            DEC  icnt    ; x1 correct back
  290.            SJMP    $+6  ; x2 miss flag
  291. ;;O2:
  292.            NOP  ; x1
  293.            NOP  ; x1
  294.            CLR  ibit    ; x1 remove flag set
  295. ;;IOEX:
  296. #MEND
  297. ;
  298. ;         --------------------------------------------------
  299. ;
  300.  
  301. #MACRO  FRONT_ACTION    ibit,oibit,time,Abit,LAbit
  302. #IFDEF  FD_LEAVE_OPEN
  303.            JNB  ibit,$+33
  304.            JB    Ign,$+30
  305.            JB    oibit,$+27
  306. #ELSE
  307.            JNB  ibit,$+30
  308.            JB    Ign,$+27
  309. #ENDIF
  310.            JBC  Exit,$+14
  311.            JB    Access,$+21
  312.            MOV  A,DRd0cnt
  313.            JNZ  $+17
  314. ;
  315.            SETB    Abit
  316.            SJMP    $+12
  317.            MOV  A,#time
  318.            MOV  Acccnt,A 
  319.            SETB    Access
  320. #IFDEF  TWO_BEEP_EX
  321.            MOV  W2BCnt,A
  322.            CLR  W2BFlg
  323. #ELSE
  324.            NOP
  325.            NOP
  326.            NOP
  327.            NOP
  328. #ENDIF
  329. #MEND
  330.  
  331.  
  332.  
  333.