clock so we have made display time on LCD digitally. the clock is configured in 12 mode through programming using.the 16*2 lcd module is interfaced with 8051 micro-controller.
Proteus design
connection is almost similar to to lcd interfacing. port P2 is used as data input port which is connected to data pins of lcd.P3^0, P3^1 and P3^2 pins of micro-controller are connected to control pins RS, RW and EN of LCD. here we only need to do is made a little extra code apart from code that we had constructed earlier in LCD INTERFACING.
CODE
using a delay() function to produce exact delay of one sec. time is represented in hr/min/sec format. which needs to be converted into ASCII format by adding 48 to number before transfering it to lcd module. so another function convert(); has been created according to need of programming
complete code
#include<reg51.h>
#define lcdport P2
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^2;
void lcdcmd(char);
void lcdint();
void lcddata(char);
void lcdstring(char *);
void delay(unsigned int);
void convert(unsigned int);
int hr,min,sec;
void main()
{
int hr1=0,min1=0;
lcdport=0x00;
lcdint();
delay(500);
lcdcmd(0x85);
lcdstring("CLOCK");
while(1)
{
for(hr=hr1;hr<12;hr++)
{
for(min=min1;min1<60;min++)
{
for(sec=0;sec<60;sec++)
{
lcdcmd(0xc4);
convert(hr);
lcddata(':');
convert(min);
lcddata(':');
convert(sec);
lcdcmd(0xc2);
delay(50000); // one second delay
}
}
min1=0;
}
hr1=0;
}
}
void convert(unsigned int k)
{
int digit;
digit=(k/10);
lcddata(digit+48);
digit=(k%10);
lcddata(digit+48);
}
void delay(unsigned int x)
{
unsigned int i;
for(i=0;i<x;i++);
}
void lcdint()
{
lcdcmd(0x38);
delay(500);
lcdcmd(0x01);
delay(500);
lcdcmd(0x0c);
delay(500);
lcdcmd(0x80);
delay(500);
lcdcmd(0x0e);
delay(500);
}
void lcdcmd(char value)
{
lcdport = value;
rw=0;
rs=0;
en=1;
delay(500);
en=0;
}
void lcdstring(char *p)
{
while(*p!='\0')
{
lcddata(*p);
delay(2000);
p++;
}
}
void lcddata(char value)
{
lcdport = value;
rs=1;
rw=0;
en=1;
delay(500);
en=0;
}
VIDEO
Category: