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

📄 ds1302.s

📁 我自己编写的atmega16的ds1302源程序
💻 S
字号:
	.module ds1302.c
	.area data(ram, con, rel)
_INITDATE::
	.blkb 2
	.area idata
	.byte 'U,'Y
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 35,49
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 18,2
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 7,128
	.area data(ram, con, rel)
	.dbfile F:\自编程序\M16\ds1302\ds1302.c
	.dbsym e INITDATE _INITDATE A[8:8]c
	.area text(rom, con, rel)
	.dbfile F:\自编程序\M16\ds1302\ds1302.c
	.dbfunc e RTInputByte _RTInputByte fV
;              i -> R20
;              j -> R10
;              x -> R22
	.even
_RTInputByte::
	xcall push_gset3
	mov R22,R16
	.dbline -1
	.dbline 21
; #include<iom16v.h>
; #include<macros.h> 
; #include "ds1302.h"
; unsigned char INITDATE[8]={0x55,	//55秒
; 						   0x59,	//59分
; 						   0x23,	//23时  24小时制
; 						   0x31,	//21日
; 						   0x12,	//08月
; 						   0x02,	//星期2
; 						   0x07,	//2007年
; 						   0x80		//写保护
; 						  };
; /********************************************************************  
;  函 数 名:RTInputByte() 
;  功    能:实时时钟写入一字节 
;  说    明:往DS1302写入1Byte数据 (内部函数) 
;  入口参数:d 写入的数据  
;  返 回 值:无   
;  ***********************************************************************/ 
; void RTInputByte(unsigned char  x)  
; {  
	.dbline 23
;     unsigned char  i,j; 
;     for(i=0; i<8;i++) 
	clr R20
	xjmp L5
L2:
	.dbline 24
;     { 
	.dbline 25
;   	   if(x&(1<<i))
	ldi R16,1
	mov R17,R20
	xcall lsl8
	mov R2,R22
	and R2,R16
	breq L6
	.dbline 26
; 	    DS1302_PORT|=(1<<DS1302_DATA);
	sbi 0x12,6
	xjmp L7
L6:
	.dbline 28
;  	   else 
; 	    DS1302_PORT&=~(1<<DS1302_DATA);  
	cbi 0x12,6
L7:
	.dbline 29
; 	   DS1302_PORT|=(1<<DS1302_CLK);
	sbi 0x12,7
	.dbline 30
	clr R10
	xjmp L11
L8:
	.dbline 30
L9:
	.dbline 30
	inc R10
L11:
	.dbline 30
; 	   for(j=0; j<5;j++);
	mov R24,R10
	cpi R24,5
	brlo L8
	.dbline 31
;  	   DS1302_PORT&=~(1<<DS1302_CLK);
	cbi 0x12,7
	.dbline 32
	clr R10
	xjmp L15
L12:
	.dbline 32
L13:
	.dbline 32
	inc R10
L15:
	.dbline 32
	mov R24,R10
	cpi R24,5
	brlo L12
	.dbline 33
L3:
	.dbline 23
	inc R20
L5:
	.dbline 23
	cpi R20,8
	brlo L2
	.dbline -2
	.dbline 34
; 	   for(j=0; j<5;j++);                   
;     }  
; } 
L1:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r j 10 c
	.dbsym r x 22 c
	.dbend
	.dbfunc e RTOutputByte _RTOutputByte fc
;           data -> R20
;              k -> R22
;              i -> R10
;              j -> R12
	.even
_RTOutputByte::
	xcall push_gset4
	.dbline -1
	.dbline 43
; /********************************************************************  
;  函 数 名:RTOutputByte() 
;  功    能:实时时钟读取一字节 
;  说    明:从DS1302读取1Byte数据 (内部函数) 
;  入口参数:无   
;  返 回 值:ACC 
;  ***********************************************************************/ 
; unsigned char RTOutputByte(void)  
; {  
	.dbline 45
;     unsigned char i,k,data,j; 
; 	DS1302_DDR&=~(1<<DS1302_DATA);
	cbi 0x11,6
	.dbline 46
	clr R12
	xjmp L20
L17:
	.dbline 46
L18:
	.dbline 46
	inc R12
L20:
	.dbline 46
; 	for(j=0; j<5;j++); 
	mov R24,R12
	cpi R24,5
	brlo L17
	.dbline 47
;     for(i=0; i<8; i++) 
	clr R10
	xjmp L24
L21:
	.dbline 48
;     {           
	.dbline 49
;       k=(DS1302_PIN&(1<<DS1302_DATA));    //读数据,从低位开始  
	in R22,0x10
	andi R22,64
	.dbline 50
;       if(k)  
	breq L25
	.dbline 51
;         data|=(1<<i);  
	ldi R16,1
	mov R17,R10
	xcall lsl8
	or R20,R16
	xjmp L26
L25:
	.dbline 53
;       else  
;         data&=~(1<<i);  
	ldi R16,1
	mov R17,R10
	xcall lsl8
	mov R2,R16
	com R2
	and R20,R2
L26:
	.dbline 54
;       DS1302_PORT|=(1<<DS1302_CLK);
	sbi 0x12,7
	.dbline 55
	clr R12
	xjmp L30
L27:
	.dbline 55
L28:
	.dbline 55
	inc R12
L30:
	.dbline 55
; 	  for(j=0; j<5;j++);
	mov R24,R12
	cpi R24,5
	brlo L27
	.dbline 56
;       DS1302_PORT&=~(1<<DS1302_CLK);
	cbi 0x12,7
	.dbline 57
	clr R12
	xjmp L34
L31:
	.dbline 57
L32:
	.dbline 57
	inc R12
L34:
	.dbline 57
	mov R24,R12
	cpi R24,5
	brlo L31
	.dbline 58
L22:
	.dbline 47
	inc R10
L24:
	.dbline 47
	mov R24,R10
	cpi R24,8
	brlo L21
	.dbline 59
; 	  for(j=0; j<5;j++); 
;     }  
; 	DS1302_DDR|=(1<<DS1302_DATA);
	sbi 0x11,6
	.dbline 60
; 	return(data);  
	mov R16,R20
	.dbline -2
L16:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.dbsym r data 20 c
	.dbsym r k 22 c
	.dbsym r i 10 c
	.dbsym r j 12 c
	.dbend
	.dbfunc e BCDtoASCII _BCDtoASCII fV
;              j -> R20
;              i -> R22
;           pstr -> R18,R19
;           cBCD -> R16
	.even
_BCDtoASCII::
	xcall push_gset2
	.dbline -1
	.dbline 64
; } 
; 
; void BCDtoASCII(unsigned char cBCD,unsigned char *pstr)
; {
	.dbline 66
; 	unsigned char i,j;
; 	i=cBCD>>4;
	mov R22,R16
	swap R22
	andi R22,#0x0F
	.dbline 67
; 	j=cBCD&0x0F;
	mov R20,R16
	andi R20,15
	.dbline 68
; 	*pstr++=i+0x30;
	mov R24,R22
	subi R24,208    ; addi 48
	movw R30,R18
	st Z+,R24
	movw R18,R30
	.dbline 69
; 	*pstr=j+0x30;
	mov R24,R20
	subi R24,208    ; addi 48
	std z+0,R24
	.dbline -2
	.dbline 70
; }
L35:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r j 20 c
	.dbsym r i 22 c
	.dbsym r pstr 18 pc
	.dbsym r cBCD 16 c
	.dbend
	.dbfunc e W1302 _W1302 fV
;           ucDa -> R20
;         ucAddr -> R22
	.even
_W1302::
	xcall push_gset2
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 80
; /********************************************************************  
;  函 数 名:W1302() 
;  功    能:往DS1302写入数据 
;  说    明:先写地址,后写命令/数据 (内部函数) 
;  调    用:RTInputByte() , RTOutputByte() 
;  入口参数:ucAddr: DS1302地址, ucData: 要写的数据 
;  返 回 值:无 
;  ***********************************************************************/ 
; void W1302(unsigned char ucAddr, unsigned char ucDa) 
; {   
	.dbline 81
;     DS1302_PORT&=~(1<<DS1302_RST);  // RST  to L 
	cbi 0x12,5
	.dbline 82
;     DS1302_PORT&=~(1<<DS1302_CLK);  // CLK  to L 
	cbi 0x12,7
	.dbline 83
;     DS1302_PORT|=(1<<DS1302_RST);  // RST  to H 
	sbi 0x12,5
	.dbline 85
; 
;     RTInputByte(ucAddr);       /* 地址,命令 */ 
	mov R16,R22
	xcall _RTInputByte
	.dbline 86
;     RTInputByte(ucDa);         /* 写1Byte数据*/ 
	mov R16,R20
	xcall _RTInputByte
	.dbline 88
; 
;     DS1302_PORT|=(1<<DS1302_CLK); //CLK  to H 
	sbi 0x12,7
	.dbline 89
; 	DS1302_PORT&=~(1<<DS1302_RST); //RST  to L  
	cbi 0x12,5
	.dbline -2
	.dbline 91
; 
; } 
L36:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r ucDa 20 c
	.dbsym r ucAddr 22 c
	.dbend
	.dbfunc e R1302 _R1302 fc
;         ucData -> R20
;         ucAddr -> R20
	.even
_R1302::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 101
; /********************************************************************  
;  函 数 名:R1302() 
;  功    能:读取DS1302某地址的数据 
;  说    明:先写地址,后读命令/数据 (内部函数) 
;  调    用:RTInputByte() , RTOutputByte() 
;  入口参数:ucAddr: DS1302地址 
;  返 回 值:ucData :读取的数据 
; ***********************************************************************/ 
; unsigned char R1302(unsigned char ucAddr) 
; { 
	.dbline 103
;     unsigned char ucData;    
;     DS1302_PORT&=~(1<<DS1302_RST);  // RST  to L 
	cbi 0x12,5
	.dbline 104
;     DS1302_PORT&=~(1<<DS1302_CLK);  // CLK  to L 
	cbi 0x12,7
	.dbline 105
;     DS1302_PORT|=(1<<DS1302_RST);  // RST  to H 
	sbi 0x12,5
	.dbline 106
;     RTInputByte(ucAddr);             /* 地址,命令 */ 
	mov R16,R20
	xcall _RTInputByte
	.dbline 107
;     ucData = RTOutputByte();         /* 读1Byte数据 */ 
	xcall _RTOutputByte
	mov R20,R16
	.dbline 108
;     DS1302_PORT|=(1<<DS1302_CLK); //CLK  to H 
	sbi 0x12,7
	.dbline 109
;     DS1302_PORT&=~(1<<DS1302_RST); //RST  to L
	cbi 0x12,5
	.dbline 110
; 	return(ucData); 
	.dbline -2
L37:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r ucData 20 c
	.dbsym r ucAddr 20 c
	.dbend
	.dbfunc e init_1302 _init_1302 fV
	.even
_init_1302::
	.dbline -1
	.dbline 113
; } 
; void init_1302()
; { 
	.dbline 114
;   DS1302_DDR|=(1<<DS1302_RST);
	sbi 0x11,5
	.dbline 115
;   DS1302_DDR|=(1<<DS1302_CLK);
	sbi 0x11,7
	.dbline 116
;   DS1302_DDR|=(1<<DS1302_DATA);
	sbi 0x11,6
	.dbline 117
;   W1302(0x8e,0x00);      //关闭寄存器写保护
	clr R18
	ldi R16,142
	xcall _W1302
	.dbline 118
;   W1302(0x90,0x00);	    //写充电寄存器
	clr R18
	ldi R16,144
	xcall _W1302
	.dbline 119
;   W1302(0x80,0x00);      //秒寄存器停止位置0,时钟启动,初值设为0
	clr R18
	ldi R16,128
	xcall _W1302
	.dbline 122
;   
;     //设置时间
;     W1302(0x80,INITDATE[0]);
	lds R18,_INITDATE
	ldi R16,128
	xcall _W1302
	.dbline 123
;     W1302(0x82,INITDATE[1]);
	lds R18,_INITDATE+1
	ldi R16,130
	xcall _W1302
	.dbline 124
;     W1302(0x84,INITDATE[2]);
	lds R18,_INITDATE+2
	ldi R16,132
	xcall _W1302
	.dbline 125
;     W1302(0x86,INITDATE[3]);
	lds R18,_INITDATE+3
	ldi R16,134
	xcall _W1302
	.dbline 126
;     W1302(0x88,INITDATE[4]);
	lds R18,_INITDATE+4
	ldi R16,136
	xcall _W1302
	.dbline 127
;     W1302(0x8a,INITDATE[5]);
	lds R18,_INITDATE+5
	ldi R16,138
	xcall _W1302
	.dbline 128
; 	W1302(0x8c,INITDATE[6]);
	lds R18,_INITDATE+6
	ldi R16,140
	xcall _W1302
	.dbline 129
; 	W1302(0x8e,INITDATE[7]);
	lds R18,_INITDATE+7
	ldi R16,142
	.dbline -2
	.dbline 131
; 	 //设置时间
; }
L38:
	.dbline 0 ; func end
	xjmp _W1302
	.dbend

⌨️ 快捷键说明

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