📄 m16ds1302.s
字号:
.module M16DS1302.c
.area text(rom, con, rel)
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\M16DS1302.c
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\..\ICC_H\SOFTWARE.H
.dbfunc e ChangeIntToHex _ChangeIntToHex fV
; dec -> R20,R21
.even
_ChangeIntToHex::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 136
; /*******************************************************************
; 实验十三
; 实验名称: DS1302时钟实验
; 实验目的: 学习AVR单片机读写时钟芯片,综合应用定时器中断溢出,串口通信
; 实验现象: 每隔4SPC机得一时间,十六进制格式
; 环 境: ICCAVR6.31A
; 设 计 者: shinea8868
; 说 明: 部分程序原型源自网络,经本人修改调试可用,请尊重知识产权,如
; 作商业用途请保留本段文字
; 完成日期: 2007年4月11日
; *******************************************************************/
; #include <iom16v.h>
; #include <macros.h>
; #include "..\ICC_H\SOFTWARE.H"
; #include "..\ICC_H\DS1302.H"
;
; uchar RecvFlag = 0; //串口接收到数据中断标志
; uchar DispFlag = 0; //送显时间标志
; uchar temp1; //暂存得串口得到的数据
; /*-----------------------------------------------------------------
; 函数名称: void Uart0Init(void)
; 函数功能: 串口初始化
; 波特率 600 0.2% 字符长度 8bit 无奇偶校验
; 参 数:
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void Uart0Init(void)
; {
; UCSRB = 0x00; //关串口
; UCSRA = 0x02; //倍速模式 M16中文P151
; UCSRC = BIT(URSEL) | 0x06; //写UCSRC寄存器,设定8个bit
; UBRR = 12; //设定串口波特率为600
; UCSRB = 0x98; //开串口
; }
; /*-----------------------------------------------------------------
; 函数名称: void UartRecvData(void)
; 函数功能:
; 参 数:
; 返 回 值: 无
; -----------------------------------------------------------------*/
; #pragma interrupt_handler UartRecvData:12
; void UartRecvData(void)
; {
; temp1 = UDR;
; RecvFlag = 1;
; }
; /*-----------------------------------------------------------------
; 函数名称: void UartTransmitData(uchar *SendData, uchar len)
; 函数功能: 发送字符串
; 参 数: SendData 发送字符串的首地址
; len 发送字符串的长度
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void UartTransmitData(uchar *SendData, uint len)
; {
; uint i;
; for( i = 0; i < len; i++)
; {
; while(!(UCSRA&0x20)); //判断数据寄存器是否为空
; UDR = SendData[i];
; }
; }
; //TIMER1 initialize - prescale:256
; // WGM: 0) Normal, TOP=0xFFFF
; // desired value: 4s
; // actual value: 4s (0.0%)
; void Timer1Init(void)
; {
; TCCR1B = 0x00; //stop
; TCNT1H = 0xC2; //setup
; TCNT1L = 0xF7;
; OCR1AH = 0x0F;
; OCR1AL = 0x42;
; OCR1BH = 0x0F;
; OCR1BL = 0x42;
; ICR1H = 0x0F;
; ICR1L = 0x42;
; TCCR1A = 0x00;
; TCCR1B = 0x04; //start Timer
; }
;
; #pragma interrupt_handler timer1_ovf_isr:9
; void timer1_ovf_isr(void)
; {
; TCNT1H = 0xC2; //重计数
; TCNT1L = 0xF7;
; DispFlag = 1; //送显示
; }
; /*-----------------------------------------------------------------
; 函数名称: void InitDevices(void)
; 函数功能: 初始化各种信息
; 参 数:
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void InitDevices(void)
; {
; CLI(); //关全部中断
; Uart0Init();
; Timer1Init();
; DS1302Init();
;
; TIMSK = 0x04;
; SEI(); //开全中断
; }
;
;
; void main(void)
; {
; uchar temp[3],i;
; InitDevices();
; DDRD = 0xff;
; DS1302SetTime(0x10,0x30,0x25);
; while(1)
; {
; if( DispFlag)
; {
; // i = DS1302Read(0x83);
; DS1302GetTime(temp);
; UartTransmitData(temp,3);
; DispFlag = 0;
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
.dbline 137
; }
movw R30,R20
ldd R2,z+0
clr R3
ldi R17,10
mov R16,R2
xcall mod8u
mov R4,R16
ldi R17,10
mov R16,R2
xcall div8u
mov R24,R16
andi R24,#0x0F
swap R24
or R24,R4
movw R30,R20
std z+0,R24
.dbline -2
L1:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r dec 20 pc
.dbend
.dbfunc e ChangeHexToInt _ChangeHexToInt fV
; hex -> R16,R17
.even
_ChangeHexToInt::
.dbline -1
.dbline 166
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
.dbline 167
; }
movw R30,R16
ldd R2,z+0
clr R3
mov R24,R2
swap R24
andi R24,#0x0F
ldi R25,10
mul R25,R24
mov R24,R2
andi R24,15
mov R2,R0
add R2,R24
std z+0,R2
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbsym r hex 16 pc
.dbend
.dbfunc e Delay _Delay fV
; i -> R16
.even
_Delay::
.dbline -1
.dbline 180
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
; }
.dbline 182
; }
; }
ldi R16,200
L4:
.dbline 183
L5:
.dbline 183
; }
mov R2,R16
clr R3
subi R16,1
tst R2
brne L4
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbend
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\..\ICC_H\DS1302.H
.dbfunc e DS1302WrByte _DS1302WrByte fV
; i -> R20
; x -> R22
.even
_DS1302WrByte::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 66
.dbline 68
sbi 0x11,6
.dbline 69
clr R20
xjmp L11
L8:
.dbline 70
.dbline 71
ldi R16,1
mov R17,R20
xcall lsl8
mov R2,R22
and R2,R16
breq L12
.dbline 72
.dbline 74
sbi 0x12,6
.dbline 75
xjmp L13
L12:
.dbline 77
.dbline 78
cbi 0x12,6
.dbline 79
L13:
.dbline 80
sbi 0x12,5
.dbline 82
cbi 0x12,5
.dbline 83
L9:
.dbline 69
inc R20
L11:
.dbline 69
cpi R20,8
brlo L8
.dbline -2
L7:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r x 22 c
.dbend
.dbfunc e DS1302RdByte _DS1302RdByte fc
; k -> R20
; i -> R22
.even
_DS1302RdByte::
xcall push_gset2
.dbline -1
.dbline 95
.dbline 97
cbi 0x11,6
.dbline 98
clr R22
xjmp L18
L15:
.dbline 99
.dbline 100
in R20,0x10
andi R20,64
.dbline 101
breq L19
.dbline 102
.dbline 103
ldi R16,1
mov R17,R22
xcall lsl8
lds R2,_AA
or R2,R16
sts _AA,R2
.dbline 104
xjmp L20
L19:
.dbline 106
.dbline 107
ldi R16,1
mov R17,R22
xcall lsl8
mov R2,R16
com R2
lds R3,_AA
and R3,R2
sts _AA,R3
.dbline 108
L20:
.dbline 109
sbi 0x12,5
.dbline 110
cbi 0x12,5
.dbline 111
L16:
.dbline 98
inc R22
L18:
.dbline 98
cpi R22,8
brlo L15
.dbline 112
sbi 0x12,5
.dbline 114
cbi 0x12,5
.dbline 115
sbi 0x11,6
.dbline 116
lds R16,_AA
.dbline -2
L14:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r k 20 c
.dbsym r i 22 c
.dbend
.dbfunc e DS1302Write _DS1302Write fV
; ucDa -> R20
; ucAddr -> R22
.even
_DS1302Write::
xcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 127
.dbline 128
cbi 0x12,7
.dbline 129
cbi 0x12,5
.dbline 130
sbi 0x12,7
.dbline 132
mov R16,R22
xcall _DS1302WrByte
.dbline 133
mov R16,R20
xcall _DS1302WrByte
.dbline 135
sbi 0x12,5
.dbline 136
cbi 0x12,7
.dbline -2
L21:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r ucDa 20 c
.dbsym r ucAddr 22 c
.dbend
.dbfunc e DS1302Read _DS1302Read fc
; ucData -> R20
; ucAddr -> R20
.even
_DS1302Read::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 147
.dbline 149
cbi 0x12,7
.dbline 150
cbi 0x12,5
.dbline 151
sbi 0x12,7
.dbline 152
mov R16,R20
xcall _DS1302WrByte
.dbline 153
xcall _DS1302RdByte
mov R20,R16
.dbline 155
sbi 0x12,5
.dbline 157
cbi 0x12,7
.dbline 158
.dbline -2
L22:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r ucData 20 c
.dbsym r ucAddr 20 c
.dbend
.dbfunc e DS1302SetTime _DS1302SetTime fV
; second -> y+4
; minutes -> R22
; hour -> R20
.even
_DS1302SetTime::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 167
.dbline 168
ldd R18,y+4
ldi R16,128
xcall _DS1302Write
.dbline 169
mov R18,R22
ldi R16,130
xcall _DS1302Write
.dbline 170
mov R18,R20
ldi R16,132
xcall _DS1302Write
.dbline -2
L23:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l second 4 c
.dbsym r minutes 22 c
.dbsym r hour 20 c
.dbend
.dbfunc e DS1302GetTime _DS1302GetTime fV
; time -> R20,R21
.even
_DS1302GetTime::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 179
.dbline 180
ldi R16,133
xcall _DS1302Read
movw R30,R20
st Z+,R16
movw R20,R30
.dbline 181
ldi R16,131
xcall _DS1302Read
movw R30,R20
st Z+,R16
movw R20,R30
.dbline 182
ldi R16,129
xcall _DS1302Read
movw R30,R20
st Z+,R16
movw R20,R30
.dbline -2
L24:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r time 20 pc
.dbend
.dbfunc e DS1302Init _DS1302Init fV
.even
_DS1302Init::
.dbline -1
.dbline 191
; }
; }
; }
; }
; }
; }
; }
; }
.dbline 192
; }
sbi 0x11,7
.dbline 193
; }
sbi 0x11,6
.dbline 194
; }
sbi 0x11,5
.dbline -2
L25:
.dbline 0 ; func end
ret
.dbend
.area data(ram, con, rel)
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\..\ICC_H\DS1302.H
_RecvFlag::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\..\ICC_H\DS1302.H
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\M16DS1302.c
.dbsym e RecvFlag _RecvFlag c
_DispFlag::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\M16DS1302.c
.dbsym e DispFlag _DispFlag c
.area text(rom, con, rel)
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\M16DS1302.c
.dbfunc e Uart0Init _Uart0Init fV
.even
_Uart0Init::
.dbline -1
.dbline 28
.dbline 29
clr R2
out 0xa,R2
.dbline 30
ldi R24,2
out 0xb,R24
.dbline 31
ldi R24,134
out 0x20,R24
.dbline 32
ldi R24,12
out 0x9,R24
.dbline 33
ldi R24,152
out 0xa,R24
.dbline -2
L26:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 44
jmp _UartRecvData
.area text(rom, con, rel)
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\M16DS1302.c
.dbfunc e UartRecvData _UartRecvData fV
.even
_UartRecvData::
st -y,R2
st -y,R24
in R2,0x3f
st -y,R2
.dbline -1
.dbline 43
.dbline 44
in R2,0xc
sts _temp1,R2
.dbline 45
ldi R24,1
sts _RecvFlag,R24
.dbline -2
L27:
ld R2,y+
out 0x3f,R2
ld R24,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.dbfunc e UartTransmitData _UartTransmitData fV
; i -> R20,R21
; len -> R18,R19
; SendData -> R16,R17
.even
_UartTransmitData::
xcall push_gset1
.dbline -1
.dbline 55
.dbline 57
clr R20
clr R21
xjmp L32
X0:
.dbline 58
L33:
.dbline 59
L34:
.dbline 59
sbis 0xb,5
rjmp L33
.dbline 60
movw R30,R20
add R30,R16
adc R31,R17
ldd R2,z+0
out 0xc,R2
.dbline 61
L30:
.dbline 57
subi R20,255 ; offset = 1
sbci R21,255
L32:
.dbline 57
cp R20,R18
cpc R21,R19
brlo L34
.dbline -2
L28:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r len 18 i
.dbsym r SendData 16 pc
.dbend
.dbfunc e Timer1Init _Timer1Init fV
.even
_Timer1Init::
.dbline -1
.dbline 68
.dbline 69
clr R2
out 0x2e,R2
.dbline 70
ldi R24,194
out 0x2d,R24
.dbline 71
ldi R24,247
out 0x2c,R24
.dbline 72
ldi R24,15
out 0x2b,R24
.dbline 73
ldi R24,66
out 0x2a,R24
.dbline 74
ldi R24,15
out 0x29,R24
.dbline 75
ldi R24,66
out 0x28,R24
.dbline 76
ldi R24,15
out 0x27,R24
.dbline 77
ldi R24,66
out 0x26,R24
.dbline 78
out 0x2f,R2
.dbline 79
ldi R24,4
out 0x2e,R24
.dbline -2
L36:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 32
jmp _timer1_ovf_isr
.area text(rom, con, rel)
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\M16DS1302.c
.dbfunc e timer1_ovf_isr _timer1_ovf_isr fV
.even
_timer1_ovf_isr::
st -y,R24
in R24,0x3f
st -y,R24
.dbline -1
.dbline 84
.dbline 85
ldi R24,194
out 0x2d,R24
.dbline 86
ldi R24,247
out 0x2c,R24
.dbline 87
ldi R24,1
sts _DispFlag,R24
.dbline -2
L37:
ld R24,y+
out 0x3f,R24
ld R24,y+
.dbline 0 ; func end
reti
.dbend
.dbfunc e InitDevices _InitDevices fV
.even
_InitDevices::
.dbline -1
.dbline 96
.dbline 97
cli
.dbline 98
xcall _Uart0Init
.dbline 99
xcall _Timer1Init
.dbline 100
xcall _DS1302Init
.dbline 102
ldi R24,4
out 0x39,R24
.dbline 103
sei
.dbline -2
L38:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
; i -> <dead>
; temp -> y+1
.even
_main::
sbiw R28,4
.dbline -1
.dbline 108
.dbline 110
xcall _InitDevices
.dbline 111
ldi R24,255
out 0x11,R24
.dbline 112
ldi R24,37
std y+0,R24
ldi R18,48
ldi R16,16
xcall _DS1302SetTime
xjmp L41
L40:
.dbline 114
.dbline 115
lds R2,_DispFlag
tst R2
breq L43
.dbline 116
.dbline 118
movw R16,R28
subi R16,255 ; offset = 1
sbci R17,255
xcall _DS1302GetTime
.dbline 119
ldi R18,3
ldi R19,0
movw R16,R28
subi R16,255 ; offset = 1
sbci R17,255
xcall _UartTransmitData
.dbline 120
clr R2
sts _DispFlag,R2
.dbline 121
L43:
.dbline 122
L41:
.dbline 113
xjmp L40
X1:
.dbline -2
L39:
adiw R28,4
.dbline 0 ; func end
ret
.dbsym l i 2 c
.dbsym l temp 1 A[3:3]c
.dbend
.area bss(ram, con, rel)
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\M16DS1302.c
_temp1::
.blkb 1
.dbsym e temp1 _temp1 c
_AA::
.blkb 1
.dbfile F:\job\M16学习板\DS1302时钟(实验十三)\..\ICC_H\DS1302.H
.dbsym e AA _AA c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -