page ,132 name DAC title Micro/sys Digital-to-Analog Converter routines ;---------------------------------------------------------------- ; ; Routines that write to the onboard D/A converter. ; ; 04/28/98 Initial SBC1190 release ;---------------------------------------------------------------- _STACK segment stack 'STACK' _STACK ends _TEXT segment para public 'CODE' assume cs:_TEXT, ds:NOTHING, es:NOTHING include 188regs.inc public SetDac ;============================================================================== ; SendDacWord - Sends a 16-bit word to the serial DAC ; (c) Copyright Micro/sys, Inc. All Rights Reserved. ; ; Version History: ; Version Date Designer Comments ; v1.0 04/28/98 glenn kubota Initial design. ; ; Abstract: ; ; This procedure sends a 16-bit word to the serial DAC. ; Word value must be in AX. It is assumed that SCLK is low and /DACCS ; is low upon entry to this routine. The data is sent starting with ; bit 15. ; ; Inputs ; ; AX Word to output ; ; Outputs ; ; None ;============================================================================== SendDacWord proc push ax push bx push cx push dx mov bx, ax ;save output word mov dx, P2LTCH in al, dx ;read the port2 data latch mov cx, 16 ;send 16 data bits sendbit: rcl bx, 1 ;carry bit = bit to send jc send1 send0: and al, RTCDTA0 out dx, al ;send a data bit of 0 jmp clkdata send1: or al, RTCDTA1 out dx, al ;send a data bit of 1 clkdata: or al, RTCCLK1 out dx, al ;set the serial clock line high and al, RTCCLK0 out dx, al ;clear the serial clock line loop sendbit ;send the next bit pop dx pop cx pop bx pop ax ret SendDacWord endp ;============================================================================== ; SetupDAC - Sets up the data lines associated with the DAC ; (c) Copyright Micro/sys, Inc. All Rights Reserved. ; ; Version History: ; Version Date Designer Comments ; v1.0 04/28/98 glenn kubota Initial design. ; ; Abstract: ; ; This procedure sets up the RTCCLK, RTCIO, DACCS and RTCRST lines as outputs. ; It also clears the RTCCLK line, sets the /RTCRST line low, and sets ; the /DACCS line low. ; ; Inputs ; ; None ; ; Outputs ; ; None ;============================================================================== SetupDAC proc push ax push dx mov dx, P2DIR mov al, 03Fh ; out dx, al ;set P2.7, P2.6 for output mov dx, P2CON in al, dx and al, 1Bh out dx, al ;use P2.7, P2.6, P2.5, P2.2 as port pins mov dx, P1CON in al, dx and al, 0FBh ;use P1.2 as port pin out dx, al mov dx, P1DIR in al, dx and al, 7Bh out dx, al ;set P1.7 (/RTCRST0) and P1.2 (-DACCS) for output mov dx, P2LTCH in al, dx ;read the P2 latch and al, RTCCLK0 ;clear the serial clock out dx, al mov dx, P1LTCH in al, dx or al, DACCS1 ;set the /DACCS line to 1 out dx, al mov dx, P1LTCH in al, dx and al, DACCS0 ;clear the /DACCS line to 0 out dx, al pop dx pop ax ret SetupDAC endp ;--------------------------------------------------------------------------- ; SetDac ; ; This routine outputs a voltage on the specified analog channel. ; No error checking is done on the parameters. ; ; On entry: BL Analog channel of 0 to 3 ; AX 0 to FFFh where FFFh is 5v full-scale ; ; Returns: nothing ; ;--------------------------------------------------------------------------- SetDac proc near push ax push bx push dx call SetupDAC and bl, 3 ror bl, 1 ror bl, 1 ;channel is in bits 7, 6 of BL or ah, bl ;channel is in bits 15, 14 of AX or ah, LOADREG ;AX = 16-bit word to send to DAC call SendDacWord mov dx, P1LTCH in al, dx ;read the P1 latch or al, DACCS1 ;set /DACCS high out dx, al pop dx pop bx pop ax ret SetDac endp main proc mov bl, 1 ;channel 1 mov ax, 0FFFh ;2.5v call SetDac mov ax, 4C00h int 21h main endp _TEXT ends end main