* sample solution to HW8: analog input port driver * Changes to code for use with simulator are marked with SIM. These must * be changed as noted for use with miniboard * Memory segments and required addresses for program RAM equ 0 STACK equ $ff EEPROM equ $f800 RESET equ $fffe * SIM test data. REMOVE FOR USE ON MINIBOARD. org ADCTL fcb %10000000 fcb $60 fcb $70 fcb $80 fcb $90 org OPTION fcb 0 * End test data. * Test program. I'm deliberately not using the symbolic constants * from the driver here to avoid being caught by systematic errors org EEPROM start * Establish stack pointer lds #STACK * Test 1: attempt to read port 0 (too small; should return -1) ldaa #0 psha jsr analog ins * Test 2: attempt to read port 9 (too large; should return -1) ldaa #9 psha jsr analog ins * Test 3: read port 1 (should return $78 on test data above) ldaa #1 psha jsr analog ins * Test 4: read port 8 (should return $78 on test data above) ldaa #8 psha jsr analog ins * It would actually be a good idea to test all the valid inputs, since * there are only 8 of them... but you get the idea. * all done eloop bra eloop **************************************************************************** * analog input port device driver * constants for analog input port * addresses of relevant IO ports * SIM IO put in RAM for simulator. CHANGE FOR REAL MINIBOARD * IO equ $1000 * start of IO area (I'll be using indexed addressing) IO equ $00 * start of IO area (I'll be using indexed addressing) * End of code to change for miniboard OPTION equ $39 * option register ADPU equ %10000000 * a/d power control ADCTL equ $30 * a/d control register CCF equ %10000000 * conversion complete SCAN equ %00100000 * keep scanning (not used) MULT equ %00010000 * read several channels (not used) ADR1 equ $31 * a/d result ports ADR2 equ $32 ADR3 equ $33 ADR4 equ $34 ANERR equ -1 * error return ANNUM equ 8 * number of analog ports ANPORT equ 7 * offset to unsigned char parameter analog * save regs and create activation record pshb pshx pshy tsy * translate input parameter to range 0-7 ldaa ANPORT,y * b = digbit-1; deca * range check cmpa #ANNUM blo anok * if (b >= dignum) ldaa #ANERR * return(error); bra anret * get the IO segment anok ldx #IO * turn on the analog subsystem bset OPTION,x #ADPU * tell the a/d system which port to read staa ADCTL,x * specified port, no MULT, no SCAN * might as well clra here, since we have to wait for good data anyway clra * wait for good data * SIM: commented out for testing with simulator. MUST BE UNCOMMENTED FOR * MINIBOARD *anloop brclr ADCTL,x CCF anloop * end of code commented out for simulator * read and average ldab ADR1,x addb ADR2,x adca #0 addb ADR3,x adca #0 addb ADR4,x adca #0 asra rorb asra rorb * shut down analog subsystem bclr OPTION,x #ADPU * and return result tba * common return code anret puly pulx pulb rts ***************************************************************************** * interrupt vectors org RESET fdb start