|
本帖最后由 刘耀 于 2017-10-17 21:27 编辑
我的程序原本设想实现:第一行显示温度,第二行显示时间,初始时间是14.00.
最终结果:[color=Red]第一行温度显示正常,问题出在第二行,第二行小时位置一直显示92,既初始显示92.00。
我使用的单片机型号是普中科技V3.0 液晶是带转接板。
#include<kaohe.h>
u8 code ds1302_write_addr[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};//
u8 code ds1302_read_addr[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
u8 time[7]={0,0,0x00,0x15,0x10,0x07,0x17}; //
void ds1302write(u8 addr,u8 dat)
{
u8 i;
ce=0;
_nop_();
sclk=0;
_nop_();
ce=1;
_nop_();
for(i=0;i<8;i++)
{
dsio=addr&0x01;
addr>>=1;
sclk=1;
_nop_();
sclk=0;
_nop_();
}
for(i=0;i<8;i++)
{
dsio=dat&0x01;
dat>>=1;
sclk=1;
_nop_();
sclk=0;
_nop_();
}
sclk=0;
_nop_();
ce=0;
_nop_();
}
char ds1302read(u8 addr)
{
u8 bi,byte,i;
ce=0;
_nop_();
sclk=0;
_nop_();
ce=1;
_nop_();
for(i=0;i<8;i++)
{
dsio=addr&0x01;
addr>>=1;
sclk=1;
_nop_();
sclk=0;
_nop_();
}
_nop_();
for(i=0;i<8;i++)
{
bi=dsio;
byte=(byte>>1)|(bi<<7);
sclk=1;
_nop_();
sclk=0;
_nop_();
}
ce=0;
_nop_();
sclk=1;
_nop_();
dsio=0;
_nop_();
dsio=1;
_nop_();
return byte;
}
void ds1302read_time()
{
u8 i;
for(i=0;i<7;i++)
{
time=ds1302read(ds1302_read_addr);
}
}
void ds1302init()
{
u8 i,n;
ds1302write(0x8e,0x00);
for(n=0;n<7;n++)
{
ds1302write(ds1302_write_addr,time);
}
ds1302write(0x8e,0x80);
}
#include<reg52.h>
#include<kaohe.h>
void delayxms(u16 x)
{
u16 i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
u8 WenduData[12];
void wendudatapros(int temp)
{
float tp;
if(temp< 0)
{
WenduData[5] = 0x40;
temp=temp-1;
temp=~temp;
tp=temp;
temp=tp*0.0625*100+0.5;
}
else
{
WenduData[5] =0;
tp=temp;
temp=tp*0.0625*100+0.5;
}
WenduData[0]='T';
WenduData[1]='e';
WenduData[2]='m';
WenduData[3]='p';
WenduData[4]=':'; //
WenduData[5] = temp / 10000;
WenduData[6] =temp % 10000 / 1000+0x30;
WenduData[7] = temp % 1000 / 100 +0x30;
WenduData[8]='.';//СÊýµã
WenduData[9] = temp % 100 / 10+0x30;
WenduData[10] = temp % 10+0x30;
WenduData[11]=0xdf;
WenduData[12]=0x43; //C
if(WenduData[5]==0)
{
WenduData[5]=0x20;
}
else
{
WenduData[5]=temp / 10000+0x30;
}
}
u8 shizhongdat[13];
void shizhongdatpros()
{
ds1302read_time();
shizhongdat[0]='T';
shizhongdat[1]='i';
shizhongdat[2]='m';
shizhongdat[3]='e';
shizhongdat[4]=':';
shizhongdat[5]=time[2]/16+0x30;
shizhongdat[6]=time[2]%16+0x30;
shizhongdat[7]=0x2d;//'-';
shizhongdat[8]=time[1]/16+0x30;//fen
shizhongdat[9]=time[1]%16+0x30;
shizhongdat[10]=0x2d;//'-';
shizhongdat[11]=time[0]/16+0x30;//miao
shizhongdat[12]=time[0]%16+0x30;
}
void main()
{
u8 i,j;
lcdinit();
ds18b20init();
ds1302init();
while(1)
{
wendudatapros(ds18b20tempread());//ζÈÔÚ1602ÉÏÏÔʾ
lcdwritecom(0x80);
for(i=0;i<13;i++)
{
lcdwritedat(WenduData);
}
shizhongdatpros();
lcdwritecom(0x80+0x40);
for(j=0;j<13;j++)
{
lcdwritedat(shizhongdat[j]);
}
}
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|