
AN463/D
MOTOROLA
9
0078 **************************************************************
0079 * THE KEY READ IS DECODED FOR TRANSMISSION. *
0080 * THE TRANSMISSION PROTOCOL REQUIRES A START MESSAGE OF 9 *
0081 * ONES FOLLOWED BY THE KEYPRESSED CODE. THIS CODE IS *
0082 * CONTINUALLY RETRANSMITTED IF THE KEY IS HELD DOWN. AN END *
0083 * CODE OF 9 ONES TERMINATES THE TRANSMISSION AND THE DEVICE *
0084 * RETURNS TO STOP MODE. *
0085 **************************************************************
0086
0087 0218 ad 34 presd bsr keyscn ; get key pressed
0088 021a b6 e1 lda keyst2 ; save key to check
0089 021c b7 e0 sta keyst1 ; if key held down
0090 021e ad 67 bsr decode ; decode key pressed
0091 0220 12 e3 bset 1,dflag ; set nineth bit to 1
0092 0222 a6 ff lda #$ff ; send start data
0093 0224 b7 e2 sta keyst3 ; to transmission routine
0094 0226 ad 71 bsr trnmit ; nine one's
0095 0228 b6 e1 sndagn lda keyst2 ; send key press message
0096 022a b7 e2 sta keyst3 ; byte
0097 022c 13 e3 bclr 1,dflag ; set nineth bit to 0
0098 022e ad 69 bsr trnmit
0099 0230 b6 00 lda porta ; check if key still pressed
0100 0232 a4 0f and #$0f ; end if no key pressed
0101 0234 26 0f bne endtrn
0102 0236 ad 16 bsr keyscn ; else check if same
0103 0238 b6 e0 lda keyst1 ; key pressed
0104 023a b1 e1 cmp keyst2
0105 023c 26 07 bne endtrn ; end if not
0106 023e ae c8 ldx #$c8 ; delay
0107 0240 5a tloop decx ; before next
0108 0241 26 fd bne tloop ; transmission
0109 0243 20 e3 bra sndagn
0110 0245 12 e3 endtrn bset 1,dflag ; send end message
0111 0247 a6 ff lda #$ff ; of nine ones
0112 0249 b7 e2 sta keyst3
0113 024b ad 4c bsr trnmit
0114 024d 80 rti ; re-enter stop mode
0115
0116 **************************************************************
0117 * WHEN A KEY IS PRESSED THE DEVICE COMES OUT OF STOP MODE *
0118 * THE KEYBOARD IS SCANNED TO SEE WHICH KEY IS PRESSED *
0119 **************************************************************
0120
0121 024e cd 02 fc keyscn jsr datwt ; wait for debounce
0122 0251 b6 00 lda porta ; check if key press
0123 0253 b7 e0 sta keyst1 ; store inputs
0124 0255 a4 0f and #$0f ; mask outputs
0125 0257 27 a7 beq start ; stop if no key pressed
0126 0259 ae ef ldx #$ef ; set one row low
0127 025b 9f nxtrow txa ; read ouput lines
0128 025c b4 e0 and keyst1 ; combine with inputs
0129 025e b7 e1 sta keyst2 ; store key code
0130 0260 bf 00 stx porta ; to find row which clears inputs
0131 0262 b6 00 lda porta ; check for inputs cleared
0132 0264 a4 0f and #$0f ; mask outputs
0133 0266 27 1c beq gotit ; zero in key-press row clears inputs
0134 0268 58 lslx ; check if last row
0135 0269 5c incx ; set lsb to 1
0136 026a 24 02 bcc tryb ; try portb output if not porta
0137 026c 20 ed bra nxtrow ; try next porta output row
0138
0139 026e b6 e0 tryb lda keyst1
0140 0270 b7 e1 sta keyst2
0141 0272 ae f0 ldx #$f0
0142 0274 bf 00 stx porta ; set all porta outputs high
0143 0276 11 01 bclr 0,portb ; set portb 0 output low
0144 0278 b6 00 lda porta ; check for inputs cleared
0145 027a a4 0f and #$0f ; mask outputs
0146 027c 27 06 beq gotit ; zero in key-press row clears inputs
0147 027e b6 e1 lda keyst2 ;
0148 0280 a4 3f and #$3f ; set individual code since last row
0149 0282 b7 e1 sta keyst2 ; store code
0150 0284 10 01 gotit bset 0,portb ; set portb column high again
0151 0286 81 rts
0152