?? ds1302.s
字號(hào):
sbi 0x17,6
.dbline 114
mov R16,R22
.dbline -2
L51:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r byte 22 c
.dbend
.dbfunc e DS1302_writeD _DS1302_writeD fV
; data -> R20
; addr -> R22
.even
_DS1302_writeD::
xcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 124
.dbline 125
cbi 0x18,4
.dbline 126
cbi 0x18,7
.dbline 127
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 128
sbi 0x18,4
.dbline 129
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 130
mov R16,R22
xcall _DS1302_writeB
.dbline 131
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 132
cbi 0x18,7
.dbline 133
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 134
mov R16,R20
xcall _DS1302_writeB
.dbline 135
; PORTB&=~BIT(RTC_CLK); //拉低時(shí)鐘端
cbi 0x18,7
.dbline 136
; Delayus(10); //調(diào)整片選脈沖
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 137
; PORTB&=~BIT(RTC_CS); //拉低片選端
cbi 0x18,4
.dbline -2
L58:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbsym r addr 22 c
.dbend
.dbfunc e DS1302_readD _DS1302_readD fc
; data -> R20
; addr -> R20
.even
_DS1302_readD::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 146
; }
; /*******************************************
; 函數(shù)名稱: DS1302_readD
; 功 能: 從DS1302的某個(gè)地址讀出一個(gè)字節(jié)數(shù)據(jù)
; 參 數(shù): addr--地址值(寄存器或RAM)
; 返回值 : data--讀出的數(shù)據(jù)
; /********************************************/
; uchar DS1302_readD(uchar addr)
; {
.dbline 148
; uchar data;
; PORTB&=~BIT(RTC_CS); //拉低片選端
cbi 0x18,4
.dbline 149
; PORTB&=~BIT(RTC_CLK); //拉低時(shí)鐘端
cbi 0x18,7
.dbline 150
; Delayus(10);
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 151
; PORTB|=BIT(RTC_CS); //拉高片選端
sbi 0x18,4
.dbline 152
; Delayus(10); //調(diào)整片選脈沖
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 153
; DS1302_writeB(addr); //寫入操作命令(地址)
mov R16,R20
xcall _DS1302_writeB
.dbline 154
; Delayus(10);
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 155
; data=DS1302_readB(); //讀出數(shù)據(jù)
xcall _DS1302_readB
mov R20,R16
.dbline 156
; Delayus(10);
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 157
; PORTB&=~BIT(RTC_CLK); //拉低時(shí)鐘端
cbi 0x18,7
.dbline 158
; PORTB&=~BIT(RTC_CS); //拉低片選端
cbi 0x18,4
.dbline 159
; return data; //返回讀出的數(shù)據(jù)
mov R16,R20
.dbline -2
L59:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbsym r addr 20 c
.dbend
.dbfunc e DS1302_setT _DS1302_setT fV
; addr -> R20
; i -> R22
; ptTimeD -> R10,R11
.even
_DS1302_setT::
xcall push_gset3
movw R10,R16
.dbline -1
.dbline 168
; }
; /*******************************************
; 函數(shù)名稱: DS1302_setT
; 功 能: 設(shè)置DS1302的時(shí)間
; 參 數(shù): ptTimeD--設(shè)置時(shí)間數(shù)組指針
; 返回值 : 無
; /********************************************/
; void DS1302_setT(uchar ptTimeD[])
; {
.dbline 170
; uchar i;
; uchar addr = 0x80; //寫入地址從秒寄存器開始
ldi R20,128
.dbline 171
; DS1302_writeD(C_WP|WR,UPROTECT); //控制命令,WP位為0,允許寫操作
clr R18
ldi R16,142
xcall _DS1302_writeD
.dbline 172
; Delayms(5);
ldi R16,5
ldi R17,0
xcall _Delayms
.dbline 173
; for(i=0;i<7;i++)
clr R22
xjmp L64
L61:
.dbline 174
.dbline 175
mov R30,R22
clr R31
add R30,R10
adc R31,R11
ldd R18,z+0
mov R16,R20
xcall _DS1302_writeD
.dbline 176
subi R20,254 ; addi 2
.dbline 177
ldi R16,1
ldi R17,0
xcall _Delayms
.dbline 178
L62:
.dbline 173
inc R22
L64:
.dbline 173
cpi R22,7
brlo L61
.dbline 179
; {
; DS1302_writeD(addr|WR,ptTimeD[i]); // 秒 分 時(shí) 日 月 星期 年
; addr+=2;
; Delayms(1);
; }
; DS1302_writeD(C_WP|WR,PROTECT); //控制命令,WP位為1,不允許寫操作
ldi R18,128
ldi R16,142
xcall _DS1302_writeD
.dbline -2
L60:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r addr 20 c
.dbsym r i 22 c
.dbsym r ptTimeD 10 pc
.dbend
.dbfunc e DS1302_getT _DS1302_getT fV
; i -> R20
; time -> R22,R23
.even
_DS1302_getT::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 188
; }
; /*******************************************
; 函數(shù)名稱: DS1302_getT
; 功 能: 讀取DS1302的當(dāng)前時(shí)間
; 參 數(shù): time[]--讀取的時(shí)間數(shù)組
; 返回值 : 無
; /********************************************/
; void DS1302_getT(uchar time[])
; {
.dbline 199
; uchar i;
; ////////下面的是單次讀寫//////////////////////////
; /* uchar addr = 0x80; //讀取地址從秒寄存器開始
; for(i=0;i<7;i++)
; {
; time[i]=DS1302_readD(addr|RD); // 秒 分 時(shí) 日 月 星期 年
; addr+=2;
; }*/
; ////////////////////////////////////////////////////
; /////////下面是多字節(jié)讀取///////////////
; PORTB&=~BIT(RTC_CS); //拉低片選端
cbi 0x18,4
.dbline 200
; Delayus(10);
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 201
; PORTB|=BIT(RTC_CS); //拉高片選端
sbi 0x18,4
.dbline 202
; Delayus(10); //調(diào)整片選脈沖
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 203
; DS1302_writeB(0xbf); // 0xbf:時(shí)鐘多字節(jié)讀取命令
ldi R16,191
xcall _DS1302_writeB
.dbline 204
; for (i=0;i<8;i++) //時(shí)間數(shù)據(jù)的存放格式是:
clr R20
xjmp L69
L66:
.dbline 205
.dbline 206
xcall _DS1302_readB
mov R30,R20
clr R31
add R30,R22
adc R31,R23
std z+0,R16
.dbline 207
L67:
.dbline 204
inc R20
L69:
.dbline 204
cpi R20,8
brlo L66
.dbline 209
; { //秒,分,時(shí),日,月,星期,年,控制
; time[i]=DS1302_readB(); //【7個(gè)數(shù)據(jù)(BCD格式)+1個(gè)控制】
; }
;
; PORTB&=~BIT(RTC_CS); //拉低片選端
cbi 0x18,4
.dbline 211
; ///////////////////////////////////////////////
; PORTB&=~BIT(RTC_CLK); //拉低時(shí)鐘端(時(shí)鐘端在不操作時(shí)為低)
cbi 0x18,7
.dbline -2
L65:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r time 22 pc
.dbend
.dbfunc e DS1302_init _DS1302_init fV
.even
_DS1302_init::
.dbline -1
.dbline 242
; }
; /*******************************************
; 函數(shù)名稱: DS1302_check
; 功 能: 檢測(cè)DS1302是否正常工作
; 參 數(shù): 無
; 返回值 : exist--為TRUE為檢測(cè)到DS1302,為FALSE為沒檢測(cè)到
; /********************************************/
; /*uchar DS1302_check(void)
; {
; uchar exist;
; DS1302_writeD(C_WP|WR,UPROTECT); //寫入寫允許命令
; DS1302_writeD(C_RAMBASE|WR,0xA5); //RAM0寫入0xA5
; exist=DS1302_readD(C_RAMBASE|RD); //讀取RAM0
; if(exist==0xA5)
; {
; exist=TRUE; //如果讀取值與寫入值相等,返回TRUE
; }
; else
; {
; exist=FALSE; //如果讀取值與寫入值不相等,返回FALSE
; }
; return exist;
; }*/
; /*******************************************
; 函數(shù)名稱: DS1302_init
; 功 能: 初始化DS1302
; 參 數(shù): 無
; 返回值 : 無
; /********************************************/
; void DS1302_init(void)
; {
.dbline 243
; DS1302_writeD(C_WP|WR,UPROTECT); //寫入寫允許命令
clr R18
ldi R16,142
xcall _DS1302_writeD
.dbline 244
; DS1302_writeD(C_SEC|WR,CLK_START); //啟動(dòng)振蕩器,DS1302開始工作
clr R18
ldi R16,128
xcall _DS1302_writeD
.dbline 245
; DS1302_writeD(C_WP|WR,PROTECT); //控制命令,WP位為1,不允許寫操作
ldi R18,128
ldi R16,142
xcall _DS1302_writeD
.dbline -2
L70:
.dbline 0 ; func end
ret
.dbend
.dbfunc e BCD_ASCII _BCD_ASCII fV
; ptasc -> R18,R19
; BCD -> R16
.even
_BCD_ASCII::
.dbline -1
.dbline 255
; }
; /*******************************************
; 函數(shù)名稱: BCD_ASCII
; 功 能: 將壓縮BCD碼轉(zhuǎn)換成ascii碼
; 參 數(shù): BCD--將要轉(zhuǎn)換的壓縮BCD碼
; ptasc--轉(zhuǎn)換后的ASCII碼數(shù)組指針
; 返回值 : 無
; /********************************************/
; void BCD_ASCII(uchar BCD,uchar ptasc[])
; {
.dbline 256
; ptasc[0]=BCD/16|0x30; //0X58 35 38 //轉(zhuǎn)換十位
mov R24,R16
swap R24
andi R24,#0x0F
ori R24,48
movw R30,R18
std z+0,R24
.dbline 257
; ptasc[1]=BCD&0x0F|0x30; //轉(zhuǎn)換個(gè)位
mov R24,R16
andi R24,15
ori R24,48
std z+1,R24
.dbline -2
L71:
.dbline 0 ; func end
ret
.dbsym r ptasc 18 pc
.dbsym r BCD 16 c
.dbend
.area lit(rom, con, rel)
L73:
.byte 0,0
.byte 45,0
.byte 0,45
.byte 0,0
.byte 32,0
.byte 0
L74:
.byte 0,0
.byte 58,0
.byte 0,58
.byte 0,0
.byte 0
.area text(rom, con, rel)
.dbfile D:\單片機(jī)\ds1302\ds1302_end\ds1302.c
.dbfunc e Disp_time _Disp_time fV
; line1 -> y+11
; line2 -> y+2
; asc -> y+0
; i -> R20
; time -> R22,R23
.even
_Disp_time::
xcall push_gset2
movw R22,R16
sbiw R28,22
.dbline -1
.dbline 266
; }
; /*******************************************
; 函數(shù)名稱: Disp_time
; 功 能: 在1602液晶上顯示當(dāng)前時(shí)間(第1行格式:年-月-日 星期;第2行格式:時(shí)-分-秒)
; 參 數(shù): time[]--時(shí)間數(shù)組
; 返回值 : 無
; /********************************************/
; void Disp_time(uchar time[])
; {
.dbline 268
; uchar i,asc[2];
; uchar line1[11]={0,0,'-',0,0,'-',0,0,' ',0,'\0'};//顯示第1行的字符數(shù)組
ldi R24,<L73
ldi R25,>L73
movw R30,R28
adiw R30,11
ldi R16,11
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 269
; uchar line2[9]={0,0,':',0,0,':',0,0,'\0'}; //顯示第2行的字符數(shù)組
ldi R24,<L74
ldi R25,>L74
movw R30,R28
adiw R30,2
ldi R16,9
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 270
; for(i=0;i<3;i++) //為第2行的字符數(shù)組賦值
clr R20
xjmp L78
L75:
.dbline 271
.dbline 272
movw R18,R28
mov R2,R20
clr R3
ldi R30,2
ldi R31,0
sub R30,R2
sbc R31,R3
add R30,R22
adc R31,R23
ldd R16,z+0
xcall _BCD_ASCII
.dbline 273
ldi R24,3
mul R24,R20
movw R30,R0
movw R24,R28
adiw R24,2
add R30,R24
adc R31,R25
ldd R2,y+0
std z+0,R2
.dbline 274
ldi R24,3
mul R24,R20
movw R30,R0
movw R24,R28
adiw R24,3
add R30,R24
adc R31,R25
ldd R2,y+1
std z+0,R2
.dbline 275
L76:
.dbline 270
inc R20
L78:
.dbline 270
cpi R20,3
brlo L75
.dbline 276
; {
; BCD_ASCII(time[2-i],asc);
; line2[i*3]=asc[0];
; line2[i*3+1]=asc[1];
; }
; BCD_ASCII(time[6],asc); //為第1行的年賦值
movw R18,R28
movw R30,R22
ldd R16,z+6
xcall _BCD_ASCII
.dbline 277
; line1[0]=asc[0];
ldd R2,y+0
std y+11,R2
.dbline 278
; line1[1]=asc[1];
ldd R2,y+1
std y+12,R2
.dbline 279
; BCD_ASCII(time[4],asc); //為第1行的月賦值
movw R18,R28
movw R30,R22
ldd R16,z+4
xcall _BCD_ASCII
.dbline 280
; line1[3]=asc[0];
ldd R2,y+0
std y+14,R2
.dbline 281
; line1[4]=asc[1];
ldd R2,y+1
std y+15,R2
.dbline 282
; BCD_ASCII(time[3],asc); //為第1行的日賦值
movw R18,R28
movw R30,R22
ldd R16,z+3
xcall _BCD_ASCII
.dbline 283
; line1[6]=asc[0];
ldd R2,y+0
std y+17,R2
.dbline 284
; line1[7]=asc[1];
ldd R2,y+1
std y+18,R2
.dbline 285
; BCD_ASCII(time[5],asc); //為第1行的星期賦值
movw R18,R28
movw R30,R22
ldd R16,z+5
xcall _BCD_ASCII
.dbline 286
; line1[9]=asc[1];
ldd R2,y+1
std y+20,R2
.dbline 288
;
; LCD_write_string(0X82,"20"); //第1行從第3個(gè)位置開始顯示,將07年顯示為2007的形式
ldi R18,<L91
ldi R19,>L91
ldi R16,130
xcall _LCD_write_string
.dbline 290
;
; LCD_write_string(0X84,line1);
movw R18,R28
subi R18,245 ; offset = 11
sbci R19,255
ldi R16,132
xcall _LCD_write_string
.dbline 292
;
; LCD_write_string(0X80+0X44,line2); //第2行從第5個(gè)位置開始顯示,/第2行顯示
movw R18,R28
subi R18,254 ; offset = 2
sbci R19,255
ldi R16,196
xcall _LCD_write_string
.dbline -2
L72:
adiw R28,22
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l line1 11 A[11:11]c
.dbsym l line2 2 A[9:9]c
.dbsym l asc 0 A[2:2]c
.dbsym r i 20 c
.dbsym r time 22 pc
.dbend
.area lit(rom, con, rel)
L93:
.byte 'P,'Y
.byte 35,1
.byte 1,6
.byte 7
L94:
.byte 0,0
.byte 0,0
.byte 0,0
.byte 0
.area text(rom, con, rel)
.dbfile D:\單片機(jī)\ds1302\ds1302_end\ds1302.c
.dbfunc e main _main fV
; dis_y -> <dead>
; dis_x -> <dead>
; shift -> <dead>
; setdat -> <dead>
; setadd -> <dead>
; settime -> y+7
; gettime -> y+0
.even
_main::
sbiw R28,14
.dbline -1
.dbline 301
; }
; /*******************************************
; 函數(shù)名稱: main
; 功 能: 1. 在1602液晶上顯示當(dāng)前時(shí)間 2.可以設(shè)置時(shí)間(M1-M9為數(shù)字0-9,M13為設(shè)置模式和顯示模式選擇,M14為當(dāng)前設(shè)置位選擇)
; 參 數(shù): 無
; 返回值 : 無
; /********************************************/
; void main(void)
; {
.dbline 308
;
; uchar setadd,setdat,shift; //setadd指定將當(dāng)前數(shù)值送入DS1302的哪個(gè)寄存器
; //setdat是當(dāng)前設(shè)置的數(shù)值,即被送入DS1302指定寄存器的數(shù)
; //shift來實(shí)現(xiàn)十位和各位的設(shè)置相互獨(dú)立(因?yàn)槭缓蛡€(gè)位是在一個(gè)寄存器里的)
;
; uchar dis_x,dis_y; //存儲(chǔ)1602液晶當(dāng)前光標(biāo)的位置
; uchar settime[7]={0x50,0x59,0x23,0x01,0x01,0x06,0x07};//設(shè)置的秒,分,時(shí),日,月,星期,年
ldi R24,<L93
ldi R25,>L93
movw R30,R28
adiw R30,7
ldi R16,7
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 309
; uchar gettime[7]={0x00,0x00,0x00,0x00,0x00,0x00,0x00};//保存當(dāng)前時(shí)間的數(shù)
ldi R24,<L94
ldi R25,>L94
movw R30,R28
ldi R16,7
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 311
; //初始化液晶
; DDRC=0xff;
ldi R24,255
out 0x14,R24
.dbline 312
; PORTC=0x00;
clr R2
out 0x15,R2
.dbline 313
; LCD_init();
xcall _LCD_init
.dbline 315
;
; DS1302_portinit(); //初始化DS1302的三根數(shù)據(jù)線
xcall _DS1302_portinit
.dbline 316
; DS1302_init(); //啟動(dòng)振蕩器,DS1302開始工作
xcall _DS1302_init
.dbline 317
; DS1302_setT(settime); //設(shè)置初始時(shí)間
movw R16,R28
subi R16,249 ; offset = 7
sbci R17,255
xcall _DS1302_setT
xjmp L96
L95:
.dbline 320
.dbline 321
movw R16,R28
xcall _DS1302_getT
.dbline 322
movw R16,R28
xcall _Disp_time
.dbline 324
L96:
.dbline 319
xjmp L95
X1:
.dbline -2
L92:
adiw R28,14
.dbline 0 ; func end
ret
.dbsym l dis_y 1 c
.dbsym l dis_x 1 c
.dbsym l shift 1 c
.dbsym l setdat 1 c
.dbsym l setadd 1 c
.dbsym l settime 7 A[7:7]c
.dbsym l gettime 0 A[7:7]c
.dbend
.area bss(ram, con, rel)
.dbfile D:\單片機(jī)\ds1302\ds1302_end\ds1302.c
_data_temp::
.blkb 2
.dbfile D:\單片機(jī)\ds1302\ds1302_end/1602B_LCD.C
.dbsym e data_temp _data_temp i
.area data(ram, con, rel)
.dbfile D:\單片機(jī)\ds1302\ds1302_end/1602B_LCD.C
L91:
.blkb 3
.area idata
.byte 50,48,0
.area data(ram, con, rel)
.dbfile D:\單片機(jī)\ds1302\ds1302_end/1602B_LCD.C
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -