?? 訓練項目九:ps2鍵盤的使用.s
字號:
.area text(rom, con, rel)
.even
_ps::
st -y,R1
st -y,R2
st -y,R24
st -y,R25
in R1,0x3f
st -y,R1
;
; /****************************************************************************
; ** File Name: PS/2鍵盤的使用
; ** Createed By: Wangchangsong
; ** Create Date: 07/29/2008
; ** Version: 1.0
; ** Descriptions: led display
; **
; **---------------------------------------------------------------------------
; ** Modified By:
; ** Modified Date:
; ** Version:
; ** Descriptions:
; **
; ****************************************************************************/
;
; #include <iom128v.h>
; #include <lcd.h>
; #include <macros.h>
; #pragma interrupt_handler ps:6
; #define DATA PINE&0x20
; unsigned char key = 0;
; unsigned char shift = 0;
; unsigned char up=0;
; unsigned char flag=0;
; unsigned char count=0;
; unsigned char UnShifted[60][2] = {
; 0x1C, 97,
; 0x32, 98,
; 0x21, 99,
; 0x23, 100,
; 0x24, 101,
; 0x2B, 102,
; 0x34, 103,
; 0x33, 104,
; 0x43, 105,
; 0x3B, 106,
; 0x42, 107,
; 0x4B, 108,
; 0x3A, 109,
; 0x31, 110,
; 0x44, 111,
; 0x4D, 112,
; 0x15, 113,
; 0x2D, 114,
; 0x1B, 115,
; 0x2C, 116,
; 0x3C, 117,
; 0x2A, 118,
; 0x1D, 119,
; 0x22, 120,
; 0x35, 121,
; 0x1A, 122,
; 0x45, 48,
; 0x16, 49,
; 0x1E, 50,
; 0x26, 51,
; 0x25, 52,
; 0x2E, 53,
; 0x36, 54,
; 0x3D, 55,
; 0x3E, 56,
; 0x46, 57,
; 0x0E, 39,
; 0x4E, 45,
; 0x55, 61,
; 0x5D, 92,
; 0x29, 32,
; 0x54, 91,
; 0x5B, 93,
; 0x4C, 59,
; 0x52, 39,
; 0x41, 44,
; 0x49, 46,
; 0x4A, 47,
; 0x71, 46,
; 0x70, 48,
; 0x69, 49,
; 0x72, 50,
; 0x7A, 51,
; 0x6B, 52,
; 0x73, 53,
; 0x74, 54,
; 0x6C, 55,
; 0x75, 56,
; 0x7D, 57,
; 0x0d, 9,
; };
; unsigned char Shifted[59][2] = {
; 0x1C, 65,
; 0x32, 66,
; 0x21, 67,
; 0x23, 68,
; 0x24, 69,
; 0x2B, 70,
; 0x34, 71,
; 0x33, 72,
; 0x43, 73,
; 0x3B, 74,
; 0x42, 75,
; 0x4B, 76,
; 0x3A, 77,
; 0x31, 78,
; 0x44, 79,
; 0x4D, 80,
; 0x15, 81,
; 0x2D, 82,
; 0x1B, 83,
; 0x2C, 84,
; 0x3C, 85,
; 0x2A, 86,
; 0x1D, 87,
; 0x22, 88,
; 0x35, 89,
; 0x1A, 90,
; 0x45, 48,
; 0x16, 49,
; 0x1E, 50,
; 0x26, 51,
; 0x25, 52,
; 0x2E, 53,
; 0x36, 54,
; 0x3D, 55,
; 0x3E, 56,
; 0x46, 57,
; 0x0E, 126,
; 0x4E, 95,
; 0x55, 43,
; 0x5D, 124,
; 0x29, 32,
; 0x54, 123,
; 0x5B, 125,
; 0x4C, 58,
; 0x52, 34,
; 0x41, 60,
; 0x49, 62,
; 0x4A, 63,
; 0x71, 46,
; 0x70, 48,
; 0x69, 49,
; 0x72, 50,
; 0x7A, 51,
; 0x6B, 52,
; 0x73, 53,
; 0x74, 54,
; 0x6C, 55,
; 0x75, 56,
; 0x7D, 57,
; };
;
; /****************************************************************************
; ** Function Name: ps
; ** Descriptions: read the key
; ** Input Parameters: void
; ** Output parameters: void
; ** Returned Value: void
; **---------------------------------------------------------------------------
; ****************************************************************************/
;
; void ps (void) /* 讀鍵值 */
; {
; if((count>0)&&(count<9))
lds R2,_count
ldi R24,0
cp R24,R2
brsh L2
X0:
mov R24,R2
cpi R24,9
brsh L2
X1:
; {
; flag=0; /* 標志位 */
clr R2
sts _flag,R2
; key=key>>1;
lds R2,_key
lsr R2
sts _key,R2
; if(DATA)
sbis 0x1,5
rjmp L4
X2:
; key|=0x80;
mov R24,R2
ori R24,128
sts _key,R24
xjmp L3
L4:
; else
; key&=0x7f;
lds R24,_key
andi R24,127
sts _key,R24
; }
xjmp L3
L2:
; else
; flag=1;
ldi R24,1
sts _flag,R24
L3:
; count++;
lds R24,_count
subi R24,255 ; addi 1
sts _count,R24
L6:
;
; while(!(PINE&0x10));
L7:
sbis 0x1,4
rjmp L6
X3:
;
; if(count>10)
ldi R24,10
lds R2,_count
cp R24,R2
brsh L9
X4:
; {
; count=0;
clr R2
sts _count,R2
; }
L9:
L1:
.dbline 0 ; func end
ld R1,y+
out 0x3f,R1
ld R25,y+
ld R24,y+
ld R2,y+
ld R1,y+
reti
; i -> R20
; data -> R16
.even
_key_check::
xcall push_xgsetF000
; }
;
; unsigned char key_check (unsigned char data) /* 查表,處理鍵值 */
; {
; unsigned char i=0;
clr R20
;
; switch(data)
mov R22,R16
clr R23
cpi R22,89
ldi R30,0
cpc R23,R30
breq L19
X5:
ldi R24,89
ldi R25,0
cp R24,R22
cpc R25,R23
brlt L43
X6:
L42:
cpi R22,18
ldi R30,0
cpc R23,R30
breq L16
X7:
xjmp L12
L43:
cpi R22,240
ldi R30,0
cpc R23,R30
breq L15
X8:
xjmp L12
L15:
; {
; case 0xf0:up=1;return(0);
ldi R24,1
sts _up,R24
clr R16
xjmp L11
L16:
; case 0x12:shift=(up==0)?1:0;return(0);
lds R2,_up
tst R2
brne L17
X9:
ldi R22,1
ldi R23,0
xjmp L18
L17:
clr R22
clr R23
L18:
sts _shift,R22
clr R16
xjmp L11
L19:
; case 0x59:shift=(up==0)?1:0;return(0);
lds R2,_up
tst R2
brne L20
X10:
ldi R22,1
ldi R23,0
xjmp L21
L20:
clr R22
clr R23
L21:
sts _shift,R22
clr R16
xjmp L11
L12:
; default:
; {
; if(up==0)
lds R2,_up
tst R2
breq X18
xjmp L22
X18:
X11:
; {
; if(shift==0)
lds R2,_shift
tst R2
brne L24
X12:
; {
; for(i=0;i<60;i++)
clr R20
xjmp L29
L26:
; {
; if (UnShifted[i][0]==data)
ldi R24,<_UnShifted
ldi R25,>_UnShifted
mov R30,R20
clr R31
lsl R30
rol R31
add R30,R24
adc R31,R25
ldd R2,z+0
cp R2,R16
brne L30
X13:
; return(UnShifted[i][1]);
ldi R24,<_UnShifted+1
ldi R25,>_UnShifted+1
mov R30,R20
clr R31
lsl R30
rol R31
add R30,R24
adc R31,R25
ldd R16,z+0
xjmp L11
L30:
; }
L27:
inc R20
L29:
cpi R20,60
brlo L26
X14:
; }
xjmp L23
L24:
; else if(shift==1)
lds R24,_shift
cpi R24,1
brne L23
X15:
; {
; for(i=0;i<59;i++)
clr R20
xjmp L38
L35:
; {
; if (Shifted[i][0]==data)
ldi R24,<_Shifted
ldi R25,>_Shifted
mov R30,R20
clr R31
lsl R30
rol R31
add R30,R24
adc R31,R25
ldd R2,z+0
cp R2,R16
brne L39
X16:
; return(Shifted[i][1]);
ldi R24,<_Shifted+1
ldi R25,>_Shifted+1
mov R30,R20
clr R31
lsl R30
rol R31
add R30,R24
adc R31,R25
ldd R16,z+0
xjmp L11
L39:
; }
L36:
inc R20
L38:
cpi R20,59
brlo L35
X17:
; }
; }
xjmp L23
L22:
; else
; {
; up=0;
clr R2
sts _up,R2
; return(0);
clr R16
L23:
; }
; }
; }
L11:
.dbline 0 ; func end
xjmp pop_xgsetF000
; a -> R10
.even
_main::
sbiw R28,2
; }
;
; /****************************************************************************
; ** Function Name: main
; ** Descriptions:
; ** Input Parameters: void
; ** Output parameters: void
; ** Returned Value: void
; **---------------------------------------------------------------------------
; ****************************************************************************/
;
; void main(void)
; {
;
; unsigned char a=0;
clr R10
;
; MCUCR=0; /* MCU控制寄存器 */
clr R2
out 0x35,R2
; SEI();
sei
; lcd_init();
xcall _lcd_init
; DDRE&=0xcf; /* PE4和PE5作輸入 */
in R24,0x2
andi R24,207
out 0x2,R24
; EIMSK=0x10; /* 外部中斷屏蔽寄存器 */
ldi R24,16
out 0x39,R24
; EICRB=0x02; /* 外部中斷寄存器B */
ldi R24,2
out 0x3a,R24
; lcd_clear();
xcall _lcd_clear
xjmp L46
L45:
; while(1) /* 顯示在液晶顯示器上 */
; {
; a=key_check(key); lcd_putss(0,0,a);}
lds R16,_key
xcall _key_check
mov R10,R16
mov R2,R10
clr R3
std y+1,R3
std y+0,R2
clr R18
clr R19
clr R16
clr R17
xcall _lcd_putss
L46:
xjmp L45
X19:
L44:
.dbline 0 ; func end
adiw R28,2
ret
; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -