home *** CD-ROM | disk | FTP | other *** search
- ; Demo96.ASM 8096 Simulator Demonstration
-
- ; This program monitors Analog Channel 3, and
- ; changes operating states between "Rising"
- ; and "Falling", depending on a comparison
- ; between the current analog value and predefined
- ; high and low threshold values. When the value is
- ; between the thresholds, the state is not changed.
-
- ; In the "Rising" state, an embedded macro is invoked
- ; that increases the analog value, while in the
- ; "Falling" state, an embedded macro is invoked to
- ; decrease the analog value.
-
- Fseg ; Special Function Regs
-
- R0 word 00h
- AD_Cmd data 02h
- ADResL data 02h
- ADResH data 03h
- HSIMode data 03h
- HSITime word 04h
- HSOTime word 04h
- HSIStat data 06h
- HSOCmd data 06h
- SBUF_Rx data 07h
- SBUF_Tx data 07h
- IntMask data 08h
- IntPend data 09h
- WDogClr data 0Ah
- T1 word 0Ah
- T2 word 0Ch
- Baud data 0Eh
- P0 data 0Eh
- P1 data 0Fh
- P2 data 10h
- SPCon data 11h
- SPStat data 11h
- IOC0 data 15h
- IOS0 data 15h
- IOC1 data 16h
- IOS1 data 16h
- PWMCtrl data 17h
-
- endS
-
- ; Data Definitions
-
- AX WORD 24h ; Word register
- Val1 Equ 7532h ; Integer value
- SP word 18h ; Stack Pointer
- AL data AX ; byte components
- AH data AX+1
- BX word 28h
- BL data BX
- BH data BX+1
- CX word 2Ah
- CL data CX
- CH data CX+1
- DX word 32h
- DL data DX
- DH data DX+1
-
- SerStat data 52h
- SerData data 53h
- P2Image data 54h
-
- AnStat data 56h ; for status tests
- UpBit equ 02 ; steering bit
- AnValue data 58h ; data holding word
- HiThresh equ 401 ; upper threshold
- LoThresh equ 297 ; lower threshold
-
- ;%S Copyright 1985 Cybernetic Micro Systems, Inc.
-
- org 2000h ; Interrupt Vectors
-
- dw TimerInt
- dw ADConvInt
- dw HSIDataInt
- dw HSOLineInt
- dw HSIzeroInt
- dw SoftHSOInt
- dw SerialInt
- dw ExtInt
- dw TRAPInt
-
-
- Org 2080h ; powerup reset address
-
- ; Initialize various hardware functions
-
- Start:
- ld SP,#0A0h ; stack area
- ld AX,#42h
- ld CX,AX
- add BX,[CX]+
- add DX,76h[AX]
-
- ; Define two macros, one to increase the
- ; analog voltage on channel 3, the other
- ; to decrease it.
-
- ldb AH,AL
- ldb CL,#26 ;!3 A3+47,; Analog Voltage Rising
- ldb BL,[CX]
- ldb DH,2000h[AX] ;!4 A3-25,; Analog Voltage Falling
-
-
- ClearDog: ;:Enable Watch Dog
- ldb WDogClr,#01Eh
- ldb WDogClr,#0E1h ; clear watch dog
-
- PWM_On: ;:Set PWM
- ldb PWMCtrl,#25h ; turn on PWM
-
- AtoD_On: ;:A/D Value
- ldb 26h,#0Bh ; channel 3 to start
- ldb AD_Cmd,26h ; get initial value
-
- add 46h,04 ; unload HSI FIFO
-
- HSOLineOn: ;:High Speed CAM On
- ldb HSOCmd,#31h ; set HSO line 1
- ldb 47h,#31h ; record of HSO cmd
- ld 48h,#10h
- add 48h,T1 ; get T1 + 10h
- ld HSOTime,48h ; write time to HSO
-
- SerialOn: ;:Enable Serial
- ldb Baud,#11h ; baud rate 8011h
- ldb Baud,#80h
- ldb SPCon,#09h ; mode 1, REN
- ldb SerStat,#20h ; Transmitter ready
-
- InterruptsOn:
- ldb IOC0,#55h ; IOC0, enable HSI lines
- ldb IOC1,#02Dh ; IOC1, PWM,T1,T2,TxD
- ldb P2Image,#0C1h ; initial Port 2 outputs
- ldb IntMask,#0FFh ; enable all interrupts
- ei
- ldb AnStat,#04h ; set status byte, set a value
- ld AnValue,#LoThresh+100
-
- ; Main Program Loop
-
- MainLoop:
- incb 73
- add AX,#21h
- orb P2Image,#80h
- ldb P2,P2Image ; set P2.7
- inc 36H
- ld 58,#Val1 ; 16 bit data, LSB first
-
- ; Only check the analog state while byte 36h,
- ; bit 2 is low. 36h incremented once per loop.
-
- jbs 36h,2,SkipChk ;?Skip Tests
-
- scall Test_Analog
-
- shr AX,#5
- xor AX,58 ; modify AX
-
- SkipChk:
- andb P2Image,#NOT 80h
- ldb P2,P2Image ; clear P2.7
- mulb 92h,CL,BL
-
-
- ; Branch to Up or Down routine, depending on
- ; state set by TestAnalog subroutine
-
- jbs AnStat,UpBit,GoingUp ;?Rising Value
-
- ; Change P1 value for DeCrementing, and
- ; lower analog value through embedded macro
-
- GoingDown: ;:Falling Analog
- ldb P1,#0DCh ; decrementing
- add AX,#Val1-385 ;#4
- ldb CL,73 ; copy byte 73 to CL
- sjmp MainLoop
-
- ; Change P1 value for AdDing, and raise
- ; analog value through embedded macro
-
- GoingUp: ;:Rising Analog
- ldb P1,#0ADh ; incrementing
- ldb DL,73 ;#3
- sub AX,#Val1+567
- sjmp MainLoop
-
- ; Start a new conversion if one is not in
- ; progress. Use the old converted value to
- ; check against the threshold. If above the
- ; high threshold, set the "Falling" state and
- ; drive P2.6 low. If below the low threshold,
- ; set the "Rising" state and drive P2.6 high.
-
- Test_Analog: ;:Threshold Check
- jbs ADResL,3,ConvOK ;?In Process
- ldb AD_Cmd,26h ; else start a new conversion
-
- ConvOK:
- cmp AnValue,#HiThresh
- jge OverMax ;?Max Value
- cmp AnValue,#LoThresh
- jlt UnderMin ;?Min Value
- NoChange:
- ret
-
- OverMax: ;:Upper Limit
- ldb AnStat,#Not 04h ; switch to down mode
- andb P2Image,#Not 40h ; make P2.6 low
- ret
-
- UnderMin: ;:Lower Limit
- ldb AnStat,#04h ; switch to up mode
- andb P2Image,#40h ; make P2.6 high
- ret
-
- TimerInt: ;:Timer Int
- ret
-
- ADConvInt: ;:A/D Int
- ldb AnValue,ADResL ; get low result
- ldb AnValue+1,ADResH ; and high
- shr AnValue,#6 ; align to bytes
- ret
-
- HSIDataInt: ;:HSI Event
- ldb 43h,HSIStat ; get status
- ld 44h,HSITime ; get HSI time
- ret
-
- HSOLineInt: ;:HSO Line
- pushf ; disable ints
- incb 47h ; record of HSO cmd
- jbc 47h,3,HSO_Ok ;?Cmd OK
- xorb 47h,#20h ; change set/clear bit
- HSO_Ok:
- andb 47h,#37h
- ldb HSOCmd,47h ; set HSO cmd
- ld 48h,#25h
- add 48h,T1 ; get T1 + 25h
- ld HSOTime,48h ; write time to HSO
- popf
- ret
-
- HSIzeroInt: ;:HSI.0 Int
- ret
-
- SoftHSOInt: ;:HSO Timer
- pushf
- incb 4Bh
- jbc 4Bh,2,ValOK ;?Not C or D
- orb 4Bh,#02h
- ValOK:
- andb 4Bh,#0Fh
- orb 4Bh,#38h ; HSO events 8 - F
- ldb HSOCmd,4Bh
- ld 48h,#22h
- add 48h,0Ah ; T1 + 22h
- ld HSOTime,48h ; set HSO time
- popf
- ret
-
- SerialInt: ;:Serial Data
- orb SerStat,SPStat ; preserve status bits
- jbc SerStat,6,ChkTx ;?Not Receiver
- andb SerStat,#NOT 40h ; clear RI bit
- ldb SerData,Sbuf_Rx ; read receiver
-
- ChkTx:
- jbc SerStat,5,SerDone ;?Not Transmitter
- andb SerStat,#NOT 20h ; clear TI bit
- ldb Sbuf_Tx,AH ; write a char
-
- SerDone:
- ret
-
- ExtInt: ;:External Int
- ldb WDogClr,#01Eh
- ldb WDogClr,#0E1h ; clear watch dog
- ret
-
- TRAPInt: ;:TRAP Instr
- ret
-
- nop
-
- ;%E Copyright 1985 Cybernetic Micro Systems, Inc.
-
- END START ; Starting Address