void initlcd();
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void msdelay(unsigned int x);
void usdelay();
void delay(unsigned int i);
sfr ldata=0xA0;//P2
sbit led=P3^1;
sbit rs=P3^5;
sbit rw=P3^6;
sbit en=P3^7;
sbit INTR=P3^2;
sbit rea=P3^3;
sbit wri=P3^4;
void convert(unsigned char x);
void readadc();
unsigned char msg[]= "Temperature";
unsigned char msg1[]="Measurement";
unsigned char Temp[]="027 deg";
unsigned char set,ref;
void readadc(void)
{
unsigned char a,c;
P1=0xFF;
INTR=1;rea=1;wri=1;
wri=0;
wri=1;
while(INTR==1);
rea=0;
a=P1;
c=a;
ref=c;
convert(a);
rea=1;
return;
}
void convert(unsigned char x)
{
unsigned char d1,d2,d3,y;
y=x/10;
d1=x%10;
d1=d1|0x30;
d3=y/10;
d3=d3|0x30;
d2=y%10;
d2=d2|0x30;
Temp[0]=d3;
Temp[1]=d2;
Temp[2]=d1;
return;
}
void ENABLE(void) // Invoking the enable function
{ en=1; // Give high to low pulse to Enable the LCD.
msdelay(1);
en=0;
msdelay(1);
}
void msdelay(unsigned int value)
{
unsigned int i,j;
for(i=0;i<value;i++)
for(j=0;j<1275;j++);
return;
}
void usdelay()
{
unsigned int i;
for(i=0;i<250;i++);
return;
}
void delay(unsigned int i)
{
int m;
for(m=0;m<=i;m++);
return;
}
void lcdcmd(unsigned char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
msdelay(1);
en=0;
msdelay(1);
return;
}
void lcddata(unsigned char value)
{
ldata= value;
rs=1;
rw=0;
en=1;
msdelay(1);
en=0;
msdelay(1);
return;
}
void lcd_sendstr(unsigned char *string)
{
while(*string)
lcddata(*string++);
}
void LINE(int i) // start of LINE function
{
if (i==1)
{rs=0; // first make the reset signal low
rw=0; // make RW low to give commands to the LCD
P2=0x80; // force cursor to beginning of the first line
ENABLE(); // enable the LCD
rs=1;
}else
{
rs=0;
rw=0;
P2=0xC0; // force cursor to beginning of the second line
ENABLE();
rs=1;
}
}
void initlcd()
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
}
void main(void)
{
unsigned char a,i;
set=0x50;
led=0;
led=0;
msdelay(30);
led=1;
msdelay(30);
led=0;
msdelay(30);
led=1;
P2=0x00;
initlcd();
lcdcmd(0x01);
LINE(1);
lcd_sendstr("Temperature");
LINE(2);
lcd_sendstr(" Measurement ");
msdelay(200);
lcdcmd(0xC1);
for(a=0;a<=11;a++)
{
lcddata(Temp[a]);
}
while(1)
{
readadc();
if(set<=ref){led=1;}else{led=0;};
lcdcmd(0xC0);
for(a=0;a<=6;a++)
{
lcddata(Temp[a]);
}
}
}
No comments:
Post a Comment