;------------------------------------------------ ; Scientific interface test program. ; Copyright B.J.Frost, May 1986, Version #1 ;------------------------------------------------ org 100H ; equates: daport equ 0a2h ; d/a output address op8bit equ 0a1h ; 8-bit TTL output address ad8btr equ 0a0h ; 8-bit a/d trigger address ad8brd equ 0a2h ; 8-bit a/d data address ip8bit equ 0a1h ; 8-bit TTL input address dsadad equ 0a0h ; dual-slope a/d data address begin jp start ; variables: dval defs 1 ; D-A converter code store atemp defs 1 ; temp store dflag defs 1 ; set if 8-bit A/D to D/A linked delwrd defs 2 ; variable delay store digit0 defs 1 ; ds A/D digit 0 store digit1 defs 1 ; " digit 1 store digit2 defs 1 ; " digit 2 store digit3 defs 1 ; " digit 3 store start call setup ; setup initial values wstart ld de,mtit ; clear screen, title, message call pstr ; printed, ml1 ld de,prompt ; prompt and.. call pstr call inch ; wait for user call lc2uc ; force upper case cp "I" ; user wants dual-slope A-D? jp z, dsad ; yes. cp "A" ; no. User wants 8-Bit A-D? jp z, ad8b ; yes. cp "D" ; no. User wants D-A? jp z, da ; yes. cp "G" ; no. User wants dig input? jp z, input ; yes. cp "H" ; no. user wants digital output? jp z, output ; yes. cp 3 ; no. User wants exit to cp/m? jp z, warms ; yes. out call undef ; no, print error mess. jr ml1 ; and loop back ; main title mtit defw clear,pcurs defb 32,32+5 defw ulon defm "Scientific Interface Test Program 1.1" defw uloff ; options menu: defw pcurs defb 32+5,32+6 defm "I Dual-slope integrating A-D converter." defw pcurs defb 32+7,32+6 defm "A 8-Bit A-D converter." defw pcurs defb 32+9,32+6 defm "D 8-Bit D-A converter." defw pcurs defb 32+11,32+6 defm "G Digital input." defw pcurs defb 32+13,32+6 defm "H Digital output." defw pcurs defb 32+15,32+6 defm "'C Return to CP/M." defb term ; user prompt prompt defw pcurs defb 32+20,32+6 defm "Enter option:" defb term ; error routine: ; print 'undefined option' undef ld de,err1 jp pstr err1 defb bell defw pcurs defb 32+24,32+10 defm "*** Undefined option, please re-enter. ***" defb term ; clear print of 'undefined option' clerr ld de,err2 jp pstr err2 defw pcurs defb 32+24,32+10 defm " " defb term *Eject ; Digital input display. input ld de,inp3 ; print title and options call pstr inp5 in a,(ip8bit) ; get input call mulval ; print value call inkey ; get user jr z,inp5 ; no key, repeat ; key detected, decode it. call lc2uc ; force upper case inp1 cp 3 ; want to exit? jr z, inp4 ; yes. ld a,bell ; no, undefined i/p call outch ; beep jr inp5 inp4 jp wstart ; out. ; main title: inp3 defw clear,pcurs defb 32,32+5 defw ulon defm "Digital input display" defw uloff ; options menu: defw pcurs defb 32+7,32+6 defm "'C Exit to main menu." defb term *Eject ; Digital output control. output ld de,out3 ; print title and options call pstr ld a,0 out5 call mulval ; show value ld de,out4 call pstr ; place entry pointer call inhex ; get value jr c,out1 ; bad entry, so out. out (op8bit),a ; send value jr out5 ; loop back out1 jp wstart ; main title: out3 defw clear,pcurs defb 32,32+5 defw ulon defm "Digital output control" defw uloff defw pcurs defb 32+5,32+6 defm "Enter required output in hex, or something" defb cr,lf defw pcurs defb 32+6,32+6 defm " stupid to exit to main menu." defb term out4 defw pcurs defb 32+15,32 defb ">",term *Eject ; Dual-slope A-D converter control. dsad ld de,dsad1 call pstr ; print title and options dsad2 call readds ; read A/D call pdig ; print result call inkey ; any key? cp 3 ; want out? jr nz,dsad2 ; no, loop jp wstart ; yes. out. ; main title dsad1 defw clear,pcurs defb 32,32+5 defw ulon defm "Integrating dual-slope Analogue to Digital converter." defw uloff ; options menu: defw pcurs defb 32+5,32+6 defm "'C Return to main menu." defb term ; read integrating converter once into storage ; synchronise with EOC just starting (-ve edge) readds di ; interrupts off please! ad11 in a,(dsadad) ; get port byte and 80H ; EOC high? jr z,ad11 ; no, loop. ad2 in a,(dsadad) ; read port again and 80H ; EOC low? jr nz, ad2 ; no, loop. ; fetch first BCD digit (digit 0) by DS0=1. ad3 in a,(dsadad) ; get port again ld b,a ; saved and 10H ; digit select 0 is =1 ? jr z,ad3 ; no, loop. ad4 ld a,b ; restore reading and 0fH ; keep BCD ld (digit0),a ; and save as digit 0. ; fetch digit 1 by DS1,3=0. ad5 in a,(dsadad) ; get port ld b,a ; save reading and 20H ; next digit? jr nz, ad5 ;no. ld a,b ; yes. restore reading and 0fH ; keep BCD ld (digit1),a ; stored as digit 1 ; fetch digit 2 by DS2=1. ad6 in a,(dsadad) ; get port ld b,a ; saved and 40H ; next digit? jr z,ad6 ; no. ld a,b ; yes. restore. and 0fH ; keep BCD ld (digit2),a ; saved as digit 2 ; fetch digit 3 by DS1,3=0. ad7 in a,(dsadad) ; get port ld b,a ; saved and 20H ; next digit? jr nz, ad7 ; no ld a,b ; yes. restore and 0fH ; keep BCD ld (digit3),a ; saved. ret ; now print digits, polarity first. pdig ld de,pdig1 ; position cursor call pstr ld a,(digit0) ; fetch MSD ld b,a ; save ld c,"+" ; assume positive and 04H ; mask polarity jr nz, ispos ; is positive ld c,"-" ; load - character ispos ld a,c ; ready to print call outch ; print polarity ; do most significant digit value. ld a,(digit0) ; fetch digit ld c,"0" ; assume zero and 08H ; mask digit bit jr nz, iszer ; is zero (bit is 1) ld c,"1" ; is a one iszer ld a,c call outch ; print it ; print decimal point, ld a,"." ; dec pt call outch ; printed ; do first of BCD digits. ld a,(digit1) add a,30H call outch ; middle BCD digit, ld a,(digit2) add a,30H call outch ; last BCD digit, ld a,(digit3) add a,30H call outch ld de,pdig2 call pstr ; print RH brackets ret pdig1 defw pcurs defb 32+10,32+10 defw rev defb "["," " defb term pdig2 defb " ","]" defw revoff defb term *Eject ; 8-Bit A-D converter control. ad8b ld de,ad8b1 call pstr ; print title, options ld de,100 ; set up default delay ad8b4 ld (delwrd),de ad8b7 call link ; show state of A/D, D/A link. call clerr ; clear error mess ad8b2 call read8 ; read A/D ld (dval),a ; saved for D/A if required call mulval ; print reading call daset ; set up D/A if required ld de,(delwrd) ; fetch delay value call delay ; wait call inkey ; any chr? jr z,ad8b2 ; no, loop call lc2uc ; force upper case ld de,1000 ; assume want slow readings. cp "S" ; user wants it? jr z,ad8b4 ; yes. ld de,100 ; assume want middle speed. cp "M" ; user wants it? jr z,ad8b4 ; yes. ld de,1 ; assume fast readings cp "F" ; is it? jr z,ad8b4 ; yes. cp 3 ; want exit to main menu? jr nz,ad8b5 ; no. jp wstart ; exit ad8b5 cp "L" ; want toggle D/A link? jr nz,ad8b6 ; no ld a,(dflag) xor 1 ; swop bit 0 ld (dflag),a jr ad8b7 ad8b6 call undef ; undefined entry error jr ad8b2 ; put reading to D/A if 'dflag' is set. daset ld a,(dflag) ; want value to D/A? add a,0 ret z ; no. ld a,(dval) ; yes. value to D/A converter out (daport),a ret ; messages ad8b1 defw clear,pcurs defb 32,32+5 defw ulon defm "8-Bit Analogue to Digital converter control." defw uloff ; options menu: defw pcurs defb 32+5,32+6 defm "L Toggle link readings to D/A output." defw pcurs defb 32+7,32+6 defm "S Slow reading rate." defw pcurs defb 32+9,32+6 defm "M Medium reading rate." defw pcurs defb 32+11,32+6 defm "F Fastest reading rate." defw pcurs defb 32+13,32+6 defm "'C Return to main menu." defb term ; show state of A/D to D/A converter link. Is linked- ; - if 'dflag' set, not otherwise. link ld de,link1 call pstr ; show message ld de, link2 ; assume not linked, ld a, (dflag) ; is it zero then? add a,0 jr z,link3 ; yes. ld de,link4 ; no. is linked. link3 jp pstr ; print link message link1 defw pcurs defb 32+23,32+6 defm "Link A/D readings to D/A converter: " defb term link2 defm "Not linked." defb term link4 defm "Linked. " defb term ; read 8-bit A/D converter. read8 out (ad8btr),a ; trigger A/D nop ; minimum delay nop nop nop nop nop in a,(ad8brd) ; read A/D ret *Eject ; D-A converter control. da ld de,da1 ; print D-A title and options call pstr da9 call clerr ; clear any error mess da2 ld a,(dval) ; get code out (daport),a ; send to d/a ld a,(dval) call mulval ; show current code ld de,prompt ; print 'Enter option' etc call pstr call inch ; get character call lc2uc ; set upper case ld b,0 ; want to zero the code? cp "Z" jr nz,da3 ; no. da4 ld a,b ld (dval),a ; update code value from 'b' jr da9 da3 ld b,80h ; want to set middle code? cp "M" jr z,da4 ; yes, do it ld b,255 ; want to set top code? cp "T" jr z,da4 ; yes, set top code ld b,1 ; want to increment code? cp "+" jr z,da5 ; yes ld b,-1 ; no, want to decrement? cp "-" jr nz,da6 ; no. da5 ld a,(dval) add a,b ld (dval),a ; code incd or decd jr da9 ; loop for reprint da6 cp 3 ; want return to main menu? jr nz, da8 ; no, error then. jp wstart da8 call undef ; print 'undefined option' jr da2 ; and loop ; messages da1 defw clear,pcurs defb 32,32+5 defw ulon defm "Digital to Analogue converter control." defw uloff ; options menu: defw pcurs defb 32+5,32+6 defm "Z Zero code to converter." defw pcurs defb 32+7,32+6 defm "M Middle code (80 hex) to converter." defw pcurs defb 32+9,32+6 defm "T Top code (FF hex) to converter." defw pcurs defb 32+11,32+6 defm "+ Increment converter code." defw pcurs defb 32+13,32+6 defm "- Decrement converter code." defw pcurs defb 32+15,32+6 defm "'C Return to main menu." defb term *Eject ; show value in 'A' on screen as dec, hex, and binary. mulval ld (atemp),a ; save byte ld de,vmess1 call pstr ; position on screen ld a,"[" call outch ld a,(atemp) ; fetch from store call pdbyte ; print in decimal ld de,dac1 call pstr ; print chr string ld a,(atemp) call pbyte ; print in hex ld de,dac1 ; print chr string call pstr ld a,(atemp) call pbbyte ; print in binary ld a,"]" call outch ld de,vmess2 ; attributes off call pstr ret vmess1 defw rev,pcurs defb 32+6,32+55 defm " " defb term vmess2 defw revoff defm " " defb term dac1 defb "]"," ","[",term ; setup initial values and conditions setup xor a ; clear acc ld (dval),a ; clear D-A code value ret *Eject ; fetch system routines *include sysrot