📄 tc.s
字号:
.module tc.c
.area text(rom, con, rel)
.dbfile G:\燕洪成\gra_des\exper\tc\tc.c
.dbfile G:\燕洪成\gra_des\exper\inc\myfun.h
.dbfunc e Delayus _Delayus fV
; time -> R16,R17
.even
_Delayus::
.dbline -1
.dbline 4
; #define uchar unsigned char
; //******DelayTime*******//
; void Delayus(int time)
; {
L2:
.dbline 6
; do
; time--;
subi R16,1
sbci R17,0
L3:
.dbline 7
; while(time>1);
ldi R24,1
ldi R25,0
cp R24,R16
cpc R25,R17
brlt L2
X0:
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r time 16 I
.dbend
.dbfunc e Delayms _Delayms fV
; time -> R20,R21
.even
_Delayms::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 10
; }
; void Delayms(unsigned int time)
; {
xjmp L7
L6:
.dbline 12
; while(time!=0)
; {
.dbline 13
; Delayus(1000);
ldi R16,1000
ldi R17,3
xcall _Delayus
.dbline 14
; time--;
subi R20,1
sbci R21,0
.dbline 15
; }
L7:
.dbline 11
cpi R20,0
cpc R20,R21
brne L6
X1:
.dbline -2
L5:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r time 20 i
.dbend
.dbfile G:\燕洪成\gra_des\exper\tc\tc.c
.dbfunc e PORT_Init _PORT_Init fV
.even
_PORT_Init::
.dbline -1
.dbline 14
; // **************************************************************
; // *** 实验: Timer/Counter ***
; // *** 2007年10月13日 ***
; // *** 目标MCU:MEGA168v 晶振:内部 8MHZ ***
; // *** fuse_config:CLKDIV8 disabled ***
; // **************************************************************
; //set_bit:PORTD |=(1<<PORTD3);
; //clr_bit:PORTD &=~(1<<PORTD3);
; #include<iom168v.h>
; #include<macros.h>
; #include<myfun.h>
;
; void PORT_Init(void)
; {
.dbline 15
; DDRD = 0xFF;
ldi R24,255
out 0xa,R24
.dbline -2
L9:
.dbline 0 ; func end
ret
.dbend
.area data(ram, con, rel)
.dbfile G:\燕洪成\gra_des\exper\tc\tc.c
_counter::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile G:\燕洪成\gra_des\exper\tc\tc.c
.dbsym e counter _counter i
.area text(rom, con, rel)
.dbfile G:\燕洪成\gra_des\exper\tc\tc.c
.dbfunc e timer0_init _timer0_init fV
.even
_timer0_init::
.dbline -1
.dbline 25
; }
; //*************************************************//
; //******************* TC **********************//
; //*************************************************//
; unsigned int counter=0;
; //prescale:8;WGM: Normal;
; //desired value: 5KHz
; //actual value: 5.009KHz (0.2%)
; void timer0_init(void)
; {
.dbline 26
; TCCR0B = 0x00; //stop
clr R2
out 0x25,R2
.dbline 27
; TCNT0 = 0x10; //set count
ldi R24,16
out 0x26,R24
.dbline 28
; TCCR0A = 0x00;
out 0x24,R2
.dbline 29
; TIMSK0 = 0x01; //enable timer overflow interrupt
ldi R24,1
sts 110,R24
.dbline 30
; TCCR0B = 0x02; //start timer
ldi R24,2
out 0x25,R24
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 64
jmp _timer0_ovf_isr
.area text(rom, con, rel)
.dbfile G:\燕洪成\gra_des\exper\tc\tc.c
.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
.even
_timer0_ovf_isr::
st -y,R2
st -y,R3
st -y,R24
st -y,R25
st -y,R30
in R2,0x3f
st -y,R2
.dbline -1
.dbline 34
; }
; #pragma interrupt_handler timer0_ovf_isr:17
; void timer0_ovf_isr(void)
; {
.dbline 35
; TCNT0 = 0x10; //set count
ldi R24,16
out 0x26,R24
.dbline 36
; counter++;
lds R24,_counter
lds R25,_counter+1
adiw R24,1
sts _counter+1,R25
sts _counter,R24
.dbline 37
; if(counter == 4000)
cpi R24,160
ldi R30,15
cpc R25,R30
brne L12
X2:
.dbline 38
; PORTD |= (1<<PORTD3);
sbi 0xb,3
L12:
.dbline 39
; if(counter == 8000)
lds R24,_counter
lds R25,_counter+1
cpi R24,64
ldi R30,31
cpc R25,R30
brne L14
X3:
.dbline 40
; {
.dbline 41
; counter = 0;
clr R2
clr R3
sts _counter+1,R3
sts _counter,R2
.dbline 42
; PORTD &= ~(1<<PORTD3);
cbi 0xb,3
.dbline 43
; }
L14:
.dbline -2
L11:
.dbline 0 ; func end
ld R2,y+
out 0x3f,R2
ld R30,y+
ld R25,y+
ld R24,y+
ld R3,y+
ld R2,y+
reti
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 49
; }
; //*************************************************//
; //****************** TC_over **********************//
; //*************************************************//
; void main(void)
; {
.dbline 50
; CLI();
cli
.dbline 51
; PORT_Init();
xcall _PORT_Init
.dbline 52
; timer0_init();
xcall _timer0_init
.dbline 53
; SEI();
sei
L17:
.dbline 55
;
; while(1) ;
L18:
.dbline 55
xjmp L17
X4:
.dbline -2
L16:
.dbline 0 ; func end
ret
.dbend
; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -