.module uart.c
.area text(rom, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\uart.c
.dbfunc e putchar _putchar fV
; c -> R16
.even
_putchar::
.dbline -1
.dbline 21
; /******************************************/
; /* 广州天河双龙电子公司 */
; /* http://www.sl.com.cn */
; /* PS2键盘演示程序 */
; /* 作者:ntzwq@wx88.net */
; /* 2002年5月10日 */
; /* 目标MCU:MEGA8 晶振:外部(EXT) 8MHZ */
; /******************************************/
; // 1、使用ICCAVR的终端调试窗口(Terminal),进行调试。
; // 2、对ICCAVR的终端调试窗口进行设置,设置串口为com1或com2,
; // 通信波特率为19200(Tools->Environment Options...)。
; // 3、将PS2键盘插入SL-MEGA8开发板的PS2键盘插座。
; #include
; #define fosc 8000000 //晶振8MHZ
; #define baud 19200 //波特率
; #define osc_address 0x1ff0
; extern unsigned char read_flash(unsigned int add);
; extern void init_kb(void);
; /* 字符输出函数 */
; void putchar(unsigned char c)
; {
L2:
.dbline 22
L3:
.dbline 22
; while (!(UCSRA&(1 sbis 0xb,5
rjmp L2
.dbline 23
; UDR=c;
out 0xc,R16
.dbline -2
.dbline 24
; }
L1:
.dbline 0 ; func end
ret
.dbsym r c 16 c
.dbend
.dbfunc e puts _puts fI
; s -> R20,R21
.even
_puts::
rcall push_gset1
movw R20,R16
.dbline -1
.dbline 28
; extern unsigned char getchar(void);
; /* 字符串输出函数 */
; int puts(char *s)
; {
rjmp L7
L6:
.dbline 30
.dbline 31
movw R30,R20
ldd R16,z+0
rcall _putchar
.dbline 32
subi R20,255 ; offset = 1
sbci R21,255
.dbline 33
L7:
.dbline 29
; while (*s)
movw R30,R20
ldd R2,z+0
tst R2
brne L6
.dbline 34
; {
; putchar(*s);
; s++;
; }
; putchar(0x0a);//回车换行
ldi R16,10
rcall _putchar
.dbline 35
; putchar(0x0d);
ldi R16,13
rcall _putchar
.dbline 36
; return 1;
ldi R16,1
ldi R17,0
.dbline -2
L5:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r s 20 pc
.dbend
.dbfunc e putstr _putstr fV
; s -> R20,R21
.even
_putstr::
rcall push_gset1
movw R20,R16
.dbline -1
.dbline 40
; }
; /* 不含回车换行的字符串输出函数 */
; void putstr(char *s)
; {
rjmp L11
L10:
.dbline 42
.dbline 43
movw R30,R20
ldd R16,z+0
rcall _putchar
.dbline 44
subi R20,255 ; offset = 1
sbci R21,255
.dbline 45
L11:
.dbline 41
; while (*s)
movw R30,R20
ldd R2,z+0
tst R2
brne L10
.dbline -2
.dbline 46
; {
; putchar(*s);
; s++;
; }
; }
L9:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r s 20 pc
.dbend
.dbfunc e uart_init _uart_init fV
.even
_uart_init::
.dbline -1
.dbline 49
; /* UART初始化 */
; void uart_init(void)
; {
.dbline 50
; OSCCAL=read_flash(osc_address);
ldi R16,8176
ldi R17,31
rcall _read_flash
out 0x31,R16
.dbline 51
; UCSRB=(1 ldi R24,24
out 0xa,R24
.dbline 52
; UBRRL=(fosc/16/(baud+1))%256;
ldi R24,26
out 0x9,R24
.dbline 53
; UBRRH=(fosc/16/(baud+1))/256;
clr R2
out 0x20,R2
.dbline 54
; UCSRC=(1 ldi R24,134
out 0x20,R24
.dbline -2
.dbline 55
; }
L13:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
; i -> R20
.even
_main::
.dbline -1
.dbline 58
; /* RS232通信main函数 */
; void main(void)
; {
.dbline 60
; unsigned char i;
; init_kb();
rcall _init_kb
.dbline 61
; uart_init();
rcall _uart_init
.dbline 62
; puts("广州天河双龙电子公司PS2键盘演示程序");
ldi R16, ldi R17,>L15
rcall _puts
.dbline 63
; puts("HTTP://WWW.SL.COM.CN");
ldi R16, ldi R17,>L16
rcall _puts
.dbline 64
; puts("MAIL TO:sllg@sl.com.cn");
ldi R16, ldi R17,>L17
rcall _puts
.dbline 65
; putchar(0x0a);
ldi R16,10
rcall _putchar
.dbline 66
; putchar(0x0d);//换行
ldi R16,13
rcall _putchar
rjmp L19
L18:
.dbline 68
; while(1)
; {
.dbline 69
; i=getchar();
rcall _getchar
mov R20,R16
.dbline 70
; if (i!=0)//按PC键盘开始测试
tst R16
breq L21
.dbline 71
; {
.dbline 72
; putstr("当前按键是:");
ldi R16, ldi R17,>L23
rcall _putstr
.dbline 73
; putchar(i);
mov R16,R20
rcall _putchar
.dbline 74
; putchar(0x0a);
ldi R16,10
rcall _putchar
.dbline 75
; putchar(0x0d);
ldi R16,13
rcall _putchar
.dbline 76
; puts("广州天河双龙电子公司PS2键盘演示程序");
ldi R16, ldi R17,>L15
rcall _puts
.dbline 77
; puts("HTTP://WWW.SL.COM.CN");
ldi R16, ldi R17,>L16
rcall _puts
.dbline 78
; puts("MAIL TO:sllg@sl.com.cn");
ldi R16, ldi R17,>L17
rcall _puts
.dbline 79
; putchar(0x0a);
ldi R16,10
rcall _putchar
.dbline 80
; putchar(0x0d);
ldi R16,13
rcall _putchar
.dbline 81
; }
L21:
.dbline 82
L19:
.dbline 67
rjmp L18
X0:
.dbline -2
.dbline 83
; }
; }
L14:
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
.area data(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\uart.c
L23:
.blkb 13
.area idata
.byte 181,177,199,176,176,180,188,252,202,199,163,186,0
.area data(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\uart.c
L17:
.blkb 23
.area idata
.byte 'M,'A,'I,'L,32,'T,'O,58,'s,'l,'l,'g,64,'s,'l,46
.byte 'c,'o,'m,46,'c,'n,0
.area data(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\uart.c
L16:
.blkb 21
.area idata
.byte 'H,'T,'T,'P,58,47,47,'W,'W,'W,46,'S,'L,46,'C,'O
.byte 'M,46,'C,'N,0
.area data(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\uart.c
L15:
.blkb 36
.area idata
.byte 185,227,214,221,204,236,186,211,203,171,193,250,181,231,215,211
.byte 185,171,203,190,'P,'S,50,188,252,197,204,209,221,202,190,179
.byte 204,208,242,0
.area data(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\PS2_KEYBOARD\uart.c