📄 ds1302.s
字号:
.module DS1302.c
.area data(ram, con, rel)
_WriteAddress::
.blkb 2
.area idata
.byte 140,136
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 134,132
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 130,128
.area data(ram, con, rel)
.blkb 1
.area idata
.byte 138
.area data(ram, con, rel)
.dbfile E:\biyesheji\TESTBE~1\DS1302\程序/ds1302.h
.dbsym e WriteAddress _WriteAddress A[7:7]c
_WriteTime::
.blkb 2
.area idata
.byte 16,18
.area data(ram, con, rel)
.dbfile E:\biyesheji\TESTBE~1\DS1302\程序/ds1302.h
.blkb 2
.area idata
.byte 49,36
.area data(ram, con, rel)
.dbfile E:\biyesheji\TESTBE~1\DS1302\程序/ds1302.h
.blkb 2
.area idata
.byte 'P,48
.area data(ram, con, rel)
.dbfile E:\biyesheji\TESTBE~1\DS1302\程序/ds1302.h
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile E:\biyesheji\TESTBE~1\DS1302\程序/ds1302.h
.dbsym e WriteTime _WriteTime A[7:7]c
.area text(rom, con, rel)
.dbfile E:\biyesheji\TESTBE~1\DS1302\程序/ds1302.h
.dbfunc e DS1302_set _DS1302_set fV
; i -> R16
.even
_DS1302_set::
.dbline -1
.dbline 44
; //ICC-AVR 修改日期: 2006-10-29 15:38:44
; //姓名:荣俊齐
; // Target : M8
; // Crystal: 1.0000Mhz
;
; #include <iom8v.h>
; #include <macros.h>
; #include "ds1302.h"
; #include "DELAY.C"
; const char SEG_table[10]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};
; char Sec_buffer[4]={0,0,0,0};
; char Min_buffer[4]={0,0,0,0};
;
; /******************************************************************************
; 定义164的时钟和数据线
; ********************************************************************************/
; #define DATA_1 PORTD|=(1<<0)
; #define DATA_0 PORTD&=~(1<<0)
; #define CLK_1 PORTD|=(1<<1)
; #define CLK_0 PORTD&=~(1<<1)
; /******************************************************************************
; 定义数码管的选择端口
; ********************************************************************************/
; #define LED1 PORTD=0X07//LED2
; #define LED2 PORTD=0X0B//LED1
; #define LED3 PORTD=0X13//LED3
; #define LED4 PORTD=0X23//LED4
; #define LED0 PORTD=0X03//灭
;
; /*******************************************************************************
; 单片机初始化程序
;
; ******************************************************************************/
; void port_init(void)
; {
; PORTB = 0x00;
; DDRB = 0x00;
; PORTC = 0x00; //m103 output only
; DDRC = 0xff;
; PORTD = 0x00;
; DDRD = 0xFF;
; }
;
; //TIMER1 initialize - prescale:1
.dbline 45
; // WGM: 0) Normal, TOP=0xFFFF
cbi 0x15,1
.dbline 46
; // desired value: 1mSec
cbi 0x15,0
.dbline 47
; // actual value: 1.000mSec (0.0%)
clr R16
rjmp L5
L2:
.dbline 48
.dbline 49
nop
.dbline 50
L3:
.dbline 47
inc R16
L5:
.dbline 47
cpi R16,8
brlo L2
.dbline 51
; void timer1_init(void)
; {
; TCCR1B = 0x00; //stop
; TCNT1H = 0xFC; //setup
sbi 0x15,0
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbend
.dbfunc e DS1302_Write _DS1302_Write fV
; i -> R20,R21
; x -> R22
.even
_DS1302_Write::
rcall push_gset2
mov R22,R16
.dbline -1
.dbline 57
; TCNT1L = 0x18;
; OCR1AH = 0x03;
; OCR1AL = 0xE8;
; OCR1BH = 0x03;
; OCR1BL = 0xE8;
; ICR1H = 0x03;
.dbline 60
; ICR1L = 0xE8;
; TCCR1A = 0x00;
; TCCR1B = 0x01; //start Timer
cbi 0x15,1
.dbline 61
; }
sbi 0x14,2
.dbline 62
;
clr R20
clr R21
L7:
.dbline 63
;
.dbline 63
cbi 0x15,1
.dbline 64
; void init_devices(void)
ldi R16,1
ldi R17,0
movw R18,R20
rcall lsl16
mov R2,R22
clr R3
and R2,R16
and R3,R17
tst R2
brne X0
tst R3
breq L11
X0:
.dbline 65
; {
sbi 0x15,2
rjmp L12
L11:
.dbline 67
; CLI(); //disable all interrupts
; port_init();
cbi 0x15,2
L12:
.dbline 68
nop
.dbline 69
sbi 0x15,1
.dbline 70
nop
.dbline 71
L8:
.dbline 62
subi R20,255 ; offset = 1
sbci R21,255
.dbline 62
cpi R20,8
ldi R30,0
cpc R21,R30
brlt L7
.dbline 72
; timer1_init();
; MCUCR = 0x00;
; GICR = 0x00;
; TIMSK = 0x04;
; SEI(); //re-enable interrupts
cbi 0x15,1
.dbline -2
L6:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 I
.dbsym r x 22 c
.dbend
.dbfunc e DS1302_WriteT _DS1302_WriteT fV
; time -> R20
; ddr -> R22
.even
_DS1302_WriteT::
rcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 76
;
; }
; /*******************************************************************************
; 显示程序
.dbline 77
;
rcall _DS1302_set
.dbline 78
; ******************************************************************************/
mov R16,R22
rcall _DS1302_Write
.dbline 79
; /*发送显示一个字节*/
mov R16,R20
rcall _DS1302_Write
.dbline -2
L13:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r time 20 c
.dbsym r ddr 22 c
.dbend
.dbfunc e DS1302_Read _DS1302_Read fc
; temp -> R20
; temp2 -> R22
; temp1 -> R10
; k -> R12
; n -> R14
; xx -> R12
.even
_DS1302_Read::
rcall push_gset5
mov R12,R16
.dbline -1
.dbline 85
; void sendbeyt(char x)
; {
; int i;
; for(i=0;i<8;i++)
; {
; CLK_1;
.dbline 86
; if(x&(1<<i))
clr R20
.dbline 87
; DATA_1;
clr R10
.dbline 88
; else
clr R22
.dbline 89
; DATA_0;
rcall _DS1302_set
.dbline 90
; CLK_0;
mov R16,R12
rcall _DS1302_Write
.dbline 91
; }
cbi 0x14,2
.dbline 92
; CLK_1;
cbi 0x15,1
.dbline 93
; }
clr R14
rjmp L18
L15:
.dbline 94
;
.dbline 94
cbi 0x15,1
.dbline 95
; /* 发送显示4字节*/
nop
.dbline 96
; void sendFOURbeyt()
in R24,0x13
andi R24,4
mov R12,R24
.dbline 97
; { LED3;
cpi R24,4
brne L19
.dbline 98
; sendbeyt(SEG_table[Sec_buffer[0]]);
ldi R16,1
mov R17,R14
rcall lsl8
or R10,R16
rjmp L20
L19:
.dbline 100
; delay_nus(200);
; LED4;
ldi R16,1
mov R17,R14
rcall lsl8
mov R2,R16
com R2
and R10,R2
L20:
.dbline 101
sbi 0x15,1
.dbline 102
nop
.dbline 103
L16:
.dbline 93
inc R14
L18:
.dbline 93
mov R24,R14
cpi R24,4
brlo L15
.dbline 104
; sendbeyt(SEG_table[Sec_buffer[1]]);
; delay_nus(200);
; LED1;
; sendbeyt(SEG_table[Min_buffer[0]]);
clr R14
rjmp L24
L21:
.dbline 105
; delay_nus(200);
.dbline 105
cbi 0x15,1
.dbline 106
; LED2;
nop
.dbline 107
; sendbeyt(SEG_table[Min_buffer[1]]);
in R24,0x13
andi R24,4
mov R12,R24
.dbline 108
; delay_nus(200);
cpi R24,4
brne L25
.dbline 109
; LED0;
ldi R16,1
mov R17,R14
rcall lsl8
or R22,R16
rjmp L26
L25:
.dbline 111
; delay_nus(200);
; }
ldi R16,1
mov R17,R14
rcall lsl8
mov R2,R16
com R2
and R22,R2
L26:
.dbline 112
sbi 0x15,1
.dbline 113
nop
.dbline 114
L22:
.dbline 104
inc R14
L24:
.dbline 104
mov R24,R14
cpi R24,3
brlo L21
.dbline 115
; /*******************************************************************************
; 中断送显程序
;
; ******************************************************************************/
ldi R24,10
mul R24,R10
mov R20,R0
add R20,R22
.dbline 116
; #pragma interrupt_handler timer1_ovf_isr:9
cbi 0x15,1
.dbline 117
; void timer1_ovf_isr(void)
mov R16,R20
.dbline -2
L14:
rcall pop_gset5
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r temp2 22 c
.dbsym r temp1 10 c
.dbsym r k 12 c
.dbsym r n 14 c
.dbsym r xx 12 c
.dbend
.dbfunc e DS1302_ReadTime _DS1302_ReadTime fV
.even
_DS1302_ReadTime::
.dbline -1
.dbline 123
; {
; sendFOURbeyt();
; //TIMER1 has overflowed
; TCNT1H = 0xFC; //reload counter high value
; TCNT1L = 0x18; //reload counter low value
; }
.dbline 124
; /******************************************************************************
ldi R16,129
rcall _DS1302_Read
mov R2,R16
clr R3
sts _second+1,R3
sts _second,R2
.dbline 125
; BCD分解为数组元素
ldi R16,131
rcall _DS1302_Read
mov R2,R16
clr R3
sts _minute+1,R3
sts _minute,R2
.dbline 126
; ***************************************************************************/
ldi R16,133
rcall _DS1302_Read
mov R2,R16
clr R3
sts _hour+1,R3
sts _hour,R2
.dbline 127
; void BINtoArray(char *p,unsigned int count)
ldi R16,135
rcall _DS1302_Read
mov R2,R16
clr R3
sts _date+1,R3
sts _date,R2
.dbline 128
; { unsigned char i,temp;
ldi R16,137
rcall _DS1302_Read
mov R2,R16
clr R3
sts _month+1,R3
sts _month,R2
.dbline 129
; CLI();
ldi R16,141
rcall _DS1302_Read
mov R2,R16
clr R3
sts _year+1,R3
sts _year,R2
.dbline -2
L27:
.dbline 0 ; func end
ret
.dbend
.dbfunc e DS1302_WriteTime _DS1302_WriteTime fV
; time -> R20,R21
; ddr -> R22,R23
.even
_DS1302_WriteTime::
rcall push_gset2
.dbline -1
.dbline 136
; for(i=0;i<4;i++)
; {
; temp=count%10;
; *p=temp;
; count=count/10;
; p++;
; }
.dbline 137
; SEI();
ldi R22,<_WriteAddress
ldi R23,>_WriteAddress
.dbline 138
; }
ldi R20,<_WriteTime
ldi R21,>_WriteTime
rjmp L30
L29:
.dbline 140
.dbline 141
movw R30,R20
ldd R18,z+0
movw R30,R22
ldd R16,z+0
rcall _DS1302_WriteT
.dbline 142
subi R22,255 ; offset = 1
sbci R23,255
.dbline 143
subi R20,255 ; offset = 1
sbci R21,255
.dbline 144
L30:
.dbline 139
;
movw R30,R22
ldd R2,z+0
tst R2
brne L29
.dbline -2
L28:
rcall pop_gset2
.dbline 0 ; func end
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -