|
在做毕设,硬件电路以及程序如下。但是液晶显示无变化。求指导修改
[复制链接]
#include"reg51.h"
#include"stdio.h"
#define uchar unsigned char
#define uint unsigned int
#define LCM_data P0
sbit lcd_flag=P0^7;
sbit AD0832do=P1^0;
sbit AD0832cs=P1^1;
sbit AD0832clk=P1^2;
sbit LCM_RS=P2^0;
sbit LCM_RW=P2^1;
sbit LCM_E=P2^2;
sbit TLC5615_SCLK=P2^3;
sbit TLC5615_CS=P2^4;
sbit TLC5615_DIN=P2^5;
uchar H;
uchar dis1[16];
uchar dis2[16]={"Temp:"};
void delay(uchar m)
{
uint i;
for(i=0;ix[n+1])
{
p=x[n];
x[n]=x[n+1];
x[n+1]=p;
}
}
}
float ZZLB()
{
uchar m,n;
uchar arrx[5]={0},arry[5]={0}; //
float p;
for(m=0;m<5;m++)
{
H=0;
arrx[m]=tlccread();
delay(2);
}
for(n=0;n<5;n++)
{
H=1;
arry[n]=tlccread();
}
PAIXU(arrx);
PAIXU(arry);
p=TBC(arrx[2],arry[2]);
return(p);
}
uint zxh(float a) //线性化子程序
{
uint T;
float k1=25.445,k2=24.549,k3=25.786,k4=26.123,k5=26.596,k6=27.278;//标度变换求温度
if(a<28.456) T=700+(uint)(k1*(a-24.526));
else if(a<32.370) T=800+(uint)(k2*(a-28.456));
else if(a<36.248) T=900+(uint)(k3*(a-32.370));
else if(a<40.076) T=1000+(uint)(k4*(a-36.248));
else if(a<43.836) T=1100+(uint)(k5*(a-41.966));
else T=1200+(uint)(k6*(a-43.836)+14);
return(T);
}
bit lcd_busy() //RS=Low,RW=High,E=High:读状态
{ //判断是否忙碌函数
bit flag;
LCM_RS=0; //寄存器为Low
LCM_RW=1; //是否读写为High
LCM_E=1; //使能端为High
if (lcd_flag==1) flag=1;
else flag=0;
LCM_E=0;
return(flag); //返回标志,判断是否LCD忙碌
}
void lcd_putcommand(uchar command) //RS=Low,RW=Low,E=High:写指令
{ //写指令函数
while (lcd_busy()); //判断是否忙碌
LCM_RS=0;
LCM_RW=0;
LCM_E=0; //置E=low
LCM_data=command; //输入指令
LCM_E=1; //置E=High
LCM_E=0;
}
void lcd_putchar(uchar putchar) //RS=High,RW=Low,E=High:写数据
{ //写数据函数
while(lcd_busy()); //判断是否忙碌
LCM_RS=1;
LCM_RW=0;
LCM_E=0; //置E=Low
LCM_data=putchar; //输入数据
LCM_E=1; //置E=High
LCM_E=0;
}
void lcd_moveto(uchar x, uchar y) //第X行Y列(X=1 or 2,Y=1-16)
{ //设计输入位置函数
if ((x-1)==0) lcd_putcommand(0x80|y-1); //判断是否第一行,并设计为第Y列
if ((x-1)==1) lcd_putcommand(0xc0|y-1); //判断是否第二行,并设计为第Y列
}
void lcd_delay(unsigned char t)
{ //设计延时函数
unsigned int i;
for(;t>0;t--)
for(i=0;i<124;i++);
}
void lcd_init(void)
{
lcd_putcommand(0x38); //LCD为2行,5×7字
lcd_delay(1);
lcd_putcommand(0x0c); //打开显示,显示光标
lcd_delay(1);
lcd_putcommand(0x06); //光标右移,字符不动
lcd_delay(1);
}
void lcd_display(uchar *sztext1,uchar *sztext2)
{ uchar m;
lcd_moveto(1,1); //光标至第1行第1列
m=0;
while(sztext1[m]!='\0')
{
lcd_putchar(sztext1[m]); //写数据
m++;
lcd_delay(30);
}
lcd_moveto(2,1); //光标至第2行第1列
m=0;
while(sztext2[m]!='\0')
{
lcd_putchar(sztext2[m]); //写数据
m++;
lcd_delay(30);
}
//lcd_putcommand(0x01); //清屏
}
void main(void)
{
uchar a;
uint b;
lcd_init();
while(1)
{
a=ZZLB();
b=zxh(a);
if((b<0)||(b>1200))
{
dis1[2]='b';
dis1[3]='a';
dis1[4]='d';
}
dis1[0]='w';
dis1[1]='d';
if((b>=0)&&(b<=1200))
{
dis1[2]=':';
dis1[3]=(b%1000)/100+0x30;
dis1[4]=(b%100)/10+0x30;
dis1[5]=(b%10)+0x30;
dis1[6]='C';
lcd_display(dis2,dis1);
}
}
}
[ 本帖最后由 zhanghao8911 于 2012-5-6 10:43 编辑 ]
|
|