本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
以前没有用过DS1302,现在初次用,想在LCD上只显示出秒的变化 。但结果是不变动 。程序如下: 请大家指点指点!
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit rw=P3^1;
sbit rs=P3^0;
sbit en=P3^2;
sbit clk=P2^4;
sbit rst=P2^6;
sbit IO=P2^5;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
uchar miao;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_lcdcom(uchar com)
{
rs=0;
P0=com;
en=1;
delay(10);
en=0;
delay(10);
}
void write_lcddate(uchar date)
{
rs=1;
P0=date;
en=1;
delay(10);
en=0;
delay(10);
}
void write_sfm(uchar add,uchar date)
{
uchar shi ,ge;
shi=date/10;
ge=date%10;
write_lcdcom(0x80+0x40+add);
write_lcddate(0x30+shi);
write_lcddate(0x30+ge);
}
void initLCD()
{
en=0;
rw=0;
write_lcdcom(0x01);
write_lcdcom(0x38);
write_lcdcom(0x0c);
write_lcdcom(0x06);
}
void write_byte1302( uchar dat)
{
uchar i;
ACC=dat;
for(i=0;i<8;i++)
{
IO=ACC0;
clk=0;
clk=1;
ACC=ACC>>1;
}
}
uchar read_byte1302()
{
uchar i;
for(i=0;i<8;i++)
{
ACC=ACC>>1;
clk=1;
clk=0;
ACC7=IO;
}
return(ACC);
}
void write1302(uchar add,uchar dat)
{
rst=0;
clk=0;
rst=1;
write_byte1302(add);
write_byte1302(dat);
rst=0;
clk=1;
}
uchar read1302(uchar add)
{
uchar temp;
rst=0;
clk=0;
rst=1;
write_byte1302(add);
temp=read_byte1302();
clk=1;
rst=0;
// clk=1;
return(temp);
}
main()
{
initLCD();
write1302(0x80,0x00);
while(1)
{
write_sfm(5,read1302(0x81));
}
} |