⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ds1305.s

📁 DS1305程序代码,在网上很少,一般不容易找到.现上传一个给大家分享.
💻 S
📖 第 1 页 / 共 2 页
字号:
	.dbline 180
L28:
	.dbline 168
	dec R22
L30:
	.dbline 168
	clr R2
	cp R2,R22
	brlo L27
	.dbline 181
;     asm("nop"); 
;     asm("nop"); 
;     set_ds1305_sclk(); 
;     asm("nop"); 
;     asm("nop"); 
;     clr_ds1305_sclk(); 
;     asm("nop"); 
;     asm("nop"); 
;   } 
;   clr_ds1305_rst(); 
	cbi 0x15,0
	.dbline 182
;   asm("nop"); 
	nop
	.dbline 183
;   asm("nop"); 
	nop
	.dbline 184
;   return(data); 
	mov R16,R20
	.dbline -2
L20:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r data 20 c
	.dbsym r i 22 c
	.dbsym r reg 16 c
	.dbend
	.dbfunc e check_ds1305 _check_ds1305 fc
	.even
_check_ds1305::
	.dbline -1
	.dbline 187
; } 
; unsigned char check_ds1305(void) 
; { 
	.dbline 188
;   ds1305_write(ds1305_control_reg,0x40); 
	ldi R18,64
	ldi R16,15
	rcall _ds1305_write
	.dbline 189
;   if(ds1305_read(ds1305_control_reg)==0x40) return 1; 
	ldi R16,15
	rcall _ds1305_read
	cpi R16,64
	brne L34
	.dbline 189
	ldi R16,1
	rjmp L33
L34:
	.dbline 190
;   return 0; 
	clr R16
	.dbline -2
L33:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e ds1305_read_time _ds1305_read_time fV
	.even
_ds1305_read_time::
	.dbline -1
	.dbline 193
; } 
; void ds1305_read_time(void) 
; { 
	.dbline 194
;   year=ds1305_read(ds1305_year_reg);   //年
	ldi R16,6
	rcall _ds1305_read
	mov R2,R16
	clr R3
	sts _year+1,R3
	sts _year,R2
	.dbline 195
;   year=((year&0xf0)>>4)*10+(year&0x0F)+2000; 
	movw R18,R2
	andi R18,240
	andi R19,0
	lsr R19
	ror R18
	lsr R19
	ror R18
	lsr R19
	ror R18
	lsr R19
	ror R18
	ldi R16,10
	ldi R17,0
	rcall empy16s
	lds R24,_year
	lds R25,_year+1
	andi R24,15
	andi R25,0
	movw R2,R16
	add R2,R24
	adc R3,R25
	movw R24,R2
	subi R24,48  ; offset = 2000
	sbci R25,248
	sts _year+1,R25
	sts _year,R24
	.dbline 196
;   month=ds1305_read(ds1305_month_reg);//月 
	ldi R16,5
	rcall _ds1305_read
	sts _month,R16
	.dbline 197
;   month=((month&0xf0)>>4)*10+(month&0x0F);
	mov R24,R16
	andi R24,240
	swap R24
	andi R24,#0x0F
	ldi R25,10
	mul R25,R24
	mov R24,R16
	andi R24,15
	mov R2,R0
	add R2,R24
	sts _month,R2
	.dbline 198
;   day=ds1305_read(ds1305_date_reg);   //日
	ldi R16,4
	rcall _ds1305_read
	sts _day,R16
	.dbline 199
;   day=((day&0xf0)>>4)*10+(day&0x0F); 
	mov R24,R16
	andi R24,240
	swap R24
	andi R24,#0x0F
	ldi R25,10
	mul R25,R24
	mov R24,R16
	andi R24,15
	mov R2,R0
	add R2,R24
	sts _day,R2
	.dbline 200
;   week=ds1305_read(ds1305_day_reg);   //周 
	ldi R16,3
	rcall _ds1305_read
	sts _week,R16
	.dbline 201
;   week=((week&0xf0)>>4)*10+(week&0x0F);
	mov R24,R16
	andi R24,240
	swap R24
	andi R24,#0x0F
	ldi R25,10
	mul R25,R24
	mov R24,R16
	andi R24,15
	mov R2,R0
	add R2,R24
	sts _week,R2
	.dbline 202
;   hour=ds1305_read(ds1305_hr_reg);   //时 
	ldi R16,2
	rcall _ds1305_read
	sts _hour,R16
	.dbline 203
;   hour=((hour&0xf0)>>4)*10+(hour&0x0F);
	mov R24,R16
	andi R24,240
	swap R24
	andi R24,#0x0F
	ldi R25,10
	mul R25,R24
	mov R24,R16
	andi R24,15
	mov R2,R0
	add R2,R24
	sts _hour,R2
	.dbline 204
;   minute=ds1305_read(ds1305_min_reg);   //分 
	ldi R16,1
	rcall _ds1305_read
	sts _minute,R16
	.dbline 205
;   minute=((minute&0xf0)>>4)*10+(minute&0x0F);
	mov R24,R16
	andi R24,240
	swap R24
	andi R24,#0x0F
	ldi R25,10
	mul R25,R24
	mov R24,R16
	andi R24,15
	mov R2,R0
	add R2,R24
	sts _minute,R2
	.dbline 206
;   second=ds1305_read(ds1305_sec_reg);   //秒 
	clr R16
	rcall _ds1305_read
	sts _second,R16
	.dbline 207
;   second=((second&0xf0)>>4)*10+(second&0x0F);
	mov R24,R16
	andi R24,240
	swap R24
	andi R24,#0x0F
	ldi R25,10
	mul R25,R24
	mov R24,R16
	andi R24,15
	mov R2,R0
	add R2,R24
	sts _second,R2
	.dbline -2
L36:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e ds1305_write_time _ds1305_write_time fV
	.even
_ds1305_write_time::
	.dbline -1
	.dbline 210
; } 
; void ds1305_write_time(void) 
; { 
	.dbline 211
;   ds1305_write(ds1305_control_reg,0x80);   //停止振荡器,关闭写保护,关闭闹铃中断       
	ldi R18,128
	ldi R16,15
	rcall _ds1305_write
	.dbline 212
;   ds1305_write(ds1305_charger_reg,0xa9);   //涓流充电 
	ldi R18,169
	ldi R16,17
	rcall _ds1305_write
	.dbline 218
;   //ds1305_write(ds1305_year_reg,year);     //年 
;   //ds1305_write(ds1305_month_reg,month);   //月 
;   //ds1305_write(ds1305_date_reg,day);     //日 
;   //ds1305_write(ds1305_day_reg,week);     //周 
;   //ds1305_write(ds1305_hr_reg,hour);     //时 
;   minute=((minute/10)<<4)+minute%10; 
	ldi R17,10
	lds R16,_minute
	rcall mod8u
	mov R2,R16
	ldi R17,10
	lds R16,_minute
	rcall div8u
	mov R24,R16
	andi R24,#0x0F
	swap R24
	add R24,R2
	sts _minute,R24
	.dbline 219
;   ds1305_write(ds1305_min_reg,minute);   //分
	mov R18,R24
	ldi R16,1
	rcall _ds1305_write
	.dbline 220
;   second=((second/10)<<4)+second%10; 
	ldi R17,10
	lds R16,_second
	rcall mod8u
	mov R2,R16
	ldi R17,10
	lds R16,_second
	rcall div8u
	mov R24,R16
	andi R24,#0x0F
	swap R24
	add R24,R2
	sts _second,R24
	.dbline 221
;   ds1305_write(ds1305_sec_reg,second);   //秒   
	mov R18,R24
	clr R16
	rcall _ds1305_write
	.dbline 222
;   ds1305_write(ds1305_control_reg,0x41);   //打开写保护 
	ldi R18,65
	ldi R16,15
	rcall _ds1305_write
	.dbline -2
L37:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e ds1305_init _ds1305_init fV
	.even
_ds1305_init::
	.dbline -1
	.dbline 226
; }
; 
; void ds1305_init(void)
; {
	.dbline 227
;   ds1305_write(ds1305_control_reg,0x80);   //停止振荡器,关闭写保护,关闭闹铃中断       
	ldi R18,128
	ldi R16,15
	rcall _ds1305_write
	.dbline 228
;   ds1305_write(ds1305_charger_reg,0xa9);   //涓流充电 
	ldi R18,169
	ldi R16,17
	rcall _ds1305_write
	.dbline 229
;   ds1305_write(ds1305_year_reg,0x05);     //年 
	ldi R18,5
	ldi R16,6
	rcall _ds1305_write
	.dbline 230
;   ds1305_write(ds1305_month_reg,0x12);   //月 
	ldi R18,18
	ldi R16,5
	rcall _ds1305_write
	.dbline 231
;   ds1305_write(ds1305_date_reg,0x23);     //日 
	ldi R18,35
	ldi R16,4
	rcall _ds1305_write
	.dbline 232
;   ds1305_write(ds1305_day_reg,0x05);     //周 
	ldi R18,5
	ldi R16,3
	rcall _ds1305_write
	.dbline 233
;   ds1305_write(ds1305_hr_reg,0x10);     //时 
	ldi R18,16
	ldi R16,2
	rcall _ds1305_write
	.dbline 234
;   ds1305_write(ds1305_min_reg,0x56);   //分 
	ldi R18,86
	ldi R16,1
	rcall _ds1305_write
	.dbline 235
;   ds1305_write(ds1305_sec_reg,0x00);   //秒
	clr R18
	clr R16
	rcall _ds1305_write
	.dbline 236
;   ds1305_write(alarm0_sec_reg,0x20);  
	ldi R18,32
	ldi R16,7
	rcall _ds1305_write
	.dbline 237
;   ds1305_write(alarm0_min_reg,0x80); 
	ldi R18,128
	ldi R16,8
	rcall _ds1305_write
	.dbline 238
;   ds1305_write(alarm0_hr_reg,0x80); 
	ldi R18,128
	ldi R16,9
	rcall _ds1305_write
	.dbline 239
;   ds1305_write(alarm0_day_reg,0x80);  
	ldi R18,128
	ldi R16,10
	rcall _ds1305_write
	.dbline 240
;   ds1305_write(ds1305_control_reg,45);   //打开写保护 
	ldi R18,45
	ldi R16,15
	rcall _ds1305_write
	.dbline -2
L38:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay_1us _delay_1us fV
	.even
_delay_1us::
	.dbline -1
	.dbline 243
; }
; void delay_1us(void)//1u延时函数
; {
	.dbline 244
;   asm("nop"); 
	nop
	.dbline -2
L39:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay_1ms _delay_1ms fV
;              i -> R16,R17
	.even
_delay_1ms::
	.dbline -1
	.dbline 248
; }
; 
; void delay_1ms(void)//1ms延时函数
; {
	.dbline 250
;   unsigned int i;
;   for (i=0;i<1034;i++)
	clr R16
	clr R17
	rjmp L44
L41:
	.dbline 251
	.dbline 252
L42:
	.dbline 250
	subi R16,255  ; offset = 1
	sbci R17,255
L44:
	.dbline 250
	cpi R16,10
	ldi R30,4
	cpc R17,R30
	brlo L41
	.dbline -2
L40:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e delay_nus _delay_nus fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nus::
	rcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 256
;   {
;   } 
; }
; 
; void delay_nus(unsigned int n)//nus延时函数
; {
	.dbline 258
;   unsigned int i;
;   for (i=0;i<n;i++)//执行n次1微秒延时
	clr R20
	clr R21
	rjmp L49
L46:
	.dbline 259
	rcall _delay_1us
L47:
	.dbline 258
	subi R20,255  ; offset = 1
	sbci R21,255
L49:
	.dbline 258
	cp R20,R22
	cpc R21,R23
	brlo L46
	.dbline -2
L45:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.dbfunc e delay_nms _delay_nms fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nms::
	rcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 263
;   delay_1us();
; }
; 
; void delay_nms(unsigned int n)//延时n毫秒
; {
	.dbline 265
;   unsigned int i;
;   for (i=0;i<n;i++)//执行n次1毫秒延时
	clr R20
	clr R21
	rjmp L54
L51:
	.dbline 266
	rcall _delay_1ms
L52:
	.dbline 265
	subi R20,255  ; offset = 1
	sbci R21,255
L54:
	.dbline 265
	cp R20,R22
	cpc R21,R23
	brlo L51
	.dbline -2
L50:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.dbfunc e uart_init _uart_init fV
	.even
_uart_init::
	.dbline -1
	.dbline 270
;   delay_1ms(); 
; }
; 
; void uart_init(void)
; {
	.dbline 272
; //UCSRB=(1<<RXEN)|(1<<TXEN); //允许发送和接收
; UBRRL=(fosc/16/baud-1)%256; //设置波特率寄存器低位字节
	ldi R24,47
	out 0x9,R24
	.dbline 273
; UBRRH=(fosc/16/baud-1)/256; //设置波特率寄存器高位字节
	clr R2
	out 0x20,R2
	.dbline 274
; UCSRC=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); //8位数据+1位STOP位
	ldi R24,134
	out 0x20,R24
	.dbline 275
; UCSRB=(1<<RXEN)|(1<<TXEN); //允许发送和接收
	ldi R24,24
	out 0xa,R24
	.dbline -2
L55:
	.dbline 0 ; func end
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile F:\ziliao\JTAG\example\DS1305\DS1305.c
_year::
	.blkb 2
	.dbsym e year _year i
_second::
	.blkb 1
	.dbsym e second _second c
_minute::
	.blkb 1
	.dbsym e minute _minute c
_hour::
	.blkb 1
	.dbsym e hour _hour c
_day::
	.blkb 1
	.dbsym e day _day c
_week::
	.blkb 1
	.dbsym e week _week c
_month::
	.blkb 1
	.dbsym e month _month c
	.area data(ram, con, rel)
	.dbfile F:\ziliao\JTAG\example\DS1305\DS1305.c
L6:
	.blkb 47
	.area idata
	.byte 181,177,199,176,181,196,202,177,188,228,202,199,163,186,32,32
	.byte 37,'d,196,234,37,'d,212,194,37,'d,200,213,32,32,208,199
	.byte 198,218,37,'d,32,37,'d,58,37,'d,58,37,'d,10,0
	.area data(ram, con, rel)
	.dbfile F:\ziliao\JTAG\example\DS1305\DS1305.c

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -