📄 keyboard.s
字号:
.module Keyboard.c
.area code(ram, con, rel)
.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 F:\李鹏飞\sl-avrad-m16\键盘演示程序\Keyboard.c
.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 F:\李鹏飞\sl-avrad-m16\键盘演示程序\Keyboard.c
_input::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\键盘演示程序\Keyboard.c
.dbsym e input _input c
_output::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\键盘演示程序\Keyboard.c
.dbsym e output _output c
.area text(rom, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\键盘演示程序\Keyboard.c
.dbfunc e put_kbbuff _put_kbbuff fV
; c -> R16
.even
_put_kbbuff::
.dbline -1
.dbline 49
; /******************************************/
; /* 广州天河双龙电子公司 */
; /* http://www.sl.com.cn */
; /* PS2键盘驱动程序 */
; /* 作者:lpf@sl.com.cn */
; /* 2003年8月28日 */
; /* 目标MCU:MEGA16 晶振:外部(EXT) 8MHZ */
; /******************************************/
; #include<iom16v.h>
; #include<macros.h>
; #define PIN_DIR DDRD
; #define PIN_KB PIND
; #define PORT_KB PORTD
; #define CLOCK 3
; #define DATAPIN 2
; #define BUFF_SIZE 64
; #define fosc 8000000
; //晶振8MHZ
; #define baud 19200
; //波特率
; #pragma data:code
; //设置数据区为程序存储器
; //没有按下shift键的PC机键盘扫描码
; const unsigned char unshifted[][2] = {
; 0x0d,9,0x0e,'`',0x15,'q',0x16,'1',0x1a,'z',0x1b,'s',0x1c,'a',0x1d,'w',0x1e,'2',
; 0x21,'c',0x22,'x',0x23,'d',0x24,'e',0x25,'4',0x26,'3',0x29,' ',0x2a,'v',0x2b,'f',0x2c,'t',0x2d,'r',0x2e,'5',
; 0x31,'n',0x32,'b',0x33,'h',0x34,'g',0x35,'y',0x36,'6',0x39,',',0x3a,'m',0x3b,'j',0x3c,'u',0x3d,'7',0x3e,'8',
; 0x41,',',0x42,'k',0x43,'i',0x44,'o',0x45,'0',0x46,'9',0x49,'.',0x4a,'/',0x4b,'l',0x4c,';',0x4d,'p',0x4e,'-',
; 0x52,0x27,0x54,'[',0x55,'=',0x5a,13, 0x5b,']',0x5d,0x5c,0x61,'<',0x66,8,0x69,'1',0x6b,'4',0x6c,'7',
; 0x70,'0',0x71,',',0x72,'2',0x73,'5',0x74,'6',0x75,'8',0x79,'+',0x7a,'3',0x7b,'-',0x7c,'*',0x7d,'9',0,0
; };
; //按下shift键的PC机键盘扫描码
; const unsigned char shifted[][2] = {
; 0x0d,9,0x0e,'~',0x15,'Q',0x16,'!',0x1a,'Z',0x1b,'S',0x1c,'A',0x1d,'W',0x1e,'@',
; 0x21,'C',0x22,'X',0x23,'D',0x24,'E',0x25,'$',0x26,'#',0x29,' ',0x2a,'V',0x2b,'F',0x2c,'T',0x2d,'R',0x2e,'%',
; 0x31,'N',0x32,'B',0x33,'H',0x34,'G',0x35,'Y',0x36,'^',0x39,'L',0x3a,'M',0x3b,'J',0x3c,'U',0x3d,'&',0x3e,'*',
; 0x41,'<',0x42,'K',0x43,'I',0x44,'O',0x45,')',0x46,'(',0x49,'>',0x4a,'?',0x4b,'L',0x4c,':',0x4d,'P',0x4e,'_',
; 0x52,'"',0x54,'{',0x55,'+',0x5a,13, 0x5b,'}',0x5d,'|',0x61,'>',0x66,8,0x69,'1',0x6b,'4',0x6c,'7',
; 0x70,'0',0x71,',',0x72,'2',0x73,'5',0x74,'6',0x75,'8',0x79,'+',0x7a,'3',0x7b,'-',0x7c,'*',0x7d,'9',0,0
; };
; #pragma data:data
; //设置数据区回到数据存储器
; unsigned char bitcount; //pc键盘数据长度计数
; unsigned char kb_buffer[BUFF_SIZE]; //键盘缓冲区
; unsigned char input=0; //缓冲区读指针
; unsigned char output=0; //缓冲区写指针
; //键盘缓冲区使用软件模拟FIFO
; void put_kbbuff(unsigned char c) //送键盘按键ASCII码到键盘缓冲区
; {
.dbline 50
; kb_buffer[input]=c;
ldi R24,<_kb_buffer
ldi R25,>_kb_buffer
lds R30,_input
clr R31
add R30,R24
adc R31,R25
std z+0,R16
.dbline 51
; if (input<(BUFF_SIZE-1))
lds R24,_input
cpi R24,63
brsh L2
.dbline 52
; input++;
subi R24,255 ; addi 1
sts _input,R24
xjmp L3
L2:
.dbline 54
clr R2
sts _input,R2
L3:
.dbline -2
.dbline 55
; else
; input=0;
; }
L1:
.dbline 0 ; func end
ret
.dbsym r c 16 c
.dbend
.dbfunc e get_char _get_char fc
; temp -> R16
.even
_get_char::
.dbline -1
.dbline 57
; unsigned char get_char(void) //从键盘缓冲区读取按键的ASCII码
; {
.dbline 59
; unsigned char temp;
; if (output==input)
lds R2,_input
lds R3,_output
cp R3,R2
brne L5
.dbline 60
; return 0;
clr R16
xjmp L4
L5:
.dbline 62
; else
; {
.dbline 63
; temp=kb_buffer[output];
ldi R24,<_kb_buffer
ldi R25,>_kb_buffer
lds R30,_output
clr R31
add R30,R24
adc R31,R25
ldd R16,z+0
.dbline 64
; if (output<(BUFF_SIZE-1))
lds R24,_output
cpi R24,63
brsh L7
.dbline 65
; output++;
subi R24,255 ; addi 1
sts _output,R24
xjmp L8
L7:
.dbline 67
; else
; output=0;
clr R2
sts _output,R2
L8:
.dbline 68
; return temp;
.dbline -2
L4:
.dbline 0 ; func end
ret
.dbsym r temp 16 c
.dbend
.dbfunc e uart_init _uart_init fV
.even
_uart_init::
.dbline -1
.dbline 72
; }
; }
; void uart_init(void)
; {
.dbline 73
; UCSRB=(1<<RXEN)|(1<<TXEN); //允许发送和接收
ldi R24,24
out 0xa,R24
.dbline 74
; UBRRL=(fosc/16/(baud+1))%256;
ldi R24,26
out 0x9,R24
.dbline 75
; UBRRH=(fosc/16/(baud+1))/256; //波特率19200
clr R2
out 0x20,R2
.dbline 76
; UCSRC=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); //8位数据+1位STOP位
ldi R24,134
out 0x20,R24
.dbline -2
.dbline 77
; }
L9:
.dbline 0 ; func end
ret
.dbend
.dbfunc e putchar _putchar fV
; c -> R16
.even
_putchar::
.dbline -1
.dbline 79
; void putchar(unsigned char c)
; {
L11:
.dbline 80
L12:
.dbline 80
; while (!(UCSRA&(1<<UDRE)));
sbis 0xb,5
rjmp L11
.dbline 81
; UDR=c;
out 0xc,R16
.dbline -2
.dbline 82
; }
L10:
.dbline 0 ; func end
ret
.dbsym r c 16 c
.dbend
.dbfunc e puts _puts fI
; s -> R10,R11
.even
_puts::
xcall push_gset3x
movw R10,R16
.dbline -1
.dbline 84
; int puts(char *s)
; {
xjmp L16
L15:
.dbline 86
.dbline 87
movw R30,R10
ldd R16,z+0
xcall _putchar
.dbline 88
movw R24,R10
adiw R24,1
movw R10,R24
.dbline 89
L16:
.dbline 85
; while (*s)
movw R30,R10
ldd R2,z+0
tst R2
brne L15
.dbline 90
; {
; putchar(*s);
; s++;
; }
; putchar(0x0a); //回车换行
ldi R16,10
xcall _putchar
.dbline 91
; putchar(0x0d);
ldi R16,13
xcall _putchar
.dbline 92
; return 1;
ldi R16,1
ldi R17,0
.dbline -2
L14:
xcall pop_gset3x
.dbline 0 ; func end
ret
.dbsym r s 10 pc
.dbend
.dbfunc e init_kb _init_kb fV
.even
_init_kb::
.dbline -1
.dbline 95
; }
; void init_kb(void)
; {
.dbline 96
; PIN_DIR&=~((1<<CLOCK)|(1<<DATAPIN));
in R24,0x11
andi R24,243
out 0x11,R24
.dbline 97
; PORT_KB|=(1<<CLOCK)|(1<<DATAPIN);
in R24,0x12
ori R24,12
out 0x12,R24
.dbline 98
; MCUCR = 0x08;
ldi R24,8
out 0x35,R24
.dbline 99
; GICR = 0x80;
ldi R24,128
out 0x3b,R24
.dbline 100
; SEI();
sei
.dbline 101
; bitcount = 11;
ldi R24,11
sts _bitcount,R24
.dbline -2
.dbline 102
; }
L18:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\键盘演示程序\Keyboard.c
L20:
.blkb 1
L21:
.blkb 1
L22:
.blkb 1
.area text(rom, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\键盘演示程序\Keyboard.c
.dbfunc e decode _decode fV
.dbsym s shiftup L22 c
.dbsym s up L21 c
.dbsym s shift L20 c
; i -> R10
; sc -> R12
.even
_decode::
xcall push_gset5x
mov R12,R16
.dbline -1
.dbline 106
;
;
; void decode(unsigned char sc) //对PC键盘的扫描码进行解码
; {
.dbline 109
; static unsigned char shift,up,shiftup;
; unsigned char i;
; if (sc==0xf0) //按键释放
mov R24,R12
cpi R24,240
brne L23
.dbline 110
; {
.dbline 111
; up=1;
ldi R24,1
sts L21,R24
.dbline 112
; return;
xjmp L19
L23:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -