Wednesday, September 24, 2008

CLOCK program in c programming language

Description:
to find out the clock
Program
#include

#include
#include
#include

#include "i2c.h"
#include "lcd.h"

idata char g_strSetting[20] ;

unsigned char day, mon, year ;
unsigned char hh,mm,ss ;
unsigned char g_byLastSec ;

unsigned int iday, imon, iyear ;
unsigned int ihh,imm,iss ;

void main ()
{
/*
// initialize serial port
// 19200 baud assuming P89C51RD2 @ 12 MHz
RCAP2H = 0xff ;
RCAP2L = 0xd9 ;
T2CON = 0x34 ;
SCON = 0x70 ;
*/
TH1 = 0xfd ;
TL1 = 0xfd ;
PCON |= 0x80 ;
SCON = 0x70 ;
TMOD = 0x21 ;
TCON = 0x50 ;


lcd_init() ;
printf("Clock program for Mini51\n") ;
display_row(0,"CLOCK on Mini51") ;
if (RI)
{
// send CR during reset, to goto clock set mode
getchare() ;
while(1)
{
printf("\nEnter data and time in dd mm yy hh mm ss format\n") ;
scanf("%x%x%x%x%x%x",&iday,&imon,&iyear,&ihh,&imm,&iss) ;
day = iday ;
mon = imon ;
year = iyear ;
hh = ihh ;
mm = imm ;
ss = iss ;
printf("You entered:\n%02bx-%02bx-%02bx %02bx:%02bx:%02bx\n",day,mon,year,hh,mm,ss) ;
printf("Press Y to store these values to RTC, any other to discard\n") ;
if (getchare() == 'Y')
{
write_rtc_byte(DAY_ADDR,day) ;
write_rtc_byte(MONTH_ADDR,mon) ;
write_rtc_byte(YEAR_ADDR,year) ;
write_rtc_byte(HOURS_ADDR,hh) ;
write_rtc_byte(MINUTES_ADDR,mm) ;
write_rtc_byte(SECONDS_ADDR,ss) ;
break ;
}
}
}
g_byLastSec = 0xff ;
while(1)
{
day = read_rtc_byte(DAY_ADDR) ;
mon = read_rtc_byte(MONTH_ADDR) ;
year = read_rtc_byte(YEAR_ADDR) ;
hh = read_rtc_byte(HOURS_ADDR) ;
mm = read_rtc_byte(MINUTES_ADDR) ;
ss = read_rtc_byte(SECONDS_ADDR) ;
if (ss != g_byLastSec)
{
sprintf(g_strSetting,"%02bx-%02bx %02bx:%02bx:%02bx",day,mon,hh,mm,ss) ;
display_row(1,g_strSetting) ;
//printf("%s\n",g_strSetting) ;
printf("%02bx-%02bx-%02bx %02bx:%02bx:%02bx\n",day,mon,year,hh,mm,ss) ;
g_byLastSec = ss ;
}
}
}

No comments:

Post a Comment

Thanks to given comments.......

My Blog List