* sample solution to HW7: digital input port driver * Memory segments and required addresses for program RAM equ 0 STACK equ $ff EEPROM equ $f800 RESET equ $fffe * Test data. REMOVE FOR USE ON MINIBOARD org DIGPRT fcb %10101100 * 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 bit 0 (too small; should return -1) ldaa #0 psha jsr digital ins * Test 2: attempt to read bit 9 (too large; should return -1) ldaa #9 psha jsr digital ins * Test 3: read bit 1 (should return 0 on test data above) ldaa #1 psha jsr digital ins * Test 4: read bit 8 (should return 1 on test data above) ldaa #8 psha jsr digital 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 **************************************************************************** * digital input port device driver * masks for input bit selection DIGMSK fcb %00000001,%00000010,%00000100,%00001000 fcb %00010000,%00100000,%01000000,%10000000 * constants for digital input port DIGPRT equ $1003 * address of digital input port DIGNUM equ 8 * number of bits in port DIGERR equ -1 * error return DIGYES equ 1 * specified bit contains 1 return DIGNO equ 0 * specified bit contains 0 return DIGBIT equ 5 * offset to unsigned char parameter digital * save regs and create activation record pshb pshx tsx * translate input parameter to range 0-7 ldab DIGBIT,x * b = digbit-1; decb * range check cmpb #DIGNUM blo digok * if (b >= dignum) ldaa #DIGERR * return(error); bra digret * check for masked bit in digital input port digok ldx #DIGMSK abx ldaa 0,x * a = digmsk[b]; anda DIGPRT * if ((a & PORTC) == 0) beq digret * return(digno); ldaa #DIGYES * return(digyes); * common return code digret pulx pulb rts ***************************************************************************** * interrupt vectors org RESET fdb start