//program to display the data on the lcd.
#include<reg51.h>
#include"delay.h"
#define lcd_data P2
sbit rs=P3^5;
sbit rw=P3^6;
sbit en=P3^7;
//function prototypes.......
void write_lcd(char);
void cmd_lcd(char);
void putc_lcd(char);
void init_lcd(void);
void puts_lcd(char*);
void putf_lcd(float);
void puti_lcd(unsigned int);
//function definitions
void init_lcd()
{
cmd_lcd(0x02);
cmd_lcd(0x38);
cmd_lcd(0x01);
cmd_lcd(0x0f);
cmd_lcd(0x06);
cmd_lcd(0x80);
}
void cmd_lcd(unsigned char cmd)
{
rs=0;
write_lcd(cmd);
}
void putc_lcd(char c)
{
rs=1;
write_lcd(c);
}
void write_lcd(char dat)
{
lcd_data=dat;
rw=0;
en=1;
en=0;
delay_ms(2);
}
//function for strings
void puts_lcd(char *s)
{
while(*s)
{
putc_lcd(*s++);
}
}
//function for integer values
void puti_lcd(unsigned int n)
{
char a[5]=0,i=0;
if(n==0)
{
putc_lcd('0');
return;
}
else
{
while(n>0)
{
a[i++]=(n%10)+48;
n=n/10;
}
for(--i;i>=0;i--)
{
putc_lcd(a[i]);
}
}
}
//function for float values
void putf_lcd(float f)
{
int i;
unsigned char j;
i=f;
puti_lcd(i);
putc_lcd(' ');
for(j=0;j<3;j++)
{
f=(f-i)*10;
i=f;
puti_lcd(i);
}
}
void main()
{
init_lvd();
cmd_lcd(0x01);
putc_lcd('V');
delay_ms(20);
cmd_lcd(0x01);
puts_lcd(" VENKY NAIDU");
delay_ms(20);
while(1);
}
No comments:
Post a Comment