帮忙看下这个程序怎么1602不显示啊
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#include<intrins.h>
#include<math.h>
#define uchar unsigned char //定义符号uchar为数据类型符unsigned char
#define uint unsigned int //定义符号uint为数据类型符unsigned int
#define ulong unsigned long //定义符号ulong为数据类型符unsigned long
sbit icl7135_B1=P1^0;
sbit icl7135_B2=P1^1;
sbit icl7135_B4=P1^2;
sbit icl7135_B8=P1^3;
sbit icl7135_RH=P1^4;
sbit icl7135_STRB=P3^2;
sbit icl7135_POL=P1^5;
sbit cd4051_A=P1^6;
sbit cd4051_B=P1^7;
#define DB_1602 P2
sbit RS_1602=P0^0;
sbit RW_1602=P0^1;
sbit E_1602=P0^2;
sbit beem_ov=P0^0;
sbit beem_low=P0^1;
uchar msg1[16]="voltage: ";
uchar msg2[16]=" v";
uchar tem[7],count;
float adshuju;
void Display();
void explode(ulong);
void explode_data(float);
void Delay(uint t);
void SendCommandByte(uchar);
void SendDataByte(uchar ch);
void InitLcd();
void DisplayMsg(uchar *);
void main()
{
InitLcd();
SendCommandByte(0x80);
DisplayMsg(msg1);
while(1)
{
count=0;
adshuju=0;
cd4051_B=1;
cd4051_A=0;
icl7135_RH=1;
while(count!=5);
if(count==5);
{
count=0;
if(adshuju>19999)
beem_ov=0;
else if(adshuju>=2)
{
adshuju=adshuju/0.2/10000;
Display();
}
else
{
adshuju=0;
cd4051_B=0;
cd4051_A=1;
icl7135_RH=1;
while(count!=5);
if(adshuju>2)
{
adshuju=adshuju/2/10000;
Display();
}
else
{adshuju=0;
cd4051_B=0;
cd4051_A=0;
icl7135_RH=1;
while(count!=5);
if(adshuju>=2)
{
adshuju=adshuju/20/10000;
Display();
}
else
beem_low=0;
}
}
}
}
}
void ISR_Int0()interrupt 0
{
uchar jgbcd;
count++;
if(count==1)icl7135_RH=0;
P1=P1&0x0f;
jgbcd=P1&0x0f;
adshuju+=jgbcd*pow(10,5-count);
}
void Display()
{
uchar i;
explode_data(adshuju);
if(icl7135_POL==1)
tem[0]=0x20;
else
tem[0]=0x2d;
for(i=0;i<6;i++)
msg2[2+i]=tem[i];
//sendCommandByte(0x80);
//DisplayMsg(msg1);
SendCommandByte(0xc0);
DisplayMsg(msg2);
}
void explode(ulong wdata)
{
uchar i;
unsigned long xh;
xh=10000;
for(i=0;i<7;i++)
tem[i]=0;
for(i=1;i<6;i++)
{
tem[i]=wdata/xh;
wdata=wdata-xh*tem[i];
xh=xh/10;
}
for(i=1;i<6;i++)
tem[i]=tem[i]+0x30;
}
void explode_data(float gdata)
{
uchar i;
idata ulong temp;
if(gdata>=10000)
explode(temp);
else if(gdata>=1000)
{
temp=gdata*10;
explode(temp);
tem[5]='.';
}
else if(gdata>=100)
{
temp=gdata*100;
explode(temp);
for(i=4;i>3;i--)
tem[i+1]=tem[i];
tem[4]='.';
}
else if(gdata>=10)
{
temp=gdata*1000;
explode(temp);
for(i=4;i>2;i--)
tem[i+1]=tem[i];
tem[3]='.';
}
else if(gdata>=0)
{
temp=gdata*10000;
explode(temp);
for(i=4;i>1;i--)
tem[i+1]=tem[i];
tem[2]='.';
}
}
void delay(uint t)
{
for(;t!=0;t--);
}
void delay1(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void delay2(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=100;b>0;b--);
}
void SendCommandByte(uchar ch)
{
//ch=_crol_(ch,8);
uchar i,hc=0;
for(i=0;i<8;i++)
{
hc<<=1;
hc|=ch&0x01;
ch>>=1;
}
RS_1602=0;
RW_1602=0;
DB_1602=hc;
E_1602=0;
delay(1);
E_1602=1;
delay(1);
E_1602=0;
delay(100);
}
void SendDataByte(uchar ch)
{
uchar i,hc=0;
for(i=0;i<8;i++)
{
hc<<=1;
hc|=ch&0x01;
ch>>=1;
}
RS_1602=1;
RW_1602=0;
DB_1602=hc;
E_1602=0;
delay(1);
E_1602=1;
delay(1);
E_1602=0;
delay(100);
}
void InitLcd()
{
delay(40000);
SendCommandByte(0x38);
delay(4000);
SendCommandByte(0x38);
delay(4000);
SendCommandByte(0x38);
delay(4000);
SendCommandByte(0x38);
SendCommandByte(0x0c);
SendCommandByte(0x01);
SendCommandByte(0x06);
}
void DisplayMsg(uchar *p)
{
uchar i;
for(i=0;1<16;i++)
SendDataByte(*p++);
}
#include<intrins.h>
#include<math.h>
#define uchar unsigned char //定义符号uchar为数据类型符unsigned char
#define uint unsigned int //定义符号uint为数据类型符unsigned int
#define ulong unsigned long //定义符号ulong为数据类型符unsigned long
sbit icl7135_B1=P1^0;
sbit icl7135_B2=P1^1;
sbit icl7135_B4=P1^2;
sbit icl7135_B8=P1^3;
sbit icl7135_RH=P1^4;
sbit icl7135_STRB=P3^2;
sbit icl7135_POL=P1^5;
sbit cd4051_A=P1^6;
sbit cd4051_B=P1^7;
#define DB_1602 P2
sbit RS_1602=P0^0;
sbit RW_1602=P0^1;
sbit E_1602=P0^2;
sbit beem_ov=P0^0;
sbit beem_low=P0^1;
uchar msg1[16]="voltage: ";
uchar msg2[16]=" v";
uchar tem[7],count;
float adshuju;
void Display();
void explode(ulong);
void explode_data(float);
void Delay(uint t);
void SendCommandByte(uchar);
void SendDataByte(uchar ch);
void InitLcd();
void DisplayMsg(uchar *);
void main()
{
InitLcd();
SendCommandByte(0x80);
DisplayMsg(msg1);
while(1)
{
count=0;
adshuju=0;
cd4051_B=1;
cd4051_A=0;
icl7135_RH=1;
while(count!=5);
if(count==5);
{
count=0;
if(adshuju>19999)
beem_ov=0;
else if(adshuju>=2)
{
adshuju=adshuju/0.2/10000;
Display();
}
else
{
adshuju=0;
cd4051_B=0;
cd4051_A=1;
icl7135_RH=1;
while(count!=5);
if(adshuju>2)
{
adshuju=adshuju/2/10000;
Display();
}
else
{adshuju=0;
cd4051_B=0;
cd4051_A=0;
icl7135_RH=1;
while(count!=5);
if(adshuju>=2)
{
adshuju=adshuju/20/10000;
Display();
}
else
beem_low=0;
}
}
}
}
}
void ISR_Int0()interrupt 0
{
uchar jgbcd;
count++;
if(count==1)icl7135_RH=0;
P1=P1&0x0f;
jgbcd=P1&0x0f;
adshuju+=jgbcd*pow(10,5-count);
}
void Display()
{
uchar i;
explode_data(adshuju);
if(icl7135_POL==1)
tem[0]=0x20;
else
tem[0]=0x2d;
for(i=0;i<6;i++)
msg2[2+i]=tem[i];
//sendCommandByte(0x80);
//DisplayMsg(msg1);
SendCommandByte(0xc0);
DisplayMsg(msg2);
}
void explode(ulong wdata)
{
uchar i;
unsigned long xh;
xh=10000;
for(i=0;i<7;i++)
tem[i]=0;
for(i=1;i<6;i++)
{
tem[i]=wdata/xh;
wdata=wdata-xh*tem[i];
xh=xh/10;
}
for(i=1;i<6;i++)
tem[i]=tem[i]+0x30;
}
void explode_data(float gdata)
{
uchar i;
idata ulong temp;
if(gdata>=10000)
explode(temp);
else if(gdata>=1000)
{
temp=gdata*10;
explode(temp);
tem[5]='.';
}
else if(gdata>=100)
{
temp=gdata*100;
explode(temp);
for(i=4;i>3;i--)
tem[i+1]=tem[i];
tem[4]='.';
}
else if(gdata>=10)
{
temp=gdata*1000;
explode(temp);
for(i=4;i>2;i--)
tem[i+1]=tem[i];
tem[3]='.';
}
else if(gdata>=0)
{
temp=gdata*10000;
explode(temp);
for(i=4;i>1;i--)
tem[i+1]=tem[i];
tem[2]='.';
}
}
void delay(uint t)
{
for(;t!=0;t--);
}
void delay1(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void delay2(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=100;b>0;b--);
}
void SendCommandByte(uchar ch)
{
//ch=_crol_(ch,8);
uchar i,hc=0;
for(i=0;i<8;i++)
{
hc<<=1;
hc|=ch&0x01;
ch>>=1;
}
RS_1602=0;
RW_1602=0;
DB_1602=hc;
E_1602=0;
delay(1);
E_1602=1;
delay(1);
E_1602=0;
delay(100);
}
void SendDataByte(uchar ch)
{
uchar i,hc=0;
for(i=0;i<8;i++)
{
hc<<=1;
hc|=ch&0x01;
ch>>=1;
}
RS_1602=1;
RW_1602=0;
DB_1602=hc;
E_1602=0;
delay(1);
E_1602=1;
delay(1);
E_1602=0;
delay(100);
}
void InitLcd()
{
delay(40000);
SendCommandByte(0x38);
delay(4000);
SendCommandByte(0x38);
delay(4000);
SendCommandByte(0x38);
delay(4000);
SendCommandByte(0x38);
SendCommandByte(0x0c);
SendCommandByte(0x01);
SendCommandByte(0x06);
}
void DisplayMsg(uchar *p)
{
uchar i;
for(i=0;1<16;i++)
SendDataByte(*p++);
}