/*********************** ADC-0804***************************/
#include<reg51.h>
#define lcd P0
sbit rs=P2^7; // assining control pins to port2.5,6,7
sbit rw=P2^6;
sbit en=P2^5;
// control pins of adc
sbit rd=P2^0;
sbit wr=P2^1;
sbit intr=P2^2;
#define MYDATA P1
void hex2dec(unsigned int);
void initlcd(void);
void cmdlcd(unsigned char);
void displcd(unsigned char);
void writelcd(unsigned char);
void strlcd(unsigned char*);
void intlcd(unsigned int);
delay(unsigned int);
void main()
{
unsigned char value;
//MYDATA=0xFF;
intr=1;
rd=1;
wr=1;
initlcd();
strlcd("welcome");
c mdlcd(0x01);
while(1)
{
wr=0;
wr=1;
while(intr==1); //monitoring end of conversion bit until intr equal to 0
rd=0;
value=MYDATA;
hex2dec(value);
}
}
// the function is used to convert the integer value to ascii value
void hex2dec(unsigned int binbyte)
{
unsigned int x,d1,d2,d3,d4;
x=binbyte/10;
d1=binbyte%10;
d2=x%10;
d3=x/10;
d4=d3*100+d2*10+d1;
cmdlcd(0x01);
cmdlcd(0xc0);
displcd(d3+0x30);
displcd(d2+0x30);
displcd(d1+0x30);
}
void initlcd()
{
cmdlcd(0x38);
cmdlcd(0x0e);
cmdlcd(0x01);
cmdlcd(0x06);
cmdlcd(0x80);
}
void writelcd(unsigned char c)
{
lcd=c;
rw=0;
en=1;
delay(1);
en=0;
}
void cmdlcd(unsigned char c)
{
rs=0;
writelcd(c);
}
void displcd(unsigned char c)
{
rs=1;
writelcd(c);
}
void strlcd(unsigned char *s)
{
while(*s)
{
displcd(*s++);
}
}
delay(unsigned int x)
{
unsigned int i,j;
for(;x>0;x--)
for(i=0;i<244;i++)
for(j=0;j<244;j++);
}
No comments:
Post a Comment