能给个ds12c887在液晶显示的c语言程序吗?stw090103@163.com
2011-04-30
展开全部
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar clock_array1[]={"TIME: 00:00:00"};
uchar clock_array2[]={"2011/04/27 3"};
uchar shi,fen,miao,lian,yue,ri,xing;
void init();
sbit rs=P2^2;
sbit rw=P2^1;
sbit en=P2^0;
sbit dscs=P2^7;
sbit dsas=P2^6;
sbit dsrw=P2^5;
sbit dsds=P2^4;
void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++)
for(j=0;j<120;j++);
}
void command (uchar com)
{
rs=0;
rw=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
}
void data1(uchar data1)
{
rs=1;
rw=0;
P0=data1;
delay(5);
en=1;
delay(5);
en=0;
}
void write_sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
command(0x80+add);
data1(0x30+shi);
data1(0x30+ge);
}
void write_lyr(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
command(0x80+0x40+add);
data1(0x30+shi);
data1(0x30+ge);
}
void write_xing(uchar add,uchar date)
{
uchar ge;
ge=date%10;
command(0x80+0x40+add);
data1(0x30+ge);
}
void ds_write(uchar add,uchar data2) //写数据
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P1=add;
dsas=0;
dsrw=0;
P1=data2;
dsrw=1;
dsas=1;
dscs=1;
}
uchar ds_read(uchar add) //读数据
{
uchar ds_date;
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P1=add;
dsas=0;
dsds=0;
P1=0xff;
ds_date=P1;
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
void init()
{
uchar i;
command(0x01);
command(0x38); //设显示模式
command(0x0c); //开显示
for(i=0;i<14;i++)
{
data1(clock_array1[i]);
delay(10);
}
command(0x80+0x40);
for(i=0;i<14;i++)
{
data1(clock_array2[i]);
delay(10);
}
}
void main()
#define uint unsigned int
#define uchar unsigned char
uchar clock_array1[]={"TIME: 00:00:00"};
uchar clock_array2[]={"2011/04/27 3"};
uchar shi,fen,miao,lian,yue,ri,xing;
void init();
sbit rs=P2^2;
sbit rw=P2^1;
sbit en=P2^0;
sbit dscs=P2^7;
sbit dsas=P2^6;
sbit dsrw=P2^5;
sbit dsds=P2^4;
void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++)
for(j=0;j<120;j++);
}
void command (uchar com)
{
rs=0;
rw=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
}
void data1(uchar data1)
{
rs=1;
rw=0;
P0=data1;
delay(5);
en=1;
delay(5);
en=0;
}
void write_sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
command(0x80+add);
data1(0x30+shi);
data1(0x30+ge);
}
void write_lyr(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
command(0x80+0x40+add);
data1(0x30+shi);
data1(0x30+ge);
}
void write_xing(uchar add,uchar date)
{
uchar ge;
ge=date%10;
command(0x80+0x40+add);
data1(0x30+ge);
}
void ds_write(uchar add,uchar data2) //写数据
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P1=add;
dsas=0;
dsrw=0;
P1=data2;
dsrw=1;
dsas=1;
dscs=1;
}
uchar ds_read(uchar add) //读数据
{
uchar ds_date;
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P1=add;
dsas=0;
dsds=0;
P1=0xff;
ds_date=P1;
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
void init()
{
uchar i;
command(0x01);
command(0x38); //设显示模式
command(0x0c); //开显示
for(i=0;i<14;i++)
{
data1(clock_array1[i]);
delay(10);
}
command(0x80+0x40);
for(i=0;i<14;i++)
{
data1(clock_array2[i]);
delay(10);
}
}
void main()
追问
在ds_read中为什么要有p1=0xff,后面又有ds_date=p1,那么不就是让ds_date=0xff了吗?求解释,在dallas的技术手册上只有时序图,并没有提到要写p1=0xff。我就是搞不明白。谢谢了
追答
其实在这之中还有一步,是DS12C887向P1口写数据, 所以P1=0xff这一步也可以不写的,写这步只是让P1口输出全为1,然后DS12C887再向P1口输出数据,然后再有ds_date=P1;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询