基于ds1302的电子日历系统
#define er 0x80+0x40
sbit DQ = P3^5;
sbit RS=P1^7;
sbit E=P2^4;
sbit RW=P1^6;
sbit IO=P1^5;
sbit SCLK=P1^4;
sbit RST=P2^2;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
sbit key1=P1^0;
sbit key2=P1^2;
sbit key3=P1^3;
uchar code tab1[]={"20 - - "};
uchar code tab2[]={" : : "};
void delay(uint xms)
{
uint x,y;
for(x=xms;x》0;x--) ;
for(y=110;y》0;y--);
}
//液晶写入指令函数
write_1602com(uchar com)
{
RS=0;
RW=0;
P0=com;
delay(1);
E=1;
delay(1);
E=0;
}
//液晶写入数据函数
write_1602dat(uchar dat)
{
RS=1;
RW=0;
P0=dat;
delay(1);
E=1;
delay(1);
E=0;
}
//液晶初始化函数
lcd_init()
{
write_1602com(0x38);
write_1602com(0x0c);
write_1602com(0x06);
write_1602com(0x01);
write_1602com(yh+1);
for(a=0;a《14;a++)
{
write_1602dat(tab1[a]);
delay(3);
}
write_1602com(er+2);
for(a=0;a《8;a++)
{
write_1602dat(tab2[a]);
delay(3);
}
}
/***************DS1302有关子函数********************/
//写一个字节
void write_byte(uchar dat)
{
ACC=dat;
RST=1;
for(a=8;a》0;a--)
{
IO=ACC0;
SCLK=0;
SCLK=1;
ACC=ACC》》1;
}
}
//读一个字节
uchar read_byte()
{
RST=1;
for(a=8;a》0;a--)
{
ACC7=IO;
SCLK=1;
SCLK=0;
ACC=ACC》》1;
}
return (ACC);
}
//向1302芯片写函数,指定写入地址,数据
void write_1302(uchar add,uchar dat)
{
RST=0;
SCLK=0;
RST=1;
write_byte(add);
write_byte(dat);
SCLK=1;
RST=0;
}
//从1302读数据函数,指定读取数据来源地址
uchar read_1302(uchar add)
{
uchar temp;
RST=0;
SCLK=0;
RST=1;
write_byte(add);
temp=read_byte(); SCLK=1;
RST=0; return(temp);
}
//BCD码转十进制函数,输入BCD,返回十进制
uchar BCD_Decimal(uchar bcd)
{
uchar Decimal;
Decimal=bcd》》4;
return(Decimal=Decimal*10+(bcd&=0x0F));
}
//1302芯片初始化子函数(2012-06-26,00:00:00,week2)
void ds1302_init()
{
RST=0;
SCLK=0;
write_1302(0x8e,0x00);
write_1302(0x80,0x00);
write_1302(0x82,0x00);
write_1302(0x84,0x00);
write_1302(0x8a,0x02);
write_1302(0x86,0x26);
write_1302(0x88,0x06);
write_1302(0x8c,0x12);
write_1302(0x8e,0x80);
}
//时分秒显示子函数
void write_sfm(uchar add,uchar dat)
{
uchar gw,sw;
gw=dat%10;
sw=dat/10;
write_1602com(er+add);
write_1602dat(0x30+sw);
write_1602dat(0x30+gw);
}
//年月日显示子函数
void write_nyr(uchar add,uchar dat)
{
uchar gw,sw;
gw=dat%10;
sw=dat/10;
write_1602com(yh+add);
write_1602dat(0x30+sw);
write_1602dat(0x30+gw);
}
//写星期函数
void write_week(uchar week)
{
write_1602com(yh+0x0c);
switch(week
{
case 1:
write_1602dat(‘M’);
write_1602dat(‘O’);
write_1602dat(‘N’);
break;
case 2:
write_1602dat(‘T’);
write_1602dat(‘U’);
write_1602dat(‘E’);
break;
case 3:
write_1602dat(‘W’);
write_1602dat(‘E’);
write_1602dat(‘D’);
break;
case 4:
write_1602dat(‘T’
write_1602dat(‘H’);
write_1602dat(‘U’);
break;
case 5:
write_1602dat(‘F’);
write_1602dat(‘R’);
write_1602dat(‘I’);
break;
case 6:
write_1602dat(‘S’);
write_1602dat(‘T’);
write_1602dat(‘A’);
break;
case 7:
write_1602dat(‘S’);
write_1602dat(‘U’);
writ
- ds1302晶振不起振_ds1302晶振电路图(07-26)
- ds1302和ds1307区别_ds1302和ds12c887区别(07-26)
- 用ds1302做时钟电路图详解(09-19)
- 一种智能化的温湿度智能控制系统设计(02-02)
- AT89S51实现LED显示数字电压表设计(07-05)
- 单片机的智能温度预警系统教学案例(03-21)