digital watch using 8051 timer

Thread Starter

khangul

Joined Jan 31, 2015
12
Code:
I want to update my LCD after every 1 second delay. how to send values 1,2,3......upto 60  to micro controller and update each and every time after 1 second delay





#include<stdio.h>
#include<reg51.h>

sbit rs= P1^0;
sbit rw= P1^1;
sbit en= P1^2;

void second();
//void mint();
void tdelay();

char lcddat[30]= {"Hour:mint:second"};
char cmd[6]={0x38,0x0E,0x01,0x80};
int tim[30]={"1,2,3,4,5,6,7,8,9,10,11,12,13"};

char i,j; //veriable decleration
int o;
char p=0;
int x=0;
int y=0x30;


void main()
{


rs=0;
rw=0;
en=0;

for (i=0;i<=5;i++)
{
P2=cmd[i]; //lcd initialization
en=1;
tdelay();
en=0;

}


P2=0x80;
en=1;
tdelay();
en=0;

rs=1;
for (j=0;j<=15;j++)// Lcd data
{

P2=lcddat[j];
en=1;
tdelay();
en=0;

}

while(1)
{

do{


rs=0;
P2=0xC0;
y++; 
en=1;
tdelay();
en=0;


rs=1;

second();

P2=tim[x];
en=1;
tdelay();
en=0;
x++;
}
while(x<60);

}
}
void tdelay() // delay of 25ms using 8051 timer
{
  TMOD=0x01;
  TL0=0xFE;
  TH0=0xA5;
  TR0=1;
while (TF0==0);
TR0=0;
TF0=0;
}

void second() // second delay
{
int p;
for (p=0;p<40;p++)
{
tdelay();
}
}
/*void mint()
{
int o;
for (o=0;o<2400;o++){
tdelay();
}
 

spinnaker

Joined Oct 29, 2009
7,830
Your code looks strangely similar to ueb-ners's. Project time again and not paying attention in school?

No one is going to write your program for you. You will need to do that. The first thing you need to do is get something written to the LCD.

You didn't even bother to mention the LCD. Assuming a HDM08216 there are plenty of libraries out there for them. The enclosed is for the Pic but you should be able to adapt the code fairly easily.
 

Attachments

Top