📄 训练项目七:键盘的使用.s
字号:
.area vector(rom, abs)
.org 16
jmp _key_check
.module _训练项目七:键盘的使用.c
.area data(ram, con, rel)
_k::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
_n::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.area text(rom, con, rel)
.area func_lit(rom, con, rel)
L24:
.word `L8
.word `L9
.word `L10
.word `L11
.word `L6
.word `L6
.word `L6
.word `L6
.word `L12
.word `L13
.word `L14
.word `L15
.word `L6
.word `L6
.word `L6
.word `L6
.word `L16
.word `L17
.word `L18
.word `L19
.word `L6
.word `L6
.word `L6
.word `L6
.word `L20
.word `L21
.word `L22
.word `L23
.area text(rom, con, rel)
; i -> R10
.even
_main::
; /****************************************************************************
; ** File Name: 键盘的使用
; ** Createed By: Wangchangsong
; ** Create Date: 07/28/2008
; ** Version: 1.0
; ** Descriptions: led display
; **
; **---------------------------------------------------------------------------
; ** Modified By:
; ** Modified Date:
; ** Version:
; ** Descriptions:
; **
; ****************************************************************************/
;
; #include <iom128v.h>
;
; #define data (PIND&0x04)==0x04
; /* 判断PD2是否为1 */
; #define set_cs asm("sbi 0x18,2")
; /* PB输出为1 */
; #define set_clk asm("sbi 0x18,3")
; /* PB3输出为1 */
; #define set_data asm("sbi 0x12,2")
; /* PD2输出为1 */
; #define cl_cs asm("cbi 0x18,2")
; /* PB2输出为0 */
; #define cl_clk asm("cbi 0x18,3")
; /* PB3输出为0 */
; #define cl_data asm("cbi 0x12,2")
; /* PD2输出为0 */
; #pragma interrupt_handler key_check:5
; /* 外部中断3 */
; unsigned char k = 0x00;n = 0;
;
; /****************************************************************************
; ** Function Name: main
; ** Descriptions:
; ** Input Parameters: uiTime
; ** Output parameters: void
; ** Returned Value: void
; **---------------------------------------------------------------------------
; ****************************************************************************/
;
; void main()
; {
; unsigned char i = 0;
clr R10
;
; init_7279();
xcall _init_7279
; s_delay();
xcall _s_delay
; send (0xA4);
ldi R16,164
ldi R17,0
xcall _send
xjmp L3
L2:
; /* 复位 */
; while(1)
; {
; switch(k)
lds R20,_k
clr R21
cpi R20,65
ldi R30,0
cpc R21,R30
brge X3
xjmp L6
X3:
X0:
ldi R24,92
ldi R25,0
cp R24,R20
cpc R25,R21
brge X4
xjmp L6
X4:
X1:
ldi R24,<L24
ldi R25,>L24
movw R30,R20
subi R30,65
sbci R31,0
lsl R30
rol R31
add R30,R24
adc R31,R25
elpm R2,Z+
elpm R3,Z
movw R30,R2
ijmp
L8:
; {
; case 65:set_cs;send(0xc8);send(0x00);break;/*下载数据且按方式1译码 */
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
clr R16
clr R17
xcall _send
xjmp L6
L9:
; case 66:set_cs;send(0xc8);send(0x01);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,1
ldi R17,0
xcall _send
xjmp L6
L10:
; case 67:set_cs;send(0xc8);send(0x02);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,2
ldi R17,0
xcall _send
xjmp L6
L11:
; case 68:set_cs;send(0xc8);send(0x03);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,3
ldi R17,0
xcall _send
xjmp L6
L12:
; case 73:set_cs;send(0xc8);send(0x04);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,4
ldi R17,0
xcall _send
xjmp L6
L13:
; case 74:set_cs;send(0xc8);send(0x05);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,5
ldi R17,0
xcall _send
xjmp L6
L14:
; case 75:set_cs;send(0xc8);send(0x06);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,6
ldi R17,0
xcall _send
xjmp L6
L15:
; case 76:set_cs;send(0xc8);send(0x07);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,7
ldi R17,0
xcall _send
xjmp L6
L16:
; case 81:set_cs;send(0xc8);send(0x08);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,8
ldi R17,0
xcall _send
xjmp L6
L17:
; case 82:set_cs;send(0xc8);send(0x09);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,9
ldi R17,0
xcall _send
xjmp L6
L18:
; case 83:set_cs;send(0xc8);send(0x0A);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,10
ldi R17,0
xcall _send
xjmp L6
L19:
; case 84:set_cs;send(0xc8);send(0x0B);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,11
ldi R17,0
xcall _send
xjmp L6
L20:
; case 89:set_cs;send(0xc8);send(0x0C);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,12
ldi R17,0
xcall _send
xjmp L6
L21:
; case 90:set_cs;send(0xc8);send(0x0D);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,13
ldi R17,0
xcall _send
xjmp L6
L22:
; case 91:set_cs;send(0xc8);send(0x0E);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,14
ldi R17,0
xcall _send
xjmp L6
L23:
; case 92:set_cs;send(0xc8);send(0x0F);break;
sbi 0x18,2
ldi R16,200
ldi R17,0
xcall _send
ldi R16,15
ldi R17,0
xcall _send
; default:break;
L6:
;
; }
; }
L3:
xjmp L2
X2:
L1:
.dbline 0 ; func end
ret
.even
_key_check::
st -y,R0
st -y,R1
st -y,R2
st -y,R3
st -y,R4
st -y,R5
st -y,R6
st -y,R7
st -y,R8
st -y,R9
st -y,R16
st -y,R17
st -y,R18
st -y,R19
st -y,R24
st -y,R25
st -y,R26
st -y,R27
st -y,R30
st -y,R31
in R0,0x3f
st -y,R0
; }
; /****************************************************************************
; ** Function Name: key_check
; ** Descriptions: read the key
; ** Input Parameters: K
; ** Output parameters: void
; ** Returned Value: void
; **---------------------------------------------------------------------------
; ****************************************************************************/
;
; void key_check()
; {
; n=1;
ldi R24,1
ldi R25,0
sts _n+1,R25
sts _n,R24
; send(0x15); /* 读键盘指令 */
ldi R16,21
ldi R17,0
xcall _send
; k=receive()+61;
xcall _receive
movw R24,R16
adiw R24,61
sts _k,R24
; set_cs;
sbi 0x18,2
L25:
.dbline 0 ; func end
ld R0,y+
out 0x3f,R0
ld R31,y+
ld R30,y+
ld R27,y+
ld R26,y+
ld R25,y+
ld R24,y+
ld R19,y+
ld R18,y+
ld R17,y+
ld R16,y+
ld R9,y+
ld R8,y+
ld R7,y+
ld R6,y+
ld R5,y+
ld R4,y+
ld R3,y+
ld R2,y+
ld R1,y+
ld R0,y+
reti
.even
_led_init::
; }
; /****************************************************************************
; ** Function Name: led_init
; ** Descriptions:
; ** Input Parameters: uiTime
; ** Output parameters: void
; ** Returned Value: void
; **---------------------------------------------------------------------------
; ****************************************************************************/
; void led_init (void)
; {
; DDRB|= 0x0C; /* PB0和PB1为输入 */
in R24,0x17
ori R24,12
out 0x17,R24
; set_cs;
sbi 0x18,2
; send (0xA4);
ldi R16,164
ldi R17,0
xcall _send
L26:
.dbline 0 ; func end
ret
.even
_init_7279::
; }
;
; /****************************************************************************
; ** Function Name: init_7279
; ** Descriptions: initialization
; ** Input Parameters: uiTime
; ** Output parameters: void
; ** Returned Value: void
; **---------------------------------------------------------------------------
; ****************************************************************************/
; void init_7279()
; {
; SREG|=0x80; /* 状态寄存器,全局中断允许 */
bset 7
; EIMSK|=0x08; /* 外部中断屏蔽寄存器 */
in R24,0x39
ori R24,8
out 0x39,R24
; EICRA&=0x3f; /* 外部中断控制寄存器A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -