新闻中心

EEPW首页>嵌入式系统>设计应用> 自制51单片机超大数码管时钟

自制51单片机超大数码管时钟

作者: 时间:2012-08-04 来源:网络 收藏

delay()
{
int j;
for (j=0;j100;j++);
}

void display(unsigned char *lp)//显示
{
uint k;
for (k=0;k4;k++)
{
pos=w[k];
segs=d[lp[k]];
delay();
segs=d[17];
}

pos=w[4];
segs=d[flash]; //秒闪烁灯
delay();
segs=d[17];

}

void Write_Ds1302_Byte(unsigned char temp)
{
unsigned char i;
for (i=0;i8;i++) //循环8次 写入数据
{
SCL2=0;
SDA2=temp0x01; //每次传输低字节
temp>>=1; //右移一位
SCL2=1;
}
}

/***********************************************************

*****************/
void Write_Ds1302( unsigned char address,unsigned char dat )
{
RST=0;
_nop_();
SCL2=0;
_nop_();
RST=1;
_nop_(); //启动
Write_Ds1302_Byte(address); //发送地址
Write_Ds1302_Byte(dat); //发送数据
RST=0; //恢复
}
/*********************************************************

*******************/
unsigned char Read_Ds1302 ( unsigned char address )
{
unsigned char i,temp=0x00;
RST=0;
_nop_();
SCL2=0;
_nop_();
RST=1;
_nop_();
Write_Ds1302_Byte(address);
for (i=0;i8;i++) //循环8次 读取数据
{
if(SDA2)
temp|=0x80; //每次传输低字节
SCL2=0;
temp>>=1; //右移一位
SCL2=1;
}
RST=0;
_nop_(); //以下为DS1302复位的稳定时间
RST=0;
SCL2=0;
_nop_();
SCL2=1;
_nop_();
SDA2=0;
_nop_();
SDA2=1;
_nop_();
return (temp); //返回
}
/**************************************************************

**************/
void Read_RTC(void) //读取 日历
{
unsigned char i,*p;
p=read_rtc_address; //地址传递
for(i=0;i7;i++) //分7次读取 年月日时分秒星期
{
now[i]=Read_Ds1302(*p);
p++;
}
}
/***********************************************************

************/
void Set_RTC(void) //设定 日历
{
unsigned char i,*p,tmp;
for(i=0;i7;i++){
tmp=now[i]/10;
now[i]=now[i]%10;
now[i]=now[i]+tmp*16;
}
Write_Ds1302(0x8E,0X00);

p=write_rtc_address; //传地址
for(i=0;i7;i++) //7次写入 年月日时分秒星期
{
Write_Ds1302(*p,now[i]);
p++;
}
Write_Ds1302(0x8E,0x80);
}

void keydelay(unsigned char t)
{
unsigned char i,j;
for(i=0;it;i++)
for(j=0;j120;j++);
}

51单片机相关文章:51单片机教程



上一页 1 2 下一页

关键词:51单片机超大数码管时钟

评论


相关推荐

技术专区

关闭