📄 timer.s
字号:
.module Timer.c
.area vector(rom, abs)
.org 14
rjmp _Timer0OverInter
.area data(ram, con, rel)
_LightCount::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile E:\罗鹏\工作资料\工作记录\CAN\程序\完成版本\Timer.c
.dbsym e LightCount _LightCount i
_KeyTime::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile E:\罗鹏\工作资料\工作记录\CAN\程序\完成版本\Timer.c
.dbsym e KeyTime _KeyTime c
_KeyStatus::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile E:\罗鹏\工作资料\工作记录\CAN\程序\完成版本\Timer.c
.dbsym e KeyStatus _KeyStatus c
.area text(rom, con, rel)
.dbfile E:\罗鹏\工作资料\工作记录\CAN\程序\完成版本\Timer.c
.dbfunc e KeyInput _KeyInput fc
; KeyData -> R20
; BitData -> R20
.even
_KeyInput::
rcall push_gset1
mov R20,R16
.dbline -1
.dbline 15
; #include "iom8515v.h"
; #include "macros.h"
; #include "MAIN.h"
;
;
; #pragma interrupt_handler Timer0OverInter:8
; uint LightCount=0;
; uchar KeyTime=0;
; uchar Key1,Key2,Key3;
; uchar KeyStatus=0;
; /*****************************************
; 读按键输入口子程序
; ******************************************/
; uchar KeyInput(uchar BitData)
; {
.dbline 17
; uchar KeyData;
; KeyData=(PIND &= (1 << BitData ));
ldi R16,1
mov R17,R20
rcall lsl8
in R2,0x10
and R2,R16
out 0x10,R2
mov R20,R2
.dbline 18
; if(KeyData == 0)
tst R2
brne L2
.dbline 19
; return(1);
ldi R16,1
rjmp L1
L2:
.dbline 21
; else
; return(0);
clr R16
.dbline -2
L1:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r KeyData 20 c
.dbsym r BitData 20 c
.dbend
.dbfunc e Timer0Ini _Timer0Ini fV
.even
_Timer0Ini::
.dbline -1
.dbline 25
; }
;
; void Timer0Ini(void)
; {
.dbline 26
; TCCR0 = 0x00;
clr R2
out 0x33,R2
.dbline 27
; TCNT0 = 0xC2; //定时1ms
ldi R24,194
out 0x32,R24
.dbline 28
; TCCR0 = 0x04; //256分频
ldi R24,4
out 0x33,R24
.dbline 29
; TIMSK = 0x02; //开定时器0溢出中断
ldi R24,2
out 0x39,R24
.dbline -2
L4:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Timer0OverInter _Timer0OverInter fV
.even
_Timer0OverInter::
st -y,R2
st -y,R3
st -y,R24
st -y,R25
st -y,R30
in R2,0x3f
st -y,R2
.dbline -1
.dbline 33
; }
;
; void Timer0OverInter(void)
; {
.dbline 34
; TCNT0 = 0xC2; //恢复定时器初值
ldi R24,194
out 0x32,R24
.dbline 35
; KeyTime++; //按键间隔时间计数器累加
lds R24,_KeyTime
subi R24,255 ; addi 1
sts _KeyTime,R24
.dbline 36
; LightCount++;
lds R24,_LightCount
lds R25,_LightCount+1
adiw R24,1
sts _LightCount+1,R25
sts _LightCount,R24
.dbline 37
; if(KeyTime == 6) //取6ms的时间间隔
lds R24,_KeyTime
cpi R24,6
brne L6
.dbline 38
; {
.dbline 39
; KeyTime=0;
clr R2
sts _KeyTime,R2
.dbline 40
; if((Key1 == 0) && (Key2 == 1) && (Key3 == 1))
lds R2,_Key1
tst R2
brne L8
lds R24,_Key2
cpi R24,1
brne L8
lds R24,_Key3
cpi R24,1
brne L8
.dbline 42
; //如果按键的前后三次状态分别是0、1、1的话,则认为有键按下
; KeyStatus=1; //置位状态标志
ldi R24,1
sts _KeyStatus,R24
rjmp L9
L8:
.dbline 44
; else
; KeyStatus=0; //否则清0状态标志
clr R2
sts _KeyStatus,R2
L9:
.dbline 45
; Key1=Key2;
lds R2,_Key2
sts _Key1,R2
.dbline 46
; Key2=Key3;
lds R2,_Key3
sts _Key2,R2
.dbline 47
; }
L6:
.dbline 58
lds R24,_LightCount
lds R25,_LightCount+1
cpi R24,232
ldi R30,3
cpc R25,R30
brne L10
.dbline 59
.dbline 60
ldi R24,16
in R2,0x12
eor R2,R24
out 0x12,R2
.dbline 61
clr R2
clr R3
sts _LightCount+1,R3
sts _LightCount,R2
.dbline 62
L10:
.dbline -2
L5:
ld R2,y+
out 0x3f,R2
ld R30,y+
ld R25,y+
ld R24,y+
ld R3,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.area bss(ram, con, rel)
.dbfile E:\罗鹏\工作资料\工作记录\CAN\程序\完成版本\Timer.c
_Key3::
.blkb 1
.dbsym e Key3 _Key3 c
_Key2::
.blkb 1
.dbsym e Key2 _Key2 c
_Key1::
.blkb 1
.dbsym e Key1 _Key1 c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -