1602显示问题。。
时间:10-02
整理:3721RD
点击:
求大神指教。我从AD0832采集数据后想让1602显示出来,是数组。不知道怎么写程序了,困扰好久了。
程序如下:
void convdata(unsigned char i) //i=dat*5/255=51,是255份; 256份误差大
{
unsigned int disdat; //不可unsigned char disdat
disdat=i*20.0/255; //500不可以。用500.0
/* 验证读数
dis[0] = i/100; //个位
dis[1] = i/10%10; //小数点后第一位
dis[2] = i%10; //小数点后第二位 */
dis[0] = disdat/100+0x30;//
dis[1] = disdat/10%10+0x30; //小数点后第一位
dis[2] = disdat%10+0x30;
}
int u;
u=dis[0]+dis[1]*0.1+dis[2]*0.01;
uchar code table2[]=u;
uchar code table3[]="jiaquan:";
void dispaly(void)
{
write_com(0xC0);
for(num=0;num<8;num++)
{
write_date(table3[num]);
delay(5); //稳定写入//
}
write_com(0xC8);
for(num=0;num<8;num++)
{
write_date(table2[dis[num]]);
delay(5); //稳定写入//
}
}
void baojing()
{
if(dis[1]>=1)
buzz=1;
delay();
buzz=0;
}
void LEDING()
{
if(dis[1]>=1)
LED=1;
else
LED=0;
}
void main()
{
count=0;
init();
CH = 0x00; //在这里选择通道 0x00(单极性0通道)或0x01(单极性1通道)
TMOD = 0x01; //设置中断
TH0=(65536-50000)/256;//定时器1初值定时50ms
TL0=(65536-50000)%256;
IE = 0x82;
TR0 = 1;
while(1)
{
keyscan();
if(count==20)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
write_sfm(8,shi); //4为地址
}
write_sfm(11,fen);
}
write_sfm(14,miao);
convdata(dat);
dispaly();
baojing();
LEDING();
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
}
程序如下:
void convdata(unsigned char i) //i=dat*5/255=51,是255份; 256份误差大
{
unsigned int disdat; //不可unsigned char disdat
disdat=i*20.0/255; //500不可以。用500.0
/* 验证读数
dis[0] = i/100; //个位
dis[1] = i/10%10; //小数点后第一位
dis[2] = i%10; //小数点后第二位 */
dis[0] = disdat/100+0x30;//
dis[1] = disdat/10%10+0x30; //小数点后第一位
dis[2] = disdat%10+0x30;
}
int u;
u=dis[0]+dis[1]*0.1+dis[2]*0.01;
uchar code table2[]=u;
uchar code table3[]="jiaquan:";
void dispaly(void)
{
write_com(0xC0);
for(num=0;num<8;num++)
{
write_date(table3[num]);
delay(5); //稳定写入//
}
write_com(0xC8);
for(num=0;num<8;num++)
{
write_date(table2[dis[num]]);
delay(5); //稳定写入//
}
}
void baojing()
{
if(dis[1]>=1)
buzz=1;
delay();
buzz=0;
}
void LEDING()
{
if(dis[1]>=1)
LED=1;
else
LED=0;
}
void main()
{
count=0;
init();
CH = 0x00; //在这里选择通道 0x00(单极性0通道)或0x01(单极性1通道)
TMOD = 0x01; //设置中断
TH0=(65536-50000)/256;//定时器1初值定时50ms
TL0=(65536-50000)%256;
IE = 0x82;
TR0 = 1;
while(1)
{
keyscan();
if(count==20)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
write_sfm(8,shi); //4为地址
}
write_sfm(11,fen);
}
write_sfm(14,miao);
convdata(dat);
dispaly();
baojing();
LEDING();
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
}
路过啊