📄 timer0.s
字号:
.module timer0.c
.area text(rom, con, rel)
.dbfile F:\WORKS\AVRSIM~1\TIMER0~1\timer0.c
.area data(ram, con, rel)
.dbfile F:\WORKS\AVRSIM~1\TIMER0~1\timer0.c
_hour::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\WORKS\AVRSIM~1\TIMER0~1\timer0.c
.dbsym e hour _hour c
_minute::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\WORKS\AVRSIM~1\TIMER0~1\timer0.c
.dbsym e minute _minute c
_second::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\WORKS\AVRSIM~1\TIMER0~1\timer0.c
.dbsym e second _second c
_counter::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\WORKS\AVRSIM~1\TIMER0~1\timer0.c
.dbsym e counter _counter c
.area text(rom, con, rel)
.dbfile F:\WORKS\AVRSIM~1\TIMER0~1\timer0.c
.dbfunc e send_byte _send_byte fV
; i -> R20
; out_byte -> R10
.even
_send_byte::
st -y,R10
st -y,R20
mov R10,R16
.dbline -1
.dbline 14
; //ICC-AVR application builder : 2007-12-14 下午 03:35:52
; // Target : M16
; // Crystal: 8.0000Mhz
;
; #include <iom16v.h>
; #include <macros.h>
; #include<slavr.h>
; unsigned char hour=0;
; unsigned char minute=0;
; unsigned char second=0;
; unsigned char counter=0;
; //*******************发送字节*******************
; void send_byte( unsigned char out_byte)
; {
.dbline 16
; unsigned char i;
; for (i=0;i<8;i++)
clr R20
xjmp L5
L2:
.dbline 17
; {
.dbline 18
; if (out_byte&0x80)
sbrs R10,7
rjmp L6
X0:
.dbline 19
; {
.dbline 20
; PORTB|=BIT(PB1); //置1data
sbi 0x18,1
.dbline 21
; }
xjmp L7
L6:
.dbline 23
; else
; {
.dbline 24
; PORTB&=~BIT(PB1);//清零
cbi 0x18,1
.dbline 25
; }
L7:
.dbline 26
; PORTB|=BIT(PB2);//置1
sbi 0x18,2
.dbline 27
; out_byte<<=1;
lsl R10
.dbline 28
; delay_us(30);//20//32//30
ldi R16,30
ldi R17,0
xcall _delay_us
.dbline 29
; PORTB&=~BIT(PB2); //清零
cbi 0x18,2
.dbline 30
; delay_us(30);//32//30
ldi R16,30
ldi R17,0
xcall _delay_us
.dbline 31
; }
L3:
.dbline 16
inc R20
L5:
.dbline 16
cpi R20,8
brlo L2
X1:
.dbline 32
; PORTB&=~BIT(PB1);//清零
cbi 0x18,1
.dbline -2
L1:
.dbline 0 ; func end
ld R20,y+
ld R10,y+
ret
.dbsym r i 20 c
.dbsym r out_byte 10 c
.dbend
.dbfunc e write7279 _write7279 fV
; dta -> R10
; cmd -> R12
.even
_write7279::
st -y,R10
st -y,R12
mov R10,R18
mov R12,R16
.dbline -1
.dbline 42
; //delay_us(50);
; //PORTB|=BIT(PB3);//清零cs1
;
; }
; //*******************写入7279*******************
;
;
; //**********************************************
; void write7279(unsigned char cmd, char dta ) //写入7279
; {
.dbline 43
; CLI();
cli
.dbline 44
; delay_us(62);//50//55//62
ldi R16,62
ldi R17,0
xcall _delay_us
.dbline 45
; send_byte (cmd);
mov R16,R12
xcall _send_byte
.dbline 46
; delay_us(33);//20//28//33
ldi R16,33
ldi R17,0
xcall _delay_us
.dbline 47
; send_byte (dta);
mov R16,R10
xcall _send_byte
.dbline 48
; SEI();
sei
.dbline -2
L8:
.dbline 0 ; func end
ld R12,y+
ld R10,y+
ret
.dbsym r dta 10 c
.dbsym r cmd 12 c
.dbend
.dbfunc e display _display fV
.even
_display::
.dbline -1
.dbline 51
; }
; void display(void)
; {
.dbline 52
; write7279(0x83,second%10);//
ldi R17,10
lds R16,_second
xcall mod8u
mov R18,R16
ldi R16,131
xcall _write7279
.dbline 53
; write7279(0x82,second/10);
ldi R17,10
lds R16,_second
xcall div8u
mov R18,R16
ldi R16,130
xcall _write7279
.dbline 54
; write7279(0x81,minute%10);
ldi R17,10
lds R16,_minute
xcall mod8u
mov R18,R16
ldi R16,129
xcall _write7279
.dbline 55
; write7279(0x80,minute/10);
ldi R17,10
lds R16,_minute
xcall div8u
mov R18,R16
ldi R16,128
xcall _write7279
.dbline 56
; write7279(0x85,hour%10);
ldi R17,10
lds R16,_hour
xcall mod8u
mov R18,R16
ldi R16,133
xcall _write7279
.dbline 57
; write7279(0x84,hour/10);
ldi R17,10
lds R16,_hour
xcall div8u
mov R18,R16
ldi R16,132
xcall _write7279
.dbline -2
L9:
.dbline 0 ; func end
ret
.dbend
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 60
; }
; void port_init(void)
; {
.dbline 61
; PORTA = 0x00;
clr R2
out 0x1b,R2
.dbline 62
; DDRA = 0x00;
out 0x1a,R2
.dbline 63
; PORTB = 0x06;
ldi R24,6
out 0x18,R24
.dbline 64
; DDRB = 0x0E;
ldi R24,14
out 0x17,R24
.dbline 65
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 66
; DDRC = 0x00;
out 0x14,R2
.dbline 67
; PORTD = 0x00;
out 0x12,R2
.dbline 68
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbend
.dbfunc e timer0_init _timer0_init fV
.even
_timer0_init::
.dbline -1
.dbline 76
; }
;
; //TIMER0 initialize - prescale:1024
; // WGM: Normal
; // desired value: 10mSec
; // actual value: 9.984mSec (0.2%)
; void timer0_init(void)
; {
.dbline 77
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
.dbline 78
; TCNT0 = 0xB2; //set count
ldi R24,178
out 0x32,R24
.dbline 79
; OCR0 = 0x4E; //set compare
ldi R24,78
out 0x3c,R24
.dbline 80
; TCCR0 = 0x05; //start timer
ldi R24,5
out 0x33,R24
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 36
jmp _timer0_ovf_isr
.area text(rom, con, rel)
.dbfile F:\WORKS\AVRSIM~1\TIMER0~1\timer0.c
.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
.even
_timer0_ovf_isr::
st -y,R2
st -y,R24
st -y,R25
in R2,0x3f
st -y,R2
.dbline -1
.dbline 85
; }
;
; #pragma interrupt_handler timer0_ovf_isr:10
; void timer0_ovf_isr(void)
; {
.dbline 86
; TCNT0 = 0xB2; //reload counter value
ldi R24,178
out 0x32,R24
.dbline 87
; if (counter<10) counter++;
lds R24,_counter
cpi R24,10
brsh L13
X2:
.dbline 87
subi R24,255 ; addi 1
sts _counter,R24
xjmp L14
L13:
.dbline 88
; else {counter=0 ;
.dbline 88
clr R2
sts _counter,R2
.dbline 89
; if (second<60) second++;
lds R24,_second
cpi R24,60
brsh L15
X3:
.dbline 89
subi R24,255 ; addi 1
sts _second,R24
xjmp L16
L15:
.dbline 90
; else {second=0 ;
.dbline 90
clr R2
sts _second,R2
.dbline 91
; if (minute<60) minute++;
lds R24,_minute
cpi R24,60
brsh L17
X4:
.dbline 91
subi R24,255 ; addi 1
sts _minute,R24
xjmp L18
L17:
.dbline 92
; else {minute=0;
.dbline 92
clr R2
sts _minute,R2
.dbline 93
; if (hour<24) hour++;
lds R24,_hour
cpi R24,24
brsh L19
X5:
.dbline 93
subi R24,255 ; addi 1
sts _hour,R24
xjmp L20
L19:
.dbline 94
; else hour=0;
clr R2
sts _hour,R2
L20:
.dbline 95
; }
L18:
.dbline 96
; }
L16:
.dbline 97
; }
L14:
.dbline -2
L12:
.dbline 0 ; func end
ld R2,y+
out 0x3f,R2
ld R25,y+
ld R24,y+
ld R2,y+
reti
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 102
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 104
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 105
; port_init();
xcall _port_init
.dbline 106
; timer0_init();
xcall _timer0_init
.dbline 108
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 109
; GICR = 0x00;
out 0x3b,R2
.dbline 110
; TIMSK = 0x01; //timer interrupt sources
ldi R24,1
out 0x39,R24
.dbline 111
; SEI(); //re-enable interrupts
sei
.dbline -2
L21:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 115
; //all peripherals are now initialized
; }
; void main(void)
; {
.dbline 116
; init_devices();
xcall _init_devices
.dbline 117
; for(;;)
L23:
.dbline 118
; display();
xcall _display
.dbline 117
.dbline 117
xjmp L23
X6:
.dbline -2
L22:
.dbline 0 ; func end
ret
.dbend
; }
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -