这是我1302的程序,麻烦看下。谢谢!
#include<reg52.h>
sbit DS1302_CLK=P3^0;
sbit DS1302_IO=P3^1;
sbit DS1302_RST=P3^2;
unsigned char fy=0;
unsigned char tj=0;
sbit tjxz = P3^5;
sbit fanyel=P3^4;
sbit fanyer=P3^3;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
sbit qian=P2^4;
sbit bai=P2^5;
sbit shi=P2^6;
sbit ge=P2^7;
bit flag;
sfr smdis = 0x80;
sfr p2m1 = 0x95;
sfr p2m0 = 0x96;
sfr p1m1 = 0x91;
sfr p1m0 = 0x92;
code unsigned char seg1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//???????
code unsigned char seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //????
unsigned char clk_time[8]={0x59,0x58,0x8,0x9,0x12,0x03,0x09,0x20}; //?,?,?,?,?,?,?
/******************DS1302:????(???)*********************/
/*void DS1302InputByte(unsigned char da)
{
unsigned char i;
ACC=da;
for(i=8;i>0;i--)
{
DS1302_IO=ACC0;
DS1302_CLK=0;
DS1302_CLK=1;
ACC=ACC>>1;
}
}
/******************DS1302:????(???)*****************/
/*unsigned char DS1302OutputByte(void)
{
unsigned char i;
for(i=0;i<8;i++)
{
ACC=ACC>>1;
DS1302_CLK = 1;
DS1302_CLK = 0;
ACC7 = DS1302_IO;
}
return(ACC);
}
*/
void DS1302InputByte(unsigned char d) //?????????(????)
{
unsigned char i,j;
EA=0;
for(i=8; i>0; i--)
{
DS1302_CLK = 0;
for(j=2;j>0;j--);
if(d&0x01)
DS1302_IO = 1;
else DS1302_IO = 0;
for(j=2;j>0;j--);
DS1302_CLK = 1;
d=d>>1;
}
EA=1;
}
unsigned char DS1302OutputByte(void) //?????????(????)
{
unsigned char i,j,d=0;
EA=0;
for(i=0; i<8; i++)
{
DS1302_IO = 1;
DS1302_CLK = 1;
for(j=2;j>0;j--);
DS1302_CLK = 0;
if( DS1302_IO)
d=d|(0x01<<i) ;
}
return(d);
EA=1;
}
void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302??, ucData: ?????
{
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr); // ??,??
DS1302InputByte(ucDa); // ?1Byte??
DS1302_CLK = 1;
DS1302_RST = 0;
}
unsigned char Read1302(unsigned char ucAddr) //??DS1302??????
{
unsigned char ucData;
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr); // ??,??
ucData = DS1302OutputByte(); // ?1Byte??
DS1302_CLK = 1;
DS1302_RST = 0;
return(ucData);
}
void delayt(unsigned char t)//??
{
unsigned int i,j;
for(i=t;i>0;i--)
{
#include<reg52.h>
sbit DS1302_CLK=P3^0;
sbit DS1302_IO=P3^1;
sbit DS1302_RST=P3^2;
unsigned char fy=0;
unsigned char tj=0;
sbit tjxz = P3^5;
sbit fanyel=P3^4;
sbit fanyer=P3^3;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
sbit qian=P2^4;
sbit bai=P2^5;
sbit shi=P2^6;
sbit ge=P2^7;
bit flag;
sfr smdis = 0x80;
sfr p2m1 = 0x95;
sfr p2m0 = 0x96;
sfr p1m1 = 0x91;
sfr p1m0 = 0x92;
code unsigned char seg1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//???????
code unsigned char seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //????
unsigned char clk_time[8]={0x59,0x58,0x8,0x9,0x12,0x03,0x09,0x20}; //?,?,?,?,?,?,?
/******************DS1302:????(???)*********************/
/*void DS1302InputByte(unsigned char da)
{
unsigned char i;
ACC=da;
for(i=8;i>0;i--)
{
DS1302_IO=ACC0;
DS1302_CLK=0;
DS1302_CLK=1;
ACC=ACC>>1;
}
}
/******************DS1302:????(???)*****************/
/*unsigned char DS1302OutputByte(void)
{
unsigned char i;
for(i=0;i<8;i++)
{
ACC=ACC>>1;
DS1302_CLK = 1;
DS1302_CLK = 0;
ACC7 = DS1302_IO;
}
return(ACC);
}
*/
void DS1302InputByte(unsigned char d) //?????????(????)
{
unsigned char i,j;
EA=0;
for(i=8; i>0; i--)
{
DS1302_CLK = 0;
for(j=2;j>0;j--);
if(d&0x01)
DS1302_IO = 1;
else DS1302_IO = 0;
for(j=2;j>0;j--);
DS1302_CLK = 1;
d=d>>1;
}
EA=1;
}
unsigned char DS1302OutputByte(void) //?????????(????)
{
unsigned char i,j,d=0;
EA=0;
for(i=0; i<8; i++)
{
DS1302_IO = 1;
DS1302_CLK = 1;
for(j=2;j>0;j--);
DS1302_CLK = 0;
if( DS1302_IO)
d=d|(0x01<<i) ;
}
return(d);
EA=1;
}
void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302??, ucData: ?????
{
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr); // ??,??
DS1302InputByte(ucDa); // ?1Byte??
DS1302_CLK = 1;
DS1302_RST = 0;
}
unsigned char Read1302(unsigned char ucAddr) //??DS1302??????
{
unsigned char ucData;
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr); // ??,??
ucData = DS1302OutputByte(); // ?1Byte??
DS1302_CLK = 1;
DS1302_RST = 0;
return(ucData);
}
void delayt(unsigned char t)//??
{
unsigned int i,j;
for(i=t;i>0;i--)
{