📄 低频频率计.s
字号:
.module _低频频率计.c
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列单片机实验开发板演示程序\低频频率计/delay.h
.dbfunc e DelayUS _DelayUS fV
; time -> R16,R17
.even
_DelayUS::
.dbline -1
.dbline 9
; //包含所需头文件
; #include <ioM16v.h>
; #include <macros.h>
; #include "delay.h"
;
;
;
; /*------宏定义------*/
; #define uchar unsigned char
xjmp L3
L2:
.dbline 11
subi R16,1
sbci R17,0
L3:
.dbline 10
; #define uint unsigned int
ldi R24,1
ldi R25,0
cp R24,R16
cpc R25,R17
brlo L2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r time 16 i
.dbend
.dbfunc e DelayMS _DelayMS fV
; i -> R20,R21
; time -> R16,R17
.even
_DelayMS::
xcall push_gset1
.dbline -1
.dbline 20
; uint m,value;
; const uchar led_date[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
; const uchar led_seg[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
;
; //端口初始化
; void port_init(void)
; {
; PORTA = 0xFF;
; DDRA = 0xFF;
; PORTB = 0xFF;
xjmp L7
L6:
.dbline 23
; DDRB = 0xFF;
; PORTC = 0x00;
; DDRC = 0x00;
.dbline 24
; PORTD = 0x40;
ldi R20,1
ldi R21,0
xjmp L12
L9:
.dbline 25
L10:
.dbline 24
subi R20,255 ; offset = 1
sbci R21,255
L12:
.dbline 24
cpi R20,118
ldi R30,4
cpc R21,R30
brlo L9
.dbline 26
L7:
.dbline 22
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L6
tst R3
brne L6
X0:
.dbline -2
L5:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r time 16 i
.dbend
.area lit(rom, con, rel)
_led_date::
.byte 192,249
.byte 164,176
.byte 153,146
.byte 130,248
.byte 128,144
.byte 136,131
.byte 198,161
.byte 134,142
.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列单片机实验开发板演示程序\低频频率计\低频频率计.c
.dbsym e led_date _led_date A[16:16]kc
_led_seg::
.byte 254,253
.byte 251,247
.byte 239,223
.byte 191,127
.dbsym e led_seg _led_seg A[8:8]kc
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列单片机实验开发板演示程序\低频频率计\低频频率计.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 17
.dbline 18
ldi R24,255
out 0x1b,R24
.dbline 19
out 0x1a,R24
.dbline 20
out 0x18,R24
.dbline 21
out 0x17,R24
.dbline 22
clr R2
out 0x15,R2
.dbline 23
out 0x14,R2
.dbline 24
ldi R24,64
out 0x12,R24
.dbline 25
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L13:
.dbline 0 ; func end
ret
.dbend
.dbfunc e timer1_init _timer1_init fV
.even
_timer1_init::
.dbline -1
.dbline 31
; }
;
;
; //定时T1初始化
; void timer1_init(void)
; {
.dbline 32
; TCCR1B = 0x00;//停止定时器
clr R2
out 0x2e,R2
.dbline 33
; TIMSK |= 0x20;//中断允许
in R24,0x39
ori R24,32
out 0x39,R24
.dbline 34
; TCNT1H = 0x00;
out 0x2d,R2
.dbline 35
; TCNT1L = 0x00;//初始值
out 0x2c,R2
.dbline 36
; OCR1AH = 0x00;
out 0x2b,R2
.dbline 37
; OCR1AL = 0x00;//匹配A值
out 0x2a,R2
.dbline 38
; OCR1BH = 0x00;
out 0x29,R2
.dbline 39
; OCR1BL = 0x00;//匹配B值
out 0x28,R2
.dbline 40
; ICR1H = 0xFF;
ldi R24,255
out 0x27,R24
.dbline 41
; ICR1L = 0xFF;//输入捕捉匹配值
out 0x26,R24
.dbline 42
; TCCR1A = 0x00;
out 0x2f,R2
.dbline 43
; TCCR1B = 0x42;//启动定时器
ldi R24,66
out 0x2e,R24
.dbline -2
L14:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 20
jmp _timer1_capt_isr
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列单片机实验开发板演示程序\低频频率计\低频频率计.c
.dbfunc e timer1_capt_isr _timer1_capt_isr fV
.even
_timer1_capt_isr::
st -y,R2
st -y,R3
st -y,R4
st -y,R5
st -y,R16
st -y,R17
st -y,R18
st -y,R19
st -y,R24
st -y,R30
in R2,0x3f
st -y,R2
xcall push_gset2
.dbline -1
.dbline 50
; }
;
;
; //定时器T1输入捕捉中断服务程序
; #pragma interrupt_handler timer1_capt_isr:6
; void timer1_capt_isr(void)
; {
.dbline 52
; //timer 1 input capture event, read (int)value in ICR1 using;
; TCNT1=0;
clr R2
clr R3
out 0x2d,R3
out 0x2c,R2
.dbline 53
; value=ICR1L; //Read low byte first (important)
in R2,0x26
clr R3
sts _value+1,R3
sts _value,R2
.dbline 54
; value|=(int)ICR1H << 8; //Read high byte and shift into top byte
in R2,0x27
clr R3
mov R3,R2
clr R2
lds R4,_value
lds R5,_value+1
or R4,R2
or R5,R3
sts _value+1,R5
sts _value,R4
.dbline 55
; m=1000000/value;
movw R2,R4
clr R4
clr R5
ldi R20,64
ldi R21,66
ldi R22,15
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall div32s
sts _m+1,R17
sts _m,R16
.dbline 56
; TIFR|=BIT(ICF1);//软件写1清中断标志
in R24,0x38
ori R24,32
out 0x38,R24
.dbline -2
L15:
xcall pop_gset2
ld R2,y+
out 0x3f,R2
ld R30,y+
ld R24,y+
ld R19,y+
ld R18,y+
ld R17,y+
ld R16,y+
ld R5,y+
ld R4,y+
ld R3,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 61
; }
;
;
; void init_devices(void)
; {
.dbline 62
; CLI(); //禁止所有中断
cli
.dbline 63
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 64
; MCUCSR = 0x80;//禁止JTAG
ldi R24,128
out 0x34,R24
.dbline 65
; GICR = 0x00;
out 0x3b,R2
.dbline 66
; port_init();
xcall _port_init
.dbline 67
; timer1_init();
xcall _timer1_init
.dbline 68
; SEI();//开全局中断
sei
.dbline -2
L16:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 72
; }
; //主函数
; void main(void)
; {
.dbline 73
; init_devices();
xcall _init_devices
xjmp L19
L18:
.dbline 76
.dbline 77
ldi R18,10
ldi R19,0
lds R16,_m
lds R17,_m+1
xcall mod16u
movw R30,R16
ldi R24,<_led_date
ldi R25,>_led_date
add R30,R24
adc R31,R25
lpm R30,Z
out 0x18,R30
.dbline 78
ldi R24,254
out 0x1b,R24
.dbline 79
ldi R16,100
ldi R17,0
xcall _DelayUS
.dbline 80
ldi R18,10
ldi R19,0
lds R16,_m
lds R17,_m+1
xcall div16u
ldi R18,10
ldi R19,0
xcall mod16u
movw R30,R16
ldi R24,<_led_date
ldi R25,>_led_date
add R30,R24
adc R31,R25
lpm R30,Z
out 0x18,R30
.dbline 81
ldi R24,253
out 0x1b,R24
.dbline 82
ldi R16,100
ldi R17,0
xcall _DelayUS
.dbline 83
ldi R18,100
ldi R19,0
lds R16,_m
lds R17,_m+1
xcall div16u
ldi R18,10
ldi R19,0
xcall mod16u
movw R30,R16
ldi R24,<_led_date
ldi R25,>_led_date
add R30,R24
adc R31,R25
lpm R30,Z
out 0x18,R30
.dbline 84
ldi R24,251
out 0x1b,R24
.dbline 85
ldi R16,100
ldi R17,0
xcall _DelayUS
.dbline 86
ldi R18,1000
ldi R19,3
lds R16,_m
lds R17,_m+1
xcall div16u
ldi R18,10
ldi R19,0
xcall mod16u
movw R30,R16
ldi R24,<_led_date
ldi R25,>_led_date
add R30,R24
adc R31,R25
lpm R30,Z
out 0x18,R30
.dbline 87
ldi R24,247
out 0x1b,R24
.dbline 88
ldi R16,100
ldi R17,0
xcall _DelayUS
.dbline 89
ldi R18,10000
ldi R19,39
lds R16,_m
lds R17,_m+1
xcall div16u
ldi R18,10
ldi R19,0
xcall mod16u
movw R30,R16
ldi R24,<_led_date
ldi R25,>_led_date
add R30,R24
adc R31,R25
lpm R30,Z
out 0x18,R30
.dbline 90
ldi R24,239
out 0x1b,R24
.dbline 91
ldi R16,100
ldi R17,0
xcall _DelayUS
.dbline 92
ldi R20,160
ldi R21,134
ldi R22,1
ldi R23,0
lds R2,_m
lds R3,_m+1
clr R4
clr R5
st -y,R23
st -y,R22
st -y,R21
st -y,R20
movw R16,R2
movw R18,R4
xcall div32s
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall mod32s
movw R30,R16
ldi R24,<_led_date
ldi R25,>_led_date
add R30,R24
adc R31,R25
lpm R30,Z
out 0x18,R30
.dbline 93
ldi R24,223
out 0x1b,R24
.dbline 94
ldi R16,100
ldi R17,0
xcall _DelayUS
.dbline 95
ldi R20,64
ldi R21,66
ldi R22,15
ldi R23,0
lds R2,_m
lds R3,_m+1
clr R4
clr R5
st -y,R23
st -y,R22
st -y,R21
st -y,R20
movw R16,R2
movw R18,R4
xcall div32s
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall mod32s
movw R30,R16
ldi R24,<_led_date
ldi R25,>_led_date
add R30,R24
adc R31,R25
lpm R30,Z
out 0x18,R30
.dbline 96
ldi R24,191
out 0x1b,R24
.dbline 97
ldi R16,100
ldi R17,0
xcall _DelayUS
.dbline 98
ldi R20,128
ldi R21,150
ldi R22,152
ldi R23,0
lds R2,_m
lds R3,_m+1
clr R4
clr R5
st -y,R23
st -y,R22
st -y,R21
st -y,R20
movw R16,R2
movw R18,R4
xcall div32s
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall mod32s
movw R30,R16
ldi R24,<_led_date
ldi R25,>_led_date
add R30,R24
adc R31,R25
lpm R30,Z
out 0x18,R30
.dbline 99
ldi R24,127
out 0x1b,R24
.dbline 100
ldi R16,100
ldi R17,0
xcall _DelayUS
.dbline 101
L19:
.dbline 75
xjmp L18
X1:
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列单片机实验开发板演示程序\低频频率计\低频频率计.c
_value::
.blkb 2
.dbsym e value _value i
_m::
.blkb 2
.dbsym e m _m i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -