home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s230 / 2.ddi / DEMO96.ASM next >
Encoding:
Assembly Source File  |  1979-12-31  |  6.1 KB  |  296 lines

  1. ; Demo96.ASM    8096 Simulator Demonstration
  2.  
  3. ; This program monitors Analog Channel 3, and
  4. ; changes operating states between "Rising"
  5. ; and "Falling", depending on a comparison
  6. ; between the current analog value and predefined
  7. ; high and low threshold values.  When the value is
  8. ; between the thresholds, the state is not changed.
  9.  
  10. ; In the "Rising" state, an embedded macro is invoked
  11. ; that increases the analog value, while in the
  12. ; "Falling" state, an embedded macro is invoked to
  13. ; decrease the analog value.
  14.  
  15. Fseg    ; Special Function Regs
  16.  
  17. R0    word 00h
  18. AD_Cmd    data 02h
  19. ADResL    data 02h
  20. ADResH    data 03h
  21. HSIMode data 03h
  22. HSITime word 04h
  23. HSOTime word 04h
  24. HSIStat data 06h
  25. HSOCmd    data 06h
  26. SBUF_Rx data 07h
  27. SBUF_Tx data 07h
  28. IntMask data 08h
  29. IntPend data 09h
  30. WDogClr data 0Ah
  31. T1    word 0Ah
  32. T2    word 0Ch
  33. Baud    data 0Eh
  34. P0    data 0Eh
  35. P1    data 0Fh
  36. P2    data 10h
  37. SPCon    data 11h
  38. SPStat    data 11h
  39. IOC0    data 15h
  40. IOS0    data 15h
  41. IOC1    data 16h
  42. IOS1    data 16h
  43. PWMCtrl data 17h
  44.  
  45. endS
  46.  
  47. ;    Data Definitions
  48.  
  49. AX    WORD 24h   ; Word register
  50. Val1    Equ  7532h ; Integer value
  51. SP    word 18h   ; Stack Pointer
  52. AL    data AX    ; byte components
  53. AH    data AX+1
  54. BX    word 28h
  55. BL    data BX
  56. BH    data BX+1
  57. CX    word 2Ah
  58. CL    data CX
  59. CH    data CX+1
  60. DX    word 32h
  61. DL    data DX
  62. DH    data DX+1
  63.  
  64. SerStat data 52h
  65. SerData data 53h
  66. P2Image data 54h
  67.  
  68. AnStat     data 56h ; for status tests
  69. UpBit     equ 02   ; steering bit
  70. AnValue  data 58h ; data holding word
  71. HiThresh equ 401  ; upper threshold
  72. LoThresh equ 297  ; lower threshold
  73.  
  74. ;%S    Copyright 1985 Cybernetic Micro Systems, Inc.
  75.  
  76. org 2000h    ; Interrupt Vectors
  77.  
  78. dw TimerInt
  79. dw ADConvInt
  80. dw HSIDataInt
  81. dw HSOLineInt
  82. dw HSIzeroInt
  83. dw SoftHSOInt
  84. dw SerialInt
  85. dw ExtInt
  86. dw TRAPInt
  87.  
  88.  
  89. Org 2080h    ; powerup reset address
  90.  
  91. ; Initialize various hardware functions
  92.  
  93. Start:
  94. ld  SP,#0A0h    ; stack area
  95. ld  AX,#42h
  96. ld  CX,AX
  97. add BX,[CX]+
  98. add DX,76h[AX]
  99.  
  100. ; Define two macros, one to increase the
  101. ; analog voltage on channel 3, the other
  102. ; to decrease it.
  103.  
  104. ldb AH,AL
  105. ldb CL,#26    ;!3 A3+47,; Analog Voltage Rising
  106. ldb BL,[CX]
  107. ldb DH,2000h[AX] ;!4 A3-25,; Analog Voltage Falling
  108.  
  109.  
  110. ClearDog:      ;:Enable Watch Dog
  111. ldb WDogClr,#01Eh
  112. ldb WDogClr,#0E1h ; clear watch dog
  113.  
  114. PWM_On:      ;:Set PWM
  115. ldb PWMCtrl,#25h ; turn on PWM
  116.  
  117. AtoD_On:    ;:A/D Value
  118. ldb 26h,#0Bh    ; channel 3 to start
  119. ldb AD_Cmd,26h    ; get initial value
  120.  
  121. add 46h,04    ; unload HSI FIFO
  122.  
  123. HSOLineOn:    ;:High Speed CAM On
  124. ldb HSOCmd,#31h ; set HSO line 1
  125. ldb 47h,#31h    ; record of HSO cmd
  126. ld  48h,#10h
  127. add 48h,T1    ; get T1 + 10h
  128. ld  HSOTime,48h ; write time to HSO
  129.  
  130. SerialOn:    ;:Enable Serial
  131. ldb Baud,#11h    ; baud rate 8011h
  132. ldb Baud,#80h
  133. ldb SPCon,#09h     ; mode 1, REN
  134. ldb SerStat,#20h ; Transmitter ready
  135.  
  136. InterruptsOn:
  137. ldb IOC0,#55h      ; IOC0, enable HSI lines
  138. ldb IOC1,#02Dh      ; IOC1, PWM,T1,T2,TxD
  139. ldb P2Image,#0C1h ; initial Port 2 outputs
  140. ldb IntMask,#0FFh ; enable all interrupts
  141. ei
  142. ldb AnStat,#04h   ; set status byte, set a value
  143. ld  AnValue,#LoThresh+100
  144.  
  145. ; Main Program Loop
  146.  
  147. MainLoop:
  148. incb 73
  149. add AX,#21h
  150. orb P2Image,#80h
  151. ldb P2,P2Image    ; set P2.7
  152. inc 36H
  153. ld  58,#Val1    ; 16 bit data, LSB first
  154.  
  155. ; Only check the analog state while byte 36h,
  156. ; bit 2 is low.  36h incremented once per loop.
  157.  
  158. jbs 36h,2,SkipChk ;?Skip Tests
  159.  
  160. scall Test_Analog
  161.  
  162. shr AX,#5
  163. xor AX,58    ; modify AX
  164.  
  165. SkipChk:
  166. andb P2Image,#NOT 80h
  167. ldb P2,P2Image    ; clear P2.7
  168. mulb 92h,CL,BL
  169.  
  170.  
  171. ; Branch to Up or Down routine, depending on
  172. ; state set by TestAnalog subroutine
  173.  
  174. jbs AnStat,UpBit,GoingUp ;?Rising Value
  175.  
  176. ; Change P1 value for DeCrementing, and
  177. ; lower analog value through embedded macro
  178.  
  179. GoingDown:     ;:Falling Analog
  180. ldb P1,#0DCh     ; decrementing
  181. add AX,#Val1-385 ;#4
  182. ldb CL,73     ; copy byte 73 to CL
  183. sjmp MainLoop
  184.  
  185. ; Change P1 value for AdDing, and raise
  186. ; analog value through embedded macro
  187.  
  188. GoingUp:    ;:Rising Analog
  189. ldb P1,#0ADh    ; incrementing
  190. ldb DL,73    ;#3
  191. sub AX,#Val1+567
  192. sjmp MainLoop
  193.  
  194. ; Start a new conversion if one is not in
  195. ; progress.  Use the old converted value to
  196. ; check against the threshold.    If above the
  197. ; high threshold, set the "Falling" state and
  198. ; drive P2.6 low.  If below the low threshold,
  199. ; set the "Rising" state and drive P2.6 high.
  200.  
  201. Test_Analog:        ;:Threshold Check
  202. jbs ADResL,3,ConvOK ;?In Process
  203. ldb AD_Cmd,26h        ; else start a new conversion
  204.  
  205. ConvOK:
  206. cmp AnValue,#HiThresh
  207. jge OverMax          ;?Max Value
  208. cmp AnValue,#LoThresh
  209. jlt UnderMin          ;?Min Value
  210. NoChange:
  211. ret
  212.  
  213. OverMax:          ;:Upper Limit
  214. ldb AnStat,#Not 04h   ; switch to down mode
  215. andb P2Image,#Not 40h ; make P2.6 low
  216. ret
  217.  
  218. UnderMin:          ;:Lower Limit
  219. ldb AnStat,#04h       ; switch to up mode
  220. andb P2Image,#40h     ; make P2.6 high
  221. ret
  222.  
  223. TimerInt:          ;:Timer Int
  224. ret
  225.  
  226. ADConvInt:          ;:A/D Int
  227. ldb AnValue,ADResL    ; get low result
  228. ldb AnValue+1,ADResH  ; and high
  229. shr AnValue,#6          ; align to bytes
  230. ret
  231.  
  232. HSIDataInt:          ;:HSI Event
  233. ldb 43h,HSIStat       ; get status
  234. ld  44h,HSITime       ; get HSI time
  235. ret
  236.  
  237. HSOLineInt:          ;:HSO Line
  238. pushf              ; disable ints
  239. incb 47h          ; record of HSO cmd
  240. jbc 47h,3,HSO_Ok      ;?Cmd OK
  241. xorb 47h,#20h          ; change set/clear bit
  242. HSO_Ok:
  243. andb 47h,#37h
  244. ldb HSOCmd,47h          ; set HSO cmd
  245. ld  48h,#25h
  246. add 48h,T1          ; get T1 + 25h
  247. ld  HSOTime,48h       ; write time to HSO
  248. popf
  249. ret
  250.  
  251. HSIzeroInt:          ;:HSI.0 Int
  252. ret
  253.  
  254. SoftHSOInt:          ;:HSO Timer
  255. pushf
  256. incb 4Bh
  257. jbc 4Bh,2,ValOK       ;?Not C or D
  258. orb 4Bh,#02h
  259. ValOK:
  260. andb 4Bh,#0Fh
  261. orb 4Bh,#38h          ; HSO events 8 - F
  262. ldb HSOCmd,4Bh
  263. ld  48h,#22h
  264. add 48h,0Ah          ; T1 + 22h
  265. ld  HSOTime,48h       ; set HSO time
  266. popf
  267. ret
  268.  
  269. SerialInt:          ;:Serial Data
  270. orb SerStat,SPStat    ; preserve status bits
  271. jbc SerStat,6,ChkTx   ;?Not Receiver
  272. andb SerStat,#NOT 40h ; clear RI bit
  273. ldb SerData,Sbuf_Rx   ; read receiver
  274.  
  275. ChkTx:
  276. jbc SerStat,5,SerDone ;?Not Transmitter
  277. andb SerStat,#NOT 20h ; clear TI bit
  278. ldb Sbuf_Tx,AH          ; write a char
  279.  
  280. SerDone:
  281. ret
  282.  
  283. ExtInt:           ;:External Int
  284. ldb WDogClr,#01Eh
  285. ldb WDogClr,#0E1h     ; clear watch dog
  286. ret
  287.  
  288. TRAPInt:          ;:TRAP Instr
  289. ret
  290.  
  291. nop
  292.  
  293. ;%E    Copyright 1985 Cybernetic Micro Systems, Inc.
  294.  
  295. END START          ; Starting Address
  296.