#include<reg51.h>
#include<stdio.h>
sbit RS=P0^0;
sbit RW=P0^1;
sbit EN=P0^2;
sbit cs=P2^0;
sbit rd=P2^1;
sbit wr=P2^2;
sbit intr=P2^3;
#define ldata P1
void lcd_init();
void cmd(unsigned char c);
void dat(unsigned char c);
void delay(unsigned int i);
void digit(unsigned int i);
int adc()
{
unsigned int x;
cs=0;
wr=0;
delay(1);
wr=1;
rd=1;
while(intr==1);
rd=0;
x=P3;
return x;
}
void main()
{
unsigned char z[20],i=0,s[]="WWW.SUMMITBHARDWAJ.BLOGSPOT.IN";
unsigned int v,a,t;
lcd_init();
cmd(0x80);
while(s[i]!='\0')
{
dat(s[i]);
i++;
}
while(1)
{
a=adc();
v=((a*5)/255);
t=((a*5)/2.55);
sprintf(z,"ADC=%3d volt=%2dV temp=%3d'c",a,v,t);
cmd(0xc0);
i=0;
while(z[i]!='\0')
{
dat(z[i]);
i++;
}
}
}
void digit(unsigned int i)
{
unsigned char a,c=0x85;
do
{
cmd(c--);
a=i%10;
dat(48+a);
cmd(0x80);
delay(10);
i=i/10;
}
while(i>0);
}
void lcd_init()
{
cmd(0X01);
delay(10);
cmd(0X08);
delay(10);
cmd(0X0c);
delay(10);
cmd(0X38);
delay(10);
}
void cmd(unsigned char c)
{
int i;
ldata=c;
RS=0;
RW=0;
EN=1;
for(i=0;i<10;i++);
EN=0;
return;
}
void dat(unsigned char c)
{
int i;
ldata=c;
RS=1;
RW=0;
EN=1;
for(i=0;i<=10;i++);
EN=0;
return;
}
void delay(unsigned int b)
{
unsigned int i,j;
for(i=0;i<b;i++)
for(j=0;j<3000;j++);
}
No comments:
Post a Comment