【全球独家】pt100测温程序-LCD1602

#include"at89X52.h"

sbitLCD_RS=P2^0;

sbitLCD_RW=P2^1;


(相关资料图)

sbitLCD_E=P2^2;

sbitADC_CS=P2^3;

sbitADC_WR=P3^6;

sbitADC_RD=P3^7;

#defineLCD_DATAP0

unsignedcharLcdBuf1[10]="";

unsignedcharcodeBmp001[][8]=

{

{0x06,0x09,0x09,0x06,0x00,0x00,0x00,0x00},

{0x06,0x09,0x10,0x10,0x10,0x09,0x06,0x00}

};

voiddellay(unsignedinth)

{

while(h--);//0.01MS

}

voidWriteDataLcd(unsignedcharwdata)

{

LCD_DATA=wdata;

LCD_RS=1;

LCD_RW=0;

LCD_E=0;

dellay(1000);

LCD_E=1;

}

voidWriteCommandLcd(unsignedcharwdata)

{

LCD_DATA=wdata;

LCD_RS=0;

LCD_RW=0;

LCD_E=0;

dellay(1000);

LCD_E=1;

}

voidlcd_init(void)

{

LCD_DATA=0;

WriteCommandLcd(0x38);

dellay(1000);

WriteCommandLcd(0x38);

dellay(1000);

WriteCommandLcd(0x01);

WriteCommandLcd(0x0c);

}

voiddisplay_xy(unsignedcharx,unsignedchary)

{

if(y==1)

x+=0x40;

x+=0x80;

WriteCommandLcd(x);

}

voiddisplay_string(unsignedcharx,unsignedchary,unsignedchar*s)

{

display_xy(x,y);

while(*s)

{

WriteDataLcd(*s);

s++;

}

}

voidWrite_CGRAM(unsignedcharadd,unsignedchar*char_num)

{

unsignedi;

add=add<<3;

WriteCommandLcd(0x40|add+8);

for(i=0;i<8;i++)

{

WriteDataLcd(*char_num++);

}

}

voiddelayms()

{

inti;

for(i=110;i>0;i--);

}

voiddelay1s()

{

inti,j;

for(i=1000;i>0;i--);

for(j=110;j>0;j--);

}

voidconvert()

{

unsignedlongvalue;

chari;

unsignedlongres;

inttemp,temp2;

intw;

P1=0xff;

ADC_RD=0;

for(i=0;i<10;i++);

value=P1;

res=(float)(2550000+110000*value/30)/(2550-11*value/30);

temp=(float)(res*10000-10000000)/3851-545;

temp2=temp;

if(temp>=0)

{

for(i=6;temp>0;i--)

{

LcdBuf1[i]=temp%10+48;

temp/=10;

}

}

if(temp<0)

{

w=-temp;

for(i=6;w>0;i--)

{

LcdBuf1[i]=w%10+48;

w/=10;

}

}

if(i>=0&&temp<0)

{

if(temp>-10)

{

LcdBuf1[i]=0;

i--;

}

LcdBuf1[i]=-;

i--;

/* if(i==5)

{

LcdBuf1[5]=0;

i--;

}

LcdBuf1[4]=-;

i--; */

}

for(;i>=0;i--)

LcdBuf1[i]=;

for(i=0;i<5;i++)

LcdBuf1[i]=LcdBuf1[i+1];

if(LcdBuf1[4]==)LcdBuf1[4]=0;

LcdBuf1[5]=.;

LcdBuf1[7]=1;

LcdBuf1[8]=C;

WriteCommandLcd(0x84);

display_string(3,0,LcdBuf1);

ADC_RD=1;

ADC_WR=0;

for(i=0;i<10;i++)

ADC_WR=1;

delayms();

}

main()

{

unsignedchari;

lcd_init();

for(i=0;i<2;i++)

Write_CGRAM(i,Bmp001[i]);

ADC_CS=0;

ADC_WR=0;

for(i=0;i<10;i++);

ADC_WR=1;

while(1)

{

convert();

delay1s();

}

}