📄 ds1302.lst
字号:
(0061) #include "D:\ICC_H\CmmICC.H"
(0062)
(0063) #define DELAY() {NOP();NOP();NOP();NOP();NOP();NOP();}
(0064)
(0065) //uint8 DS1302Second;
(0066) //uint8 DS1302Minute;
(0067) //uint8 DS1302Hour;
(0068)
(0069) //uint8 DS1302Day;
(0070) //uint8 DS1302Month;
(0071) //uint8 DS1302Year;
(0072)
(0073) //uint8 DS1302SecLow;
(0074) //uint8 DS1302MinLow;
(0075) //uint8 DS1302HourLow;
(0076) //uint8 DS1302DayLow;
(0077) //uint8 DS1302MonLow;
(0078) //uint8 DS1302YearLow;
(0079) //uint8 DS1302SecHi;
(0080) //uint8 DS1302MinHi;
(0081) //uint8 DS1302HourHi;
(0082) //uint8 DS1302DayHi;
(0083) //uint8 DS1302MonHi;
(0084) //uint8 DS1302YearHi;
(0085)
(0086) uint8 operData;
(0087) #define data0 (bool)operData&0x01
(0088) //#define data7 (bool)operData&0x80
(0089)
(0090) /*--------------------------------------------------------------------
(0091) 函数名称:DS1302写一个字节
(0092) 函数功能:
(0093) 注意事项:无
(0094) 提示说明:无
(0095) 输 入:无
(0096) 返 回:无
(0097) --------------------------------------------------------------------*/
(0098) void writeByte(void)
(0099) {
(0100) uint8 i;
(0101)
(0102) OUT_SIO;
_writeByte:
i --> R16
01FA 9AA6 SBI 0x14,6
(0103) DELAY();
01FB 0000 NOP
01FC 0000 NOP
01FD 0000 NOP
01FE 0000 NOP
01FF 0000 NOP
0200 0000 NOP
(0104) for(i=0;i<8;i++)
0201 2700 CLR R16
0202 C00F RJMP 0x0212
(0105) {
(0106) CLR_SCK;
0203 98AF CBI 0x15,7
(0107) if(data0)
0204 90200060 LDS R2,operData
0206 FE20 SBRS R2,0
0207 C002 RJMP 0x020A
(0108) SET_SIO;
0208 9AAE SBI 0x15,6
0209 C001 RJMP 0x020B
(0109) else
(0110) CLR_SIO;
020A 98AE CBI 0x15,6
(0111) SET_SCK;
020B 9AAF SBI 0x15,7
(0112) operData = operData>>1;
020C 90200060 LDS R2,operData
020E 9426 LSR R2
020F 92200060 STS operData,R2
0211 9503 INC R16
0212 3008 CPI R16,0x8
0213 F378 BCS 0x0203
0214 9508 RET
(0113) }
(0114) }
(0115) /*--------------------------------------------------------------------
(0116) 函数名称:DS1302读一个字节
(0117) 函数功能:
(0118) 注意事项:无
(0119) 提示说明:无
(0120) 输 入:无
(0121) 返 回:无
(0122) --------------------------------------------------------------------*/
(0123) void readByte(void)
(0124) {
(0125) uint8 i;
(0126)
(0127) IN_SIO;
_readByte:
i --> R16
0215 98A6 CBI 0x14,6
(0128) SET_SCK;
0216 9AAF SBI 0x15,7
(0129) for(i=0;i<8;i++)
0217 2700 CLR R16
0218 C014 RJMP 0x022D
(0130) {
(0131) operData = operData>>1;
0219 90200060 LDS R2,operData
021B 9426 LSR R2
021C 92200060 STS operData,R2
(0132) CLR_SCK;
021E 98AF CBI 0x15,7
(0133) DELAY();
021F 0000 NOP
0220 0000 NOP
0221 0000 NOP
0222 0000 NOP
0223 0000 NOP
0224 0000 NOP
(0134) //delay50us(1);
(0135) if(GET_SIO)
0225 9B9E SBIS 0x13,6
0226 C004 RJMP 0x022B
(0136) operData |= 0x80;
0227 2D82 MOV R24,R2
0228 6880 ORI R24,0x80
0229 93800060 STS operData,R24
(0137) SET_SCK;
022B 9AAF SBI 0x15,7
022C 9503 INC R16
022D 3008 CPI R16,0x8
022E F350 BCS 0x0219
022F 9508 RET
(0138) }
(0139) }
(0140) /*--------------------------------------------------------------------
(0141) 函数名称:DS1302充电参数
(0142) 函数功能:
(0143) 注意事项:无
(0144) 提示说明:无
(0145) 输 入:无
(0146) 返 回:无
(0147) --------------------------------------------------------------------*/
(0148) void setChargePrmt(void)
(0149) {
(0150) CLR_SCK;
_setChargePrmt:
0230 98AF CBI 0x15,7
(0151) SET_RST;
0231 9AAD SBI 0x15,5
(0152) operData=0X90;
0232 E980 LDI R24,0x90
0233 93800060 STS operData,R24
(0153) writeByte();
0235 DFC4 RCALL _writeByte
(0154) operData=0XA4;
0236 EA84 LDI R24,0xA4
0237 93800060 STS operData,R24
(0155) writeByte();
0239 DFC0 RCALL _writeByte
(0156) /* the following sentence here is not indispensable,
(0157) but insert this sentence here can prevent ariseing error!
(0158) because when start operating,RST must keep low level! */
(0159) CLR_RST;
023A 98AD CBI 0x15,5
023B 9508 RET
(0160) }
(0161) /*--------------------------------------------------------------------
(0162) 函数名称:DS1302关写保护
(0163) 函数功能:
(0164) 注意事项:无
(0165) 提示说明:无
(0166) 输 入:无
(0167) 返 回:无
(0168) --------------------------------------------------------------------*/
(0169) void closeWP(void)
(0170) {
(0171) CLR_RST;
_closeWP:
023C 98AD CBI 0x15,5
(0172) CLR_SCK;
023D 98AF CBI 0x15,7
(0173) SET_RST;
023E 9AAD SBI 0x15,5
(0174) operData=0X8E;
023F E88E LDI R24,0x8E
0240 93800060 STS operData,R24
(0175) writeByte();
0242 DFB7 RCALL _writeByte
(0176) operData=0X80;
0243 E880 LDI R24,0x80
0244 93800060 STS operData,R24
(0177) CLR_SIO;
0246 98AE CBI 0x15,6
(0178) writeByte();
0247 DFB2 RCALL _writeByte
(0179) /* the following sentence here is not indispensable,
(0180) but insert this sentence here can prevent ariseing error!
(0181) because when start operating,RST must keep low level! */
(0182) CLR_RST;
0248 98AD CBI 0x15,5
0249 9508 RET
(0183) }
(0184) /*--------------------------------------------------------------------
(0185) 函数名称:DS1302开写保护
(0186) 函数功能:
(0187) 注意事项:无
(0188) 提示说明:无
(0189) 输 入:无
(0190) 返 回:无
(0191) --------------------------------------------------------------------*/
(0192) void openWP(void)
(0193) {
(0194) CLR_RST;
_openWP:
024A 98AD CBI 0x15,5
(0195) CLR_SCK;
024B 98AF CBI 0x15,7
(0196) SET_RST;
024C 9AAD SBI 0x15,5
(0197) operData=0X8E;
024D E88E LDI R24,0x8E
024E 93800060 STS operData,R24
(0198) writeByte();
0250 DFA9 RCALL _writeByte
(0199) operData=0X00;
0251 2422 CLR R2
0252 92200060 STS operData,R2
(0200) CLR_SIO;
0254 98AE CBI 0x15,6
(0201) writeByte();
0255 DFA4 RCALL _writeByte
(0202) /* the following sentence here is not indispensable,
(0203) but insert this sentence here can prevent ariseing error!
(0204) because when start operating,RST must keep low level! */
(0205) CLR_RST;
0256 98AD CBI 0x15,5
0257 9508 RET
_write:
dat --> R20
addr --> R22
0258 940E03F6 CALL push_gset2
025A 2F42 MOV R20,R18
025B 2F60 MOV R22,R16
(0206) }
(0207) /*--------------------------------------------------------------------
(0208) 函数名称:DS1302的一个完整写操作
(0209) 函数功能:
(0210) 注意事项:无
(0211) 提示说明:无
(0212) 输 入:
(0213) 返 回:无
(0214) --------------------------------------------------------------------*/
(0215) void write(uint8 addr,uint8 dat)
(0216) {
(0217) CLR_RST; //before SCL change to low level, RST must keep low level
025C 98AD CBI 0x15,5
(0218) CLR_SCK;
025D 98AF CBI 0x15,7
(0219) SET_RST;
025E 9AAD SBI 0x15,5
(0220)
(0221) //CLR_SCK; //also ok!!!
(0222) //CLR_RST;
(0223) //SET_RST;
(0224)
(0225) //CLR_RST; //error
(0226) //SET_RST;
(0227) //CLR_SCK;
(0228)
(0229) operData=0X80|(addr<<1);
025F 2F86 MOV R24,R22
0260 0F88 LSL R24
0261 6880 ORI R24,0x80
0262 93800060 STS operData,R24
(0230) writeByte();
0264 DF95 RCALL _writeByte
(0231) operData=dat;
0265 93400060 STS operData,R20
(0232) writeByte();
0267 DF92 RCALL _writeByte
(0233) /* the following sentence here is not indispensable,
(0234) but insert this sentence here can prevent ariseing error!
(0235) because when start operating,RST must keep low level! */
(0236) CLR_RST;
0268 98AD CBI 0x15,5
0269 940E03E7 CALL pop_gset2
026B 9508 RET
_read:
cmd --> R20
026C 940E03F8 CALL push_gset1
026E 2F40 MOV R20,R16
(0237) }
(0238) /*--------------------------------------------------------------------
(0239) 函数名称:DS1302的一个完整读操作
(0240) 函数功能:
(0241) 注意事项:无
(0242) 提示说明:无
(0243) 输 入:
(0244) 返 回:无
(0245) --------------------------------------------------------------------*/
(0246) uint8 read(uint8 cmd)
(0247) {
(0248) //CLR_RST;
(0249) CLR_SCK;
026F 98AF CBI 0x15,7
(0250) SET_RST;
0270 9AAD SBI 0x15,5
(0251) operData=(cmd<<1)|0x81;
0271 2F84 MOV R24,R20
0272 0F88 LSL R24
0273 6881 ORI R24,0x81
0274 93800060 STS operData,R24
(0252) writeByte();
0276 DF83 RCALL _writeByte
(0253) readByte();
0277 DF9D RCALL _readByte
(0254) /* the following sentence here is not indispensable,
(0255) but insert this sentence here can prevent ariseing error!
(0256) because when start operating,RST must keep low level! */
(0257) CLR_RST;
0278 98AD CBI 0x15,5
(0258) return(operData);
0279 91000060 LDS R16,operData
027B 940E03FB CALL pop_gset1
027D 9508 RET
_DS1302_getTime:
secondAdr --> R12
minuteAdr --> R10
hourAdr --> R22
buf --> R20
027E 940E03F2 CALL push_gset4
0280 01A8 MOVW R20,R16
(0259) }
(0260) /*--------------------------------------------------------------------
(0261) 函数名称:DS1302读时间
(0262) 函数功能:
(0263) 注意事项:无
(0264) 提示说明:无
(0265) 输 入:
(0266) 返 回:无
(0267) --------------------------------------------------------------------*/
(0268) void DS1302_getTime(uint8 *buf)
(0269) {
(0270) uint8 hourAdr=2,minuteAdr=1,secondAdr=0;
0281 E062 LDI R22,2
0282 24AA CLR R10
0283 94A3 INC R10
0284 24CC CLR R12
(0271)
(0272) buf[0]=read(secondAdr);
0285 2D0C MOV R16,R12
0286 DFE5 RCALL _read
0287 01FA MOVW R30,R20
0288 8300 STD Z+0,R16
(0273) buf[0]=changeHexToInt(buf[0]);
0289 8020 LDD R2,Z+0
028A 2433 CLR R3
028B E110 LDI R17,0x10
028C 2D02 MOV R16,R2
028D 940E039F CALL mod8u
028F 2D82 MOV R24,R2
0290 9582 SWAP R24
0291 708F ANDI R24,0xF
0292 E09A LDI R25,0xA
0293 9F98 MUL R25,R24
0294 2C20 MOV R2,R0
0295 0E20 ADD R2,R16
0296 01FA MOVW R30,R20
0297 8220 STD Z+0,R2
(0274)
(0275) buf[1]=read(minuteAdr);
0298 2D0A MOV R16,R10
0299 DFD2 RCALL _read
029A 01FA MOVW R30,R20
029B 8301 STD Z+1,R16
(0276) buf[1]=changeHexToInt(buf[1]);
029C 01CA MOVW R24,R20
029D 9601 ADIW R24,1
029E 011C MOVW R2,R24
029F 01FC MOVW R30,R24
02A0 8040 LDD R4,Z+0
02A1 2455 CLR R5
02A2 E110 LDI R17,0x10
02A3 2D04 MOV R16,R4
02A4 940E039F CALL mod8u
02A6 2D84 MOV R24,R4
02A7 9582 SWAP R24
02A8 708F ANDI R24,0xF
02A9 E09A LDI R25,0xA
02AA 9F98 MUL R25,R24
02AB 2C40 MOV R4,R0
02AC 0E40 ADD R4,R16
02AD 01F1 MOVW R30,R2
02AE 8240 STD Z+0,R4
(0277)
(0278) buf[2]=read(hourAdr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -