[推荐]aw60读取DS1302程序。仿网友广州老赵的C51。
- UID
- 153886
- 性别
- 男
|
[推荐]aw60读取DS1302程序。仿网友广州老赵的C51。
void BurstR1302T(uchar *pRClock)
{
uchar i;
T_RST = 0;
T_CLK = 0;
T_RST = 1;
RTInputByte(0xbf); /* 0xbf:ʱÖÓ¶à×Ö½Ú¶ÁÃüÁî */
for (i=8; i>0; i--)
{
*pRClock = RTOutputByte(); /* ¶Á1ByteÊý¾Ý */
pRClock++;
}
T_CLK = 1;
T_RST = 0;
}
void BurstW1302R(uchar *pWReg)
{
uchar i;
W1302(0x8e,0x00); /* ¿ØÖÆÃüÁî,WP=0,д²Ù×÷*/
T_RST = 0;
T_CLK = 0;
T_RST = 1;
RTInputByte(0xfe); /* 0xbe:ʱÖÓ¶à×Ö½ÚдÃüÁî */
for (i=31; i>0; i--) /* 31Byte ¼Ä´æÆ÷Êý¾Ý */
{
RTInputByte(*pWReg); /* д1ByteÊý¾Ý*/
pWReg++;
}
T_CLK = 1;
T_RST = 0;
}
void BurstR1302R(uchar *pRReg)
{
uchar i;
T_RST = 0;
T_CLK = 0;
T_RST = 1;
RTInputByte(0xff); /* 0xff:ʱÖÓ¶à×Ö½Ú¶ÁÃüÁî */
for (i=31; i>0; i--) /*31Byte ¼Ä´æÆ÷Êý¾Ý */
{
*pRReg = RTOutputByte(); /* ¶Á1ByteÊý¾Ý */
pRReg++;
}
T_CLK = 1;
T_RST = 0;
}
void Set1302(uchar *pClock)
{
uchar i;
uchar ucAddr = 0x80;
W1302(0x8e,0x00); /* ¿ØÖÆÃüÁî,WP=0,д²Ù×÷?*/
for(i =7; i>0; i--)
{
W1302(ucAddr,*pClock); /* Ãë ·Ö Ê± ÈÕ Ô ÐÇÆÚ Äê */
pClock++;
ucAddr +=2;
}
W1302(0x8e,0x80); /* ¿ØÖÆÃüÁî,WP=1,д±£»¤?*/
}
void Get1302(uchar ucCurtime[])
{
uchar i;
uchar ucAddr = 0x81;
for (i=0; i<7; i++)
{
ucCurtime = R1302(ucAddr);/*¸ñʽΪ: Ãë ·Ö Ê± ÈÕ Ô ÐÇÆÚ Äê */
ucAddr += 2;
}
}
|
|
|
|
|
|
- UID
- 153886
- 性别
- 男
|
void main(void)
{
//ds1302
//uchar DS1302_InitDate[]={0x33,0x37,0x0e,0x0a,0x02,0x07};
//uchar DS1302_RDDate[8];
Set1302(DS1302_InitDate);
delayXms(500);
//Ãë ·Ö Ê± ÈÕ Ô ÐÇÆÚ Äê
Get1302(DS1302_RDDate);
if(DS1302_RDDate[0]>=60) {
DS1302_RDDate[0]=0;
DS1302_RDDate[1]+=1;
if(DS1302_RDDate[1]>=60) {
DS1302_RDDate[1]=0;
DS1302_RDDate[2]+=1;
if(DS1302_RDDate[2]>=24){
DS1302_RDDate[2]=0;
DS1302_RDDate[3]+=1;
DS1302_RDDate[5]+=1;
if(DS1302_RDDate[5]>=7)
DS1302_RDDate[5]=0;
if(DS1302_RDDate[3]>=31){
DS1302_RDDate[3]=0;
DS1302_RDDate[4]+=1;
if(DS1302_RDDate[4]>=12){
DS1302_RDDate[4]=0;
DS1302_RDDate[6]+=1;
if(DS1302_RDDate[6]>=99)
DS1302_RDDate[6]=0;
}
}
}
}
}
disp_int(4,0,DS1302_RDDate[6]);
disp_int(4,4,DS1302_RDDate[4]);
disp_int(4,8,DS1302_RDDate[3]);
disp_int(4,12,DS1302_RDDate[2]);
disp_int(6,0,DS1302_RDDate[1]);
disp_int(6,4,DS1302_RDDate[0]);
disp_int(6,8,DS1302_RDDate[5]);
} |
|
|
|
|
|
- UID
- 153886
- 性别
- 男
|
帖子有大小限制,太痛苦了,发了几次不成功。
还有其他报错,从CODEWARRIOR过来的中文不支持。 |
|
|
|
|
|
- UID
- 104631
- 性别
- 男
|
你可以把文件压缩成zip或rar以后,上传到本版。
版内支持附件上传的,压缩文件取英文名字,中间不要有空格 |
|
|
|
|
|