⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ps2_kb.s

📁 驱动开发板上的PS2接口
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module PS2_KB.C
	.area text(rom, con, rel)
	.dbfile C:/icc/include/AVR_PQ1A.h
	.dbfunc e Delayus _Delayus fV
;              i -> R20,R21
;             US -> R22,R23
	.even
_Delayus::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 28
; /*******************************************
;   文件:PS2_KB.C
;   环境:编译为ICC AVR6.25A,仿真为AVR Studio4.10 
;   硬件:ATMEGA16芯片
;   日期:2006年12月10日 
;   功能:驱动开发板上的PS2接口,实现PS2键盘(支持第2套扫描码)
;   备注:参考《AVR系列单片机C语言编程与应用实例》(清华大学出版社)
; /******************************************/
; #include <iom16v.h>			//包含型号头文件
; #include <macros.h>			//包含"位"操作头文件
; #include <stdio.h>			//标准输入输出头文件
; #include <AVR_PQ1A.h>		//包含自定义常量头文件
; #include "YJ1602.C"
; 
; #pragma interrupt_handler Int0:2	//外部中断0中断函数声明			  
; #pragma data:code 		  			//将译码表放在FLASH
; const uchar unshifted[][2]=			//shift键没按下译码表
; {		
;   0x0e,'`',
;   0x15,'q',
;   0x16,'1',
;   0x1a,'z',
;   0x1b,'s',
;   0x1c,'a',
;   0x1d,'w',
;   0x1e,'2',
;   0x21,'c',
;   0x22,'x',
	.dbline 30
;   0x23,'d',
;   0x24,'e',
	ldi R16,5
	ldi R17,0
	movw R18,R22
	xcall empy16s
	movw R22,R16
	lsr R23
	ror R22
	lsr R23
	ror R22
	.dbline 31
	clr R20
	clr R21
	xjmp L5
L2:
	.dbline 31
L3:
	.dbline 31
	subi R20,255  ; offset = 1
	sbci R21,255
L5:
	.dbline 31
;   0x25,'4',
	cp R20,R22
	cpc R21,R23
	brlo L2
	.dbline -2
	.dbline 32
;   0x26,'3',
L1:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r US 22 i
	.dbend
	.dbfunc e Delayms _Delayms fV
;              i -> R20,R21
;              j -> R22,R23
;             MS -> R16,R17
	.even
_Delayms::
	xcall push_gset2
	.dbline -1
	.dbline 40
;   0x29,' ',
;   0x2a,'v',
;   0x2b,'f',
;   0x2c,'t',
;   0x2d,'r',
;   0x2e,'5',
;   0x31,'n',
;   0x32,'b',
	.dbline 42
;   0x33,'h',
;   0x34,'g',
	clr R20
	clr R21
	xjmp L10
L7:
	.dbline 43
	clr R22
	clr R23
	xjmp L14
L11:
	.dbline 43
L12:
	.dbline 43
	subi R22,255  ; offset = 1
	sbci R23,255
L14:
	.dbline 43
	cpi R22,117
	ldi R30,4
	cpc R23,R30
	brlo L11
L8:
	.dbline 42
	subi R20,255  ; offset = 1
	sbci R21,255
L10:
	.dbline 42
	cp R20,R16
	cpc R21,R17
	brlo L7
	.dbline -2
	.dbline 44
;   0x35,'y',
;   0x36,'6',
L6:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r j 22 i
	.dbsym r MS 16 i
	.dbend
	.dbfunc e Board_init _Board_init fV
	.even
_Board_init::
	.dbline -1
	.dbline 52
;   0x39,',',
;   0x3a,'m',
;   0x3b,'j',
;   0x3c,'u',
;   0x3d,'7',
;   0x3e,'8',
;   0x41,',',
;   0x42,'k',
	.dbline 53
;   0x43,'i',
	ldi R24,255
	out 0x1a,R24
	.dbline 54
;   0x44,'o',
	out 0x17,R24
	.dbline 55
;   0x45,'0',
	out 0x14,R24
	.dbline 56
;   0x46,'9',
	out 0x11,R24
	.dbline 58
;   0x49,'.',
;   0x4a,'/',
	clr R2
	out 0xd,R2
	.dbline 60
;   0x4b,'l',
;   0x4c,';',
	sbi 0x1b,6
	.dbline 61
;   0x4d,'p',
	cbi 0x15,6
	.dbline 62
;   0x4e,'-',
	cbi 0x1b,1
	.dbline 63
;   0x52,'\'',
	out 0x18,R24
	.dbline 64
;   0x54,'[',
	sbi 0x1b,2
	.dbline 65
;   0x55,'=',
	ldi R16,5
	ldi R17,0
	xcall _Delayus
	.dbline 66
;   0x5b,']',
	cbi 0x1b,2
	.dbline 68
;   0x5d,'\\',
;   0x61,'<',
	clr R2
	out 0x18,R2
	.dbline 69
;   0x69,'1',
	sbi 0x1b,3
	.dbline 70
;   0x6b,'4',
	ldi R16,50
	ldi R17,0
	xcall _Delayus
	.dbline 71
;   0x6c,'7',
	cbi 0x1b,3
	.dbline 73
;   0x70,'0',
;   0x71,'.',
	ldi R24,255
	out 0x18,R24
	.dbline 74
;   0x72,'2',
	sbi 0x1b,4
	.dbline 75
;   0x73,'5',
	ldi R16,50
	ldi R17,0
	xcall _Delayus
	.dbline 76
;   0x74,'6',
	cbi 0x1b,4
	.dbline 78
;   0x75,'8',
;   0x79,'+',
	ldi R24,255
	out 0x12,R24
	.dbline 79
;   0x7a,'3',
	sbi 0x1b,7
	.dbline 80
;   0x7b,'-',
	ldi R16,50
	ldi R17,0
	xcall _Delayus
	.dbline 81
;   0x7c,'*',
	cbi 0x1b,7
	.dbline -2
	.dbline 84
;   0x7d,'9',
;   0,0
; };
L15:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfile C:\icc\examples.avr\AVR_PQ1A_DEMO\19_PS2/YJ1602.C
	.dbfunc e LCD1602_portini _LCD1602_portini fV
	.even
_LCD1602_portini::
	.dbline -1
	.dbline 20
	.dbline 21
	in R24,0x11
	ori R24,112
	out 0x11,R24
	.dbline 22
	in R24,0x17
	ori R24,255
	out 0x17,R24
	.dbline -2
	.dbline 23
L16:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD1602_readbyte _LCD1602_readbyte fc
;          dByte -> R20
;         DatCmd -> R20
	.even
_LCD1602_readbyte::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 31
	.dbline 33
	tst R20
	brne L18
	.dbline 34
	cbi 0x12,4
	xjmp L19
L18:
	.dbline 36
	sbi 0x12,4
L19:
	.dbline 38
	sbi 0x12,5
	.dbline 39
	sbi 0x12,6
	.dbline 40
	clr R2
	out 0x17,R2
	.dbline 41
	in R20,0x16
	.dbline 42
	ldi R16,1
	ldi R17,0
	xcall _Delayms
	.dbline 43
	cbi 0x12,6
	.dbline 44
	in R24,0x17
	ori R24,255
	out 0x17,R24
	.dbline 45
	mov R16,R20
	.dbline -2
L17:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r dByte 20 c
	.dbsym r DatCmd 20 c
	.dbend
	.dbfunc e LCD1602_sendbyte _LCD1602_sendbyte fV
;          dByte -> R20
;         DatCmd -> R22
	.even
_LCD1602_sendbyte::
	xcall push_gset2
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 55
	.dbline 56
	tst R22
	brne L21
	.dbline 57
	cbi 0x12,4
	xjmp L22
L21:
	.dbline 59
	sbi 0x12,4
L22:
	.dbline 61
	cbi 0x12,5
	.dbline 62
	sbi 0x12,6
	.dbline 63
	out 0x18,R20
	.dbline 64
	ldi R16,1
	ldi R17,0
	xcall _Delayms
	.dbline 65
	cbi 0x12,6
	.dbline -2
	.dbline 66
L20:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r dByte 20 c
	.dbsym r DatCmd 22 c
	.dbend
	.dbfunc e LCD1602_sendstr _LCD1602_sendstr fV
;       ptString -> R20,R21
	.even
_LCD1602_sendstr::
	xcall push_gset1
	movw R20,R16
	.dbline -1
	.dbline 74
	xjmp L25
L24:
	.dbline 76
	.dbline 77
	movw R30,R20
	ld R18,Z+
	movw R20,R30
	ldi R16,1
	xcall _LCD1602_sendbyte
	.dbline 78
L25:
	.dbline 75
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L24
	.dbline -2
	.dbline 79
L23:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r ptString 20 pc
	.dbend
	.dbfunc e LCD1602_clear _LCD1602_clear fV
	.even
_LCD1602_clear::
	.dbline -1
	.dbline 87
; const uchar shifted[][2]=      //shift键按下译码表
; {
;   0x0e,'~',
	.dbline 88
;   0x15,'Q',
	ldi R18,1
	clr R16
	xcall _LCD1602_sendbyte
	.dbline 89
;   0x16,'!',
	ldi R16,2
	ldi R17,0
	.dbline -2
	.dbline 90
;   0x1a,'Z',
L27:
	.dbline 0 ; func end
	xjmp _Delayms
	.dbend
	.dbfunc e LCD1602_readBF _LCD1602_readBF fc
;           busy -> R20
	.even
_LCD1602_readBF::
	xcall push_gset1
	.dbline -1
	.dbline 98
;   0x1b,'S',
;   0x1c,'A',
;   0x1d,'W',
;   0x1e,'@',
;   0x21,'C',
;   0x22,'X',
;   0x23,'D',
;   0x24,'E',
	.dbline 100
;   0x25,'$',
;   0x26,'#',
	clr R16
	xcall _LCD1602_readbyte
	mov R20,R16
	.dbline 101
;   0x29,' ',
	sbrs R16,7
	rjmp L29
	.dbline 102
;   0x2a,'V',
	ldi R20,1
	xjmp L30
L29:
	.dbline 104
;   0x2b,'F',
;   0x2c,'T',
	clr R20
L30:
	.dbline 105
;   0x2d,'R',
	mov R16,R20
	.dbline -2
L28:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r busy 20 c
	.dbend
	.dbfunc e LCD1602_gotoXY _LCD1602_gotoXY fV
;            Col -> R20
;            Row -> R22
	.even
_LCD1602_gotoXY::
	xcall push_gset2
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 115
;   0x2e,'%',
;   0x31,'N',
;   0x32,'B',
;   0x33,'H',
;   0x34,'G',
;   0x35,'Y',
;   0x36,'^',
;   0x39,'L',
;   0x3a,'M',
;   0x3b,'J',
	.dbline 116
;   0x3c,'U',
	clr R23
	cpi R22,2
	ldi R30,0
	cpc R23,R30
	breq L35
	xjmp L32
X0:
	.dbline 117
;   0x3d,'&',
L35:
	.dbline 119
;   0x3e,'*',
;   0x41,'<',
	mov R18,R20
	subi R18,64    ; addi 192
	clr R16
	xcall _LCD1602_sendbyte
	.dbline 119
	xjmp L33
L32:
	.dbline 121
	mov R18,R20
	subi R18,128    ; addi 128
	clr R16
	xcall _LCD1602_sendbyte
	.dbline 121
L33:
	.dbline -2
	.dbline 123
;   0x42,'K',
;   0x43,'I',
;   0x44,'O',
;   0x45,')',
L31:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r Col 20 c
	.dbsym r Row 22 c
	.dbend
	.dbfunc e LCD1602_initial _LCD1602_initial fV
	.even
_LCD1602_initial::
	.dbline -1
	.dbline 131
;   0x46,'(',
;   0x49,'>',
;   0x4a,'?',
;   0x4b,'L',
;   0x4c,':',
;   0x4d,'P',
;   0x4e,'_',
;   0x52,'"',
	.dbline 132
;   0x54,'{',
	ldi R16,100
	ldi R17,0
	xcall _Delayms
	.dbline 133
;   0x55,'+',
	xcall _LCD1602_portini
	.dbline 135
;   0x5b,'}',
;   0x5d,'|',
	ldi R18,56
	clr R16
	xcall _LCD1602_sendbyte
L37:
	.dbline 136
L38:
	.dbline 136
;   0x61,'>',
	xcall _LCD1602_readBF
	tst R16
	brne L37
	.dbline 137
;   0x69,'1',
	ldi R18,12
	clr R16
	xcall _LCD1602_sendbyte
L40:
	.dbline 138
L41:
	.dbline 138
;   0x6b,'4',
	xcall _LCD1602_readBF
	tst R16
	brne L40
	.dbline 139
;   0x6c,'7',
	xcall _LCD1602_clear
L43:
	.dbline 140
L44:
	.dbline 140
;   0x70,'0',
	xcall _LCD1602_readBF
	tst R16
	brne L43
	.dbline 141
;   0x71,'.',
	ldi R18,6
	clr R16
	.dbline -2
	.dbline 142
;   0x72,'2',
L36:
	.dbline 0 ; func end
	xjmp _LCD1602_sendbyte
	.dbend
	.area vector(rom, abs)
	.org 4
	jmp _Int0
	.area text(rom, con, rel)
	.dbfile C:\icc\examples.avr\AVR_PQ1A_DEMO\19_PS2/YJ1602.C
	.area code(ram, con, rel)
	.dbfile C:\icc\examples.avr\AVR_PQ1A_DEMO\19_PS2/YJ1602.C
	.area lit(rom, con, rel)
_unshifted::
	.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 91,93
	.byte 93,92
	.byte 'a,60
	.byte 'i,49
	.byte 'k,52
	.byte 'l,55
	.byte 'p,48
	.byte 'q,46
	.byte 'r,50
	.byte 's,53
	.byte 't,54
	.byte 'u,56
	.byte 'y,43
	.byte 'z,51
	.byte 123,45

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -