.module keyboard.c
.area lit(rom, con, rel)
_unshifted::
.byte 13,9
.byte 14,96
.byte 21,'q
.byte 22,49
.byte 26,'z
.byte 27,'s
.byte 28,'a
.byte 29,'w
.byte 30,50
.byte 33,'c
.byte 34,'x
.byte 35,'d
.byte 36,'e
.byte 37,52
.byte 38,51
.byte 41,32
.byte 42,'v
.byte 43,'f
.byte 44,'t
.byte 45,'r
.byte 46,53
.byte 49,'n
.byte 50,'b
.byte 51,'h
.byte 52,'g
.byte 53,'y
.byte 54,54
.byte 57,44
.byte 58,'m
.byte 59,'j
.byte 60,'u
.byte 61,55
.byte 62,56
.byte 'A,44
.byte 'B,'k
.byte 'C,'i
.byte 'D,'o
.byte 'E,48
.byte 'F,57
.byte 'I,46
.byte 'J,47
.byte 'K,'l
.byte 'L,59
.byte 'M,'p
.byte 'N,45
.byte 'R,39
.byte 'T,91
.byte 'U,61
.byte 'Z,13
.byte 91,93
.byte 93,92
.byte 'a,60
.byte 'f,8
.byte 'i,49
.byte 'k,52
.byte 'l,55
.byte 'p,48
.byte 'q,44
.byte 'r,50
.byte 's,53
.byte 't,54
.byte 'u,56
.byte 'y,43
.byte 'z,51
.byte 123,45
.byte 124,42
.byte 125,57
.byte 0,0
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD/scancodes.h
.dbsym e unshifted _unshifted A[136:68:2]kc
_shifted::
.byte 13,9
.byte 14,126
.byte 21,'Q
.byte 22,33
.byte 26,'Z
.byte 27,'S
.byte 28,'A
.byte 29,'W
.byte 30,64
.byte 33,'C
.byte 34,'X
.byte 35,'D
.byte 36,'E
.byte 37,36
.byte 38,35
.byte 41,32
.byte 42,'V
.byte 43,'F
.byte 44,'T
.byte 45,'R
.byte 46,37
.byte 49,'N
.byte 50,'B
.byte 51,'H
.byte 52,'G
.byte 53,'Y
.byte 54,94
.byte 57,'L
.byte 58,'M
.byte 59,'J
.byte 60,'U
.byte 61,38
.byte 62,42
.byte 'A,60
.byte 'B,'K
.byte 'C,'I
.byte 'D,'O
.byte 'E,41
.byte 'F,40
.byte 'I,62
.byte 'J,63
.byte 'K,'L
.byte 'L,58
.byte 'M,'P
.byte 'N,95
.byte 'R,34
.byte 'T,123
.byte 'U,43
.byte 'Z,13
.byte 91,125
.byte 93,124
.byte 'a,62
.byte 'f,8
.byte 'i,49
.byte 'k,52
.byte 'l,55
.byte 'p,48
.byte 'q,44
.byte 'r,50
.byte 's,53
.byte 't,54
.byte 'u,56
.byte 'y,43
.byte 'z,51
.byte 123,45
.byte 124,42
.byte 125,57
.byte 0,0
.dbsym e shifted _shifted A[136:68:2]kc
.area data(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD/scancodes.h
_input::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD/scancodes.h
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\keyboard.c
.dbsym e input _input c
_output::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\keyboard.c
.dbsym e output _output c
.area text(rom, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\keyboard.c
.dbfunc e put_kbbuff _put_kbbuff fV
; c -> R16
.even
_put_kbbuff::
.dbline -1
.dbline 19
; /******************************************/
; /* 广州天河双龙电子公司 */
; /* http://www.sl.com.cn */
; /* PS2键盘驱动程序 */
; /* 作者:ntzwq@wx88.net */
; /* 2002年5月11日 */
; /* 目标MCU:MEGA8 晶振:外部(EXT) 8MHZ */
; /******************************************/
; #include
; #include "pindefs.h"
; #include "scancodes.h"
; #include
; #define BUFF_SIZE 64
; unsigned char bitcount;
; unsigned char kb_buffer[BUFF_SIZE];
; unsigned char input=0;
; unsigned char output=0;
; void put_kbbuff(unsigned char c)
; {
.dbline 20
; kb_buffer[input]=c;
ldi R24, ldi R25,>_kb_buffer
lds R30,_input
clr R31
add R30,R24
adc R31,R25
std z+0,R16
.dbline 21
; if (input lds R24,_input
cpi R24,63
brsh L2
.dbline 22
; input++;
subi R24,255 ; addi 1
sts _input,R24
rjmp L3
L2:
.dbline 24
clr R2
sts _input,R2
L3:
.dbline -2
.dbline 25
; else
; input=0;
; }
L1:
.dbline 0 ; func end
ret
.dbsym r c 16 c
.dbend
.dbfunc e getchar _getchar fc
; temp -> R16
.even
_getchar::
.dbline -1
.dbline 27
; unsigned char getchar(void)
; {
.dbline 29
; unsigned char temp;
; if(output==input)
lds R2,_input
lds R3,_output
cp R3,R2
brne L5
.dbline 30
; return 0;
clr R16
rjmp L4
L5:
.dbline 32
; else
; {
.dbline 33
; temp=kb_buffer[output];
ldi R24, ldi R25,>_kb_buffer
lds R30,_output
clr R31
add R30,R24
adc R31,R25
ldd R16,z+0
.dbline 34
; if(output lds R24,_output
cpi R24,63
brsh L7
.dbline 35
; {
.dbline 36
; output++;
subi R24,255 ; addi 1
sts _output,R24
.dbline 37
; }
rjmp L8
L7:
.dbline 39
; else
; output=0;
clr R2
sts _output,R2
L8:
.dbline 40
; return temp;
.dbline -2
L4:
.dbline 0 ; func end
ret
.dbsym r temp 16 c
.dbend
.dbfunc e init_kb _init_kb fV
.even
_init_kb::
.dbline -1
.dbline 44
; }
; }
; void init_kb(void)
; {
.dbline 45
; PIN_DIR&=~((1 in R24,0x11
andi R24,243
out 0x11,R24
.dbline 46
; PORT_KB|=(1 in R24,0x12
ori R24,12
out 0x12,R24
.dbline 47
; MCUCR = 0x08;
ldi R24,8
out 0x35,R24
.dbline 48
; GICR = 0x80;
ldi R24,128
out 0x3b,R24
.dbline 49
; SEI();
sei
.dbline 50
; bitcount = 11;
ldi R24,11
sts _bitcount,R24
.dbline -2
.dbline 51
; }
L9:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\keyboard.c
L11:
.blkb 1
L12:
.blkb 1
L13:
.blkb 1
.area text(rom, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\keyboard.c
.dbfunc e decode _decode fV
.dbsym s shiftup L13 c
.dbsym s up L12 c
.dbsym s shift L11 c
; i -> R20
; sc -> R22
.even
_decode::
rcall push_gset3
mov R22,R16
.dbline -1
.dbline 53
; void decode(unsigned char sc)
; {
.dbline 56
; static unsigned char shift,up,shiftup;
; unsigned char i;
; if (sc==0xf0)
cpi R22,240
brne L14
.dbline 57
; {
.dbline 58
; up=1;
ldi R24,1
sts L12,R24
.dbline 59
; return;
rjmp L10
L14:
.dbline 61
; }
; if (up==1)
lds R24,L12
cpi R24,1
brne L16
.dbline 62
; {
.dbline 63
; up=0;
clr R2
sts L12,R2
.dbline 64
; if ((sc==0x12)|(sc==0x59)) shift=0;
cpi R22,18
brne L20
ldi R24,1
ldi R25,0
movw R10,R24
rjmp L21
L20:
clr R10
clr R11
L21:
cpi R22,89
brne L22
ldi R20,1
ldi R21,0
rjmp L23
L22:
clr R20
clr R21
L23:
movw R2,R10
or R2,R20
or R3,R21
tst R2
brne X0
tst R3
brne X2
rjmp L10
X2:
X0:
.dbline 64
clr R2
sts L11,R2
.dbline 65
; return;
rjmp L10
L16:
.dbline 67
; }
; switch (sc)
mov R20,R22
clr R21
cpi R20,18
ldi R30,0
cpc R21,R30
breq L27
cpi R20,18
ldi R30,0
cpc R21,R30
brlt L24
L47:
cpi R20,89
ldi R30,0
cpc R21,R30
breq L28
rjmp L24
X1:
.dbline 68
; {
L27:
.dbline 69
; case 0x12:{
.dbline 70
; shift=1;
ldi R24,1
sts L11,R24
.dbline 71
; shiftup=1;
sts L13,R24
.dbline 72
; }
L28:
.dbline 73
; case 0x59:{
.dbline 74
; shift=1;
ldi R24,1
sts L11,R24
.dbline 75
; shiftup=1;
sts L13,R24
.dbline 76
; }
L24:
.dbline 77
; default:{
.dbline 78
; if (shift==0)
lds R2,L11
tst R2
brne L29
.dbline 79
; {
.dbline 80
clr R20
rjmp L34
L31:
.dbline 80
L32:
.dbline 80
inc R20
L34:
.dbline 80
; for(i = 0;unshifted[i][0]!=sc && unshifted[i][0]; i++);
ldi R24,2
mul R24,R20
movw R30,R0
ldi R24, ldi R25,>_unshifted
add R30,R24
adc R31,R25
lpm R2,Z
clr R3
cp R2,R22
breq L35
tst R2
brne L31
L35:
.dbline 81
; if (unshifted[i][0] == sc)
ldi R24,2
mul R24,R20
movw R30,R0
ldi R24, ldi R25,>_unshifted
add R30,R24
adc R31,R25
lpm R30,Z
cp R30,R22
breq X3
rjmp L30
X3:
.dbline 82
; put_kbbuff(unshifted[i][1]);
ldi R24,2
mul R24,R20
movw R30,R0
ldi R24, ldi R25,>_unshifted+1
add R30,R24
adc R31,R25
lpm R16,Z
rcall _put_kbbuff
.dbline 83
; }
rjmp L30
L29:
.dbline 85
; else
; {
.dbline 86
clr R20
rjmp L42
L39:
.dbline 86
L40:
.dbline 86
inc R20
L42:
.dbline 86
; for(i = 0;shifted[i][0]!=sc && shifted[i][0]; i++);
ldi R24,2
mul R24,R20
movw R30,R0
ldi R24, ldi R25,>_shifted
add R30,R24
adc R31,R25
lpm R2,Z
clr R3
cp R2,R22
breq L43
tst R2
brne L39
L43:
.dbline 87
; if (shifted[i][0] == sc)
ldi R24,2
mul R24,R20
movw R30,R0
ldi R24, ldi R25,>_shifted
add R30,R24
adc R31,R25
lpm R30,Z
cp R30,R22
brne L44
.dbline 88
; {
.dbline 89
; put_kbbuff(shifted[i][1]);
ldi R24,2
mul R24,R20
movw R30,R0
ldi R24, ldi R25,>_shifted+1
add R30,R24
adc R31,R25
lpm R16,Z
rcall _put_kbbuff
.dbline 90
; }
L44:
.dbline 91
; }
L30:
.dbline 92
; }
.dbline 93
; }
.dbline -2
.dbline 94
; }
L10:
rcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r sc 22 c
.dbend
.area vector(rom, abs)
.org 4
rjmp _int1_isr
.area text(rom, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\keyboard.c
.area bss(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\keyboard.c
L49:
.blkb 1
.area text(rom, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\keyboard.c
.dbfunc e int1_isr _int1_isr fV
.dbsym s data L49 c
.even
_int1_isr::
rcall push_lset
rcall push_gset1
.dbline -1
.dbline 97
; #pragma interrupt_handler int1_isr:iv_INT1
; void int1_isr(void)
; {
.dbline 99
; static unsigned char data;
; switch (bitcount)
lds R20,_bitcount
clr R21
cpi R20,1
ldi R30,0
cpc R21,R30
breq L57
cpi R20,2
ldi R30,0
cpc R21,R30
breq L56
cpi R20,1
ldi R30,0
cpc R21,R30
brlt L50
L62:
cpi R20,11
ldi R30,0
cpc R21,R30
breq L53
rjmp L50
X4:
.dbline 100
; {
L53:
.dbline 101
; case 11:{
.dbline 102
; if ((PIN_KB&(1 sbis 0x10,2
rjmp L54
.dbline 103
; return;
rjmp L48
L54:
.dbline 105
; else
; bitcount--;
lds R24,_bitcount
subi R24,1
sts _bitcount,R24
.dbline 106
; break;}
rjmp L51
L56:
.dbline 107
; case 2:{
.dbline 108
; bitcount--;
lds R24,_bitcount
subi R24,1
sts _bitcount,R24
.dbline 109
; break;}
rjmp L51
L57:
.dbline 110
; case 1:{
.dbline 111
; bitcount--;
lds R24,_bitcount
subi R24,1
sts _bitcount,R24
.dbline 112
; if ((PIN_KB&(1 sbic 0x10,2
rjmp L58
.dbline 113
; {
.dbline 114
; bitcount=11;
ldi R24,11
sts _bitcount,R24
.dbline 115
; return;
rjmp L48
L58:
.dbline 118
; }
; else
; {
.dbline 119
; bitcount=11;
ldi R24,11
sts _bitcount,R24
.dbline 120
; decode(data);
lds R16,L49
rcall _decode
.dbline 121
; }
.dbline 122
; break;}
rjmp L51
L50:
.dbline 123
; default:{
.dbline 124
; data = (data >> 1);
lds R2,L49
lsr R2
sts L49,R2
.dbline 125
; if((PIN_KB&(1 sbis 0x10,2
rjmp L60
.dbline 126
; data|=0x80;
mov R24,R2
ori R24,128
sts L49,R24
L60:
.dbline 127
lds R24,_bitcount
subi R24,1
sts _bitcount,R24
.dbline 128
.dbline 129
L51:
.dbline -2
.dbline 130
; bitcount--;
; }
; }
; }
L48:
rcall pop_gset1
rcall pop_lset
.dbline 0 ; func end
reti
.dbend
.area bss(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\keyboard.c
_kb_buffer::
.blkb 64
.dbsym e kb_buffer _kb_buffer A[64:64]c
_bitcount::
.blkb 1
.dbsym e bitcount _bitcount c