Wednesday, June 6, 2012

Simplest logic for Time Display on LCD using 8051

/* here time starts from 0 seconds, you can add logic to set the time

not clear den try to make it clear or comment here */


#include reg51.h #include "lcd_display4bit.h" //for header check this void printTime(); long timerCount=; short int count=0; sbit getTime=P1^2; void CountSeconds() interrupt 1 {
EA=0; count++; if(count==15) { count=0; (timerCount<86400) ? (timerCount++) : (timerCount=0); } EA=1; TF0=0; TR0=1; }


void main() { P2=0x00; getTime=1; rs=en=0; lcd_init(); EA=1; ET0=1; TMOD=0x01; TR0=1; while(1) { if(getTime==0) printTime(); } } void printTime() { long hrs=0, mins=0, secs=0; hrs= timerCount/3600; mins=(timerCount-hrs*60*60)/60; secs=(timerCount-hrs*60*60-mins*60); lcd_cmd(0x80); lcd_dataS("Time is:"); lcd_cmd(0xc0); lcd_data_int(hrs); lcd_data(':'); lcd_data_int(mins); lcd_data(':'); lcd_data_int(secs); }

No comments:

Post a Comment