car parking monitoring system
hi...rushikesh
the schematic is on the same lines as shown in the attachment.
however the microcontroller for interfacing the lcd is as follows
#include <reg52.h>
#include <lcd.h>
#include<math.h>
#include<stdio.h>
sbit rs=0xa0; /*P2.0 LCD RS pin #21*/
sbit rw=0xa1; /*P2.1 LCD R/W pin #22*/
sbit en=0xa4; /*P2.4 LCD E pin #25*/
sfr lcdbus=0x80; /*p0 LCD data bus D0=P0.0*/
unsigned int sys10mscounter;
unsigned char syslimitcounter;
// Self define font
char path1[8]={0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f}; // Horizontal 1
char path2[8]={0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00}; // Horizontal 2
char pats1[8]={0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15}; // Vertical 1
char pats2[8]={0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; // Vertical 2
void soft_nop(){}
void soft_10ms() // 12MHZ 10MS software delay
{ register int i;
for(i=0;i<711;i++);
}
void soft_20ms() // 12MHZ 20MS software delay
{ soft_10ms();
soft_10ms();
}
void hard_10ms(unsigned int delaytime) // delaytime*10MS hardware delay
{ sys10mscounter=delaytime;
while(sys10mscounter);
}
unsigned char data lcdcounter;
bit lcdusing1,lcdusing2;
bit lcd_checkbusy() // is LCD busy?
{register lcdstate;
rs=0; // dc=1 -> data, =0 -> command
rw=1; // rw=1 -> read, =0 -> write
en=1; // cs=1 -> selected
soft_nop();
lcdstate=lcdbus;
en=0;
return((bit)(lcdstate&0x80));
}
void lcd_wrcmd(unsigned char lcdcmd) // write a character to LCD
{ lcdusing1=1;
while(lcd_checkbusy());
lcdbus=lcdcmd;
rs=0; // dc=1 -> data, =0 -> command
rw=0; // rw=1 -> read, =0 -> write
en=1; // cs=1 -> selected
soft_nop();
en=0;
lcdbus=0xff;
lcdusing1=0;
}
void lcd_moveto(char position) // move cursor to position 0-79
{register cmd=0x80;
lcdcounter=position;
if (position > 59)
position += 0x18;
else
{ if (position > 39) position -= 0x14;
else
{ if (position > 19) position += 0x2c;
}
}
cmd = cmd | position;
lcd_wrcmd(cmd);
}
void lcd_wrdata(char lcddata) // at surrent cursor write a character
{unsigned char i;
lcdusing2=1;
while(lcd_checkbusy());
if (lcdcounter==20){
lcd_moveto(20);
while(lcd_checkbusy());
}
if (lcdcounter==40){
lcd_moveto(40);
while(lcd_checkbusy());
}
if (lcdcounter==60){
lcd_moveto(60);
while(lcd_checkbusy());
}
if (lcdcounter==80){
lcd_moveto(0);
while(lcd_checkbusy());
lcdcounter=0;
}
lcdcounter++;
lcdbus=lcddata;
rs=1; // dc=1 -> data, =0 -> command
rw=0; // rw=1 -> read, =0 -> write
en=1; // cs=1 -> selected
soft_nop();
en=0;
lcdbus=0xff;
lcdusing2=0;
}
void lcd_string(char *strpoint) // at current cursor write a string
{register i=0;
while(strpoint!=0){
lcd_wrdata(strpoint);
i++;}
}
void lcd_init() //initialize LCD
{
lcd_wrcmd(0x38); //8 bit data bus
lcd_wrcmd(0x0c); //block cursor,non blink
lcd_wrcmd(0x06); //don't move after display
lcd_wrcmd(0x01); //Clear display
lcdcounter=0;
}
void lcd_cls() // clear LCD
{
lcd_wrcmd(0x01);
lcdcounter=0;
}
void timer0(void) interrupt 1 // T0 interrupt service routine
{
TH0=0xd8; /*12M,10ms*/
TL0=0xf6;
TR0=1;
if(sys10mscounter !=0)sys10mscounter--; // 10ms timer
if(syslimitcounter!=0)syslimitcounter--; // 10ms timer
}
main()
{unsigned char j;
IE=0;P0=0xff;P1=0xff;P2=0xff;P3=0xff; // Initialize
lcd_init(); soft_20ms();
TMOD=0x51;
TH0=0xd8; /*12M,10ms*/
TL0=0xf6;
TR0=1;ET0=1;EA=1;
while(1)
{
// Display :
// All black; horizontal 1; horizontal 2; vertical 1; vertical 2
// UUUUUU...., QQQQQQQ.... ABCD...
lcd_init(); // all black
for(j=0;j<80;j++){lcd_wrdata(0xff);}
hard_10ms(50);
lcd_init(); // Horizontal 1 -> check font definition
lcd_wrcmd(0x40);
for(j=0;j<8;j++)lcd_wrdata(path1[j]);
for(j=0;j<100;j++)lcd_wrdata(0);
hard_10ms(50);
lcd_init(); // Horizontal 2
lcd_wrcmd(0x40);
for(j=0;j<8;j++)lcd_wrdata(path2[j]);
for(j=0;j<100;j++)lcd_wrdata(0);
hard_10ms(50);
lcd_init(); // Vertical 1
lcd_wrcmd(0x40);
for(j=0;j<8;j++)lcd_wrdata(pats1[j]);
for(j=0;j<100;j++)lcd_wrdata(0);
hard_10ms(50);
lcd_init(); // Vertical 2
lcd_wrcmd(0x40);
for(j=0;j<8;j++)lcd_wrdata(pats2[j]);
for(j=0;j<100;j++)lcd_wrdata(0);
hard_10ms(50);
lcd_init();
lcd_string("WELCOME WELCOME WELCOME
WEL
COMEWELCOMEWELCOMEWELCOMEWELCOME ");
hard_10ms(50);
lcd_init();
lcd_string("QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ");
hard_10ms(50);
lcd_init();
lcd_string("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123456789+-!#$%&?");
hard_10ms(50);
}
}