//Embeded C program ( keil Program)
// 8051 Microcontroller
/*This Program is made to display Characters on LCD screen typed From PC Keyboard --interfaced with 8051 */
#include <reg51.h>
#include <string.h>
sbit rw=P2^0; //read write pin
sbit rs=P2^1; // data/command pin
sbit en=P2^2; // declare p2.2 as read/write pin
sbit b = P1^7; // busy flag
unsigned char card[12];
void writecmd(unsigned char a); // function to send command to LCD
void writedat(unsigned char b); // function to send data to LCD
void busy(); // function to check LCD is busy or not
void writestr(unsigned char *s); // function to write string on LCD
void writecmd(unsigned char a)
{
busy(); // check for LCD is busy or not
rs = 0; // clear rs pin for command
rw = 0; // clear rw pin to write
P1 = a; // send command character
en = 1; // strob LCD
en = 0;
}
void writedat(unsigned char b)
{
busy(); // check for LCD is busy or not
rs = 1; // set rs pin for data
rw = 0; // clear rw pin to write
P1 = b; // send data character
en = 1; // strob LCD
en = 0;
}
void busy()
{
en = 0; // disable display
P1 = 0xFF; // configur P0 as input
rs = 0; // clear rs pin for command
rw = 1; // set rw pin to read
while(b==1)
{
en=0; // strob LCD till P1.7 is 1
en=1;
}
en=0;
}
void writestr(unsigned char *s)
{
unsigned char l,i;
l = strlen(s); // get the length of string
for(i=1;i<=l;i++)
{
writedat(*s); // write every char one by one
s++;
}
}
main()
{
P0=0x00; // P0 and P2 as output ports
P2=0x00;
TMOD=0x20; //Enable Timer 1
TH1=0XFD;
SCON=0x50;
TR1=1;
writecmd(0x3C); // initialize LCD
writecmd(0x0E);
writecmd(0x01); // clear memory and home cursor
while(1)
{
while(RI==0);
card[0]=SBUF;
RI=0;
writestr(card);
}
}
THANK YOU FOR VISITING..!!
PLEASE COMMENT
// 8051 Microcontroller
/*This Program is made to display Characters on LCD screen typed From PC Keyboard --interfaced with 8051 */
#include <reg51.h>
#include <string.h>
sbit rw=P2^0; //read write pin
sbit rs=P2^1; // data/command pin
sbit en=P2^2; // declare p2.2 as read/write pin
sbit b = P1^7; // busy flag
unsigned char card[12];
void writecmd(unsigned char a); // function to send command to LCD
void writedat(unsigned char b); // function to send data to LCD
void busy(); // function to check LCD is busy or not
void writestr(unsigned char *s); // function to write string on LCD
void writecmd(unsigned char a)
{
busy(); // check for LCD is busy or not
rs = 0; // clear rs pin for command
rw = 0; // clear rw pin to write
P1 = a; // send command character
en = 1; // strob LCD
en = 0;
}
void writedat(unsigned char b)
{
busy(); // check for LCD is busy or not
rs = 1; // set rs pin for data
rw = 0; // clear rw pin to write
P1 = b; // send data character
en = 1; // strob LCD
en = 0;
}
void busy()
{
en = 0; // disable display
P1 = 0xFF; // configur P0 as input
rs = 0; // clear rs pin for command
rw = 1; // set rw pin to read
while(b==1)
{
en=0; // strob LCD till P1.7 is 1
en=1;
}
en=0;
}
void writestr(unsigned char *s)
{
unsigned char l,i;
l = strlen(s); // get the length of string
for(i=1;i<=l;i++)
{
writedat(*s); // write every char one by one
s++;
}
}
main()
{
P0=0x00; // P0 and P2 as output ports
P2=0x00;
TMOD=0x20; //Enable Timer 1
TH1=0XFD;
SCON=0x50;
TR1=1;
writecmd(0x3C); // initialize LCD
writecmd(0x0E);
writecmd(0x01); // clear memory and home cursor
while(1)
{
while(RI==0);
card[0]=SBUF;
RI=0;
writestr(card);
}
}
THANK YOU FOR VISITING..!!
PLEASE COMMENT
No comments:
Post a Comment