1) digital_clock.c
#include<reg51.h>
#include<string.h>
#include "lcd.h"
/*Digital Clock Without RTC on SSD using Arduino
or using a microcontroller(8051, PIC, ARM)
*/
/*
8051 Micro controller
LCD 16X2
*/
int seconds(int c)
{
while(c>0)
{
TMOD=0X01;// Timer zero mode 1
TH0=0XFC;
TL0=0X62;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
c--;
}
return 1;
}
char * convert_to_string(int n)
{
char str[]="00",i=0;
int a=n;
while(a>0)
{
int r=a%10;
a=a/10;
str[1-i]=r+48;
i++;
}
return str;
}
void main()
{
int ovrflow=0,counter=0,minutes=-1,hour=-1,flg=0;
char str[]="00",str1[]="00",str2[]="00";
lcd_init();
lcd_disp("Digital Clock");
lcd_command(0XC0);
while(1)
{
ovrflow=seconds(1000);
strcpy(str,convert_to_string(counter));
if(counter==0) minutes=(minutes+1)%60;
if(minutes==0 && counter==0) hour=(hour+1)%60;
counter=(counter+1)%60;
strcpy(str1,convert_to_string(minutes));
strcpy(str2,convert_to_string(hour));
lcd_command(0XC0);
lcd_disp(str2);
lcd_command(0XC2);
lcd_disp(":");
lcd_command(0XC3);
lcd_disp(str1);
lcd_command(0XC5);
lcd_disp(":");
lcd_command(0XC6);
lcd_disp(str);
}
}
#include<string.h>
#include "lcd.h"
/*Digital Clock Without RTC on SSD using Arduino
or using a microcontroller(8051, PIC, ARM)
*/
/*
8051 Micro controller
LCD 16X2
*/
int seconds(int c)
{
while(c>0)
{
TMOD=0X01;// Timer zero mode 1
TH0=0XFC;
TL0=0X62;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
c--;
}
return 1;
}
char * convert_to_string(int n)
{
char str[]="00",i=0;
int a=n;
while(a>0)
{
int r=a%10;
a=a/10;
str[1-i]=r+48;
i++;
}
return str;
}
void main()
{
int ovrflow=0,counter=0,minutes=-1,hour=-1,flg=0;
char str[]="00",str1[]="00",str2[]="00";
lcd_init();
lcd_disp("Digital Clock");
lcd_command(0XC0);
while(1)
{
ovrflow=seconds(1000);
strcpy(str,convert_to_string(counter));
if(counter==0) minutes=(minutes+1)%60;
if(minutes==0 && counter==0) hour=(hour+1)%60;
counter=(counter+1)%60;
strcpy(str1,convert_to_string(minutes));
strcpy(str2,convert_to_string(hour));
lcd_command(0XC0);
lcd_disp(str2);
lcd_command(0XC2);
lcd_disp(":");
lcd_command(0XC3);
lcd_disp(str1);
lcd_command(0XC5);
lcd_disp(":");
lcd_command(0XC6);
lcd_disp(str);
}
}
No comments:
Post a Comment