/************************************************
* PIN descriptions
***********************************************
* Hardware : Controller -> AT89C52
* XTAL -> 11.0592 MHz
* I/O : SCL -> P2^6;
* SDA -> P2^7;
* RS -> P2.5
* Enable -> P2.4
* Data4567 -> P2.0,P2.1,P2.2,P2.3
* settime -> P1^0;
* hour_pin -> P1^1;
* min_pin -> P1^2;
* Compiler : KEIL uVision 4.22
* Date : 27/11/2011
*/
#include<at89x52.h>
#include<stdio.h>
#include<ds1307.c>
#include<lcd.c>
sbit settime = P1^0;
sbit hour_pin =P1^1;
sbit min_pin = P1^2;
unsigned char RTC_ARR[7]; /* Buffer for second,minute,.....,year */
unsigned int j, p;
unsigned char hour_update = 0, min_update = 0;
void set_hour()
{
while(hour_pin==1);
hour_update++;
if(hour_update>23)
hour_update=0;
LCD_command(0x80);
sendno2lcd(hour_update);
LCD_putc(':');
}
void set_min()
{
while(min_pin==1);
min_update++;
if(min_update>59)
min_update=0;
LCD_command(0x83);
sendno2lcd(min_update);
}
void display_time()
{
LCD_row1(); LCD_puts("Date:");
LCD_row2(); LCD_puts("Time:");
/* Show Date in format dd/mm/yr */
LCD_command(0x86); /* Set LCD cursor at (1,6) */
send2lcd(RTC_ARR[4]); /* Show date on LCD */
LCD_putc('/');
send2lcd(RTC_ARR[5]); /* Show month on LCD */
LCD_putc('/');
send2lcd(RTC_ARR[6]); /* Show year on LCD */
/* Show Time in format hr:min:sec */
LCD_command(0xC6); /* Set LCD cursor at (2,6) */
send2lcd(RTC_ARR[2]); /* Show hour on LCD */
LCD_putc(':');
send2lcd(RTC_ARR[1]); /* Show min on LCD */
LCD_putc(':');
send2lcd(RTC_ARR[0]); /* Show sec on LCD */
}
/***************************** Main function *************************************/
void main()
{
P0 = 0; P1 = 0;
PowerOn(); /*Initialize LCD */
LCD_row1(); LCD_puts("Date:");
LCD_row2(); LCD_puts("Time:");
/* Setup time and enable oscillator */
ReadRTC(&RTC_ARR[0]);
RTC_ARR[0] = RTC_ARR[0] & 0x7F; /* enable oscillator (bit 7=0) */
RTC_ARR[1] = 0x59; /* minute = 59 */
RTC_ARR[2] = 0x11; /* hour = 11 ,24-hour mode(bit 6=0) */
RTC_ARR[3] = 0x04; /* Day = 1 or sunday */
RTC_ARR[4] = 0x23; /* Date = 23 */
RTC_ARR[5] = 0x11; /* month = November */
RTC_ARR[6] = 0x11; /* year = 2011 */
WriteRTC(&RTC_ARR[0]); /* Set RTC */
while(1)
{
ReadRTC(&RTC_ARR[0]);
display_time();
if(settime==1)
{
for(p=0;p=10;p++); //debounce check
if(settime==1)
{
LCD_clear();
LCD_puts("Time set");
for(j=0;j<1000;j++);
if(hour_pin==1)
set_hour();
if(min_pin==1)
set_min();
}
LCD_clear();
}
if(RTC_ARR[2]==hour_update)
{
if(RTC_ARR[1]==min_update)
{
LCD_clear();
LCD_puts("Alarm");
}
}
}
}
/************************************************
* PIN descriptions
***********************************************
* Hardware : Controller -> AT89C52
* XTAL -> 11.0592 MHz
* I/O : SCL -> P2^6;
* SDA -> P2^7;
* RS -> P2.5
* Enable -> P2.4
* Data4567 -> P2.0,P2.1,P2.2,P2.3
* Serial port -> P3^1;
* Compiler : KEIL uVision 4.22
*/
#include<at89x52.h>
#include<stdio.h>
#include<ds1307.c>
#include<lcd.c>
sbit led = P3^5;
sbit set_time = P1^0;
sbit hour_pin =P1^1;
sbit min_pin = P1^2;
unsigned char RTC_ARR[7]; /* Buffer for second,minute,.....,year */
unsigned int j, p;
unsigned char hour_update = 0, min_update = 0;
void set_hour()
{
while(hour_pin==0);
hour_update++;
if(hour_update>23)
hour_update=0;
LCD_command(0x80);
sendno2lcd(hour_update);
LCD_putc(':');
}
void set_min()
{
while(min_pin==0);
min_update++;
if(min_update>59)
min_update=0;
LCD_command(0x83);
sendno2lcd(min_update);
}
void settime() interrupt 2
{
unsigned int i,j;
LCD_clear();
if(set_time == 0)
{
LCD_puts("Set time");
for(j=0;j<=1000;j++);
LCD_clear();
sendno2lcd(hour_update);
LCD_putc(':');
sendno2lcd(min_update);
while(set_time==0)
{
for(i=0;i<10;i++);
if(hour_pin==0)
set_hour();
if(min_pin==0)
set_min();
}
}
else
{
LCD_puts("Exit");
LCD_clear();
}
}
void display_time()
{
LCD_row1(); LCD_puts("Date:");
LCD_row2(); LCD_puts("Time:");
/* Show Date in format dd/mm/yr */
LCD_command(0x86); /* Set LCD cursor at (1,6) */
send2lcd(RTC_ARR[4]); /* Show date on LCD */
LCD_putc('/');
send2lcd(RTC_ARR[5]); /* Show month on LCD */
LCD_putc('/');
send2lcd(RTC_ARR[6]); /* Show year on LCD */
/* Show Time in format hr:min:sec */
LCD_command(0xC6); /* Set LCD cursor at (2,6) */
send2lcd(RTC_ARR[2]); /* Show hour on LCD */
LCD_putc(':');
send2lcd(RTC_ARR[1]); /* Show min on LCD */
LCD_putc(':');
send2lcd(RTC_ARR[0]); /* Show sec on LCD */
}
/***************************** Main function *************************************/
void main(void)
{
// P0 = 0; P1 = 1;
PowerOn(); /*Initialize LCD */
IE = 0x84; /* Enable INT1 */
LCD_row1(); LCD_puts("Date:");
LCD_row2(); LCD_puts("Time:");
/* Setup time and enable oscillator */
ReadRTC(&RTC_ARR[0]);
RTC_ARR[0] = RTC_ARR[0] & 0x7F; /* enable oscillator (bit 7=0) */
RTC_ARR[1] = 0x59; /* minute = 59 */
RTC_ARR[2] = 0x11; /* hour = 11 ,24-hour mode(bit 6=0) */
RTC_ARR[3] = 0x04; /* Day = 1 or sunday */
RTC_ARR[4] = 0x23; /* Date = 23 */
RTC_ARR[5] = 0x11; /* month = November */
RTC_ARR[6] = 0x11; /* year = 2011 */
WriteRTC(&RTC_ARR[0]); /* Set RTC */
while(1)
{
ReadRTC(&RTC_ARR[0]);
display_time();
if(hour_update==RTC_ARR[2])
{
if(min_update==RTC_ARR[1])
{
LCD_clear();
LCD_puts("Alarm");
led=0;
}
LCD_clear();
}
}
}
/************************************************
* PIN descriptions
***********************************************
* Hardware : Controller -> AT89C52
* XTAL -> 11.0592 MHz
* I/O : SCL -> P2^6;
* SDA -> P2^7;
* RS -> P2.5
* Enable -> P2.4
* Data4567 -> P2.0,P2.1,P2.2,P2.3
* Serial port -> P3^1;
* Compiler : KEIL uVision 4.22
* Date : 27/11/2011
* Author : Arun
*/
#include<at89x52.h>
#include<stdio.h>
#include<ds1307.c>
#include<lcd.c>
sbit led = P3^5;
sbit set_time = P1^0;
sbit hour_pin =P1^1;
sbit min_pin = P1^2;
unsigned char RTC_ARR[7]; /* Buffer for second,minute,.....,year */
unsigned int j, p;
unsigned char hour_update = 0, min_update = 0;
void set_hour()
{
while(hour_pin==0);
hour_update++;
if(hour_update>23)
hour_update=0;
LCD_command(0x80);
sendno2lcd(hour_update);
LCD_putc(':');
}
void set_min()
{
while(min_pin==0);
min_update++;
if(min_update>59)
min_update=0;
LCD_command(0x83);
sendno2lcd(min_update);
}
void settime() interrupt 2
{
unsigned int i,j;
LCD_clear();
if(set_time == 0)
{
LCD_puts("Set time");
for(j=0;j<=1000;j++);
LCD_clear();
sendno2lcd(hour_update);
LCD_putc(':');
sendno2lcd(min_update);
while(set_time==0)
{
for(i=0;i<10;i++);
if(hour_pin==0)
set_hour();
if(min_pin==0)
set_min();
}
}
else
{
LCD_puts("Exit");
LCD_clear();
}
}
void display_time()
{
LCD_row1(); LCD_puts("Date:");
LCD_row2(); LCD_puts("Time:");
/* Show Date in format dd/mm/yr */
LCD_command(0x86); /* Set LCD cursor at (1,6) */
send2lcd(RTC_ARR[4]); /* Show date on LCD */
LCD_putc('/');
send2lcd(RTC_ARR[5]); /* Show month on LCD */
LCD_putc('/');
send2lcd(RTC_ARR[6]); /* Show year on LCD */
/* Show Time in format hr:min:sec */
LCD_command(0xC6); /* Set LCD cursor at (2,6) */
send2lcd(RTC_ARR[2]); /* Show hour on LCD */
LCD_putc(':');
send2lcd(RTC_ARR[1]); /* Show min on LCD */
LCD_putc(':');
send2lcd(RTC_ARR[0]); /* Show sec on LCD */
}
/***************************** Main function *************************************/
void main(void)
{
led=0;
PowerOn(); /*Initialize LCD */
IE = 0x84; /* Enable INT1 */
LCD_row1(); LCD_puts("Date:");
LCD_row2(); LCD_puts("Time:");
/* Setup time and enable oscillator */
ReadRTC(&RTC_ARR[0]);
RTC_ARR[0] = RTC_ARR[0] & 0x7F; /* enable oscillator (bit 7=0) */
RTC_ARR[1] = 0x01; /* minute = 59 */
RTC_ARR[2] = 0x10; /* hour = 11 ,24-hour mode(bit 6=0) */
RTC_ARR[3] = 0x04; /* Day = 1 or sunday */
RTC_ARR[4] = 0x23; /* Date = 23 */
RTC_ARR[5] = 0x11; /* month = November */
RTC_ARR[6] = 0x11; /* year = 2011 */
WriteRTC(&RTC_ARR[0]); /* Set RTC */
while(1)
{
ReadRTC(&RTC_ARR[0]);
display_time();
if(BCD2HEX(RTC_ARR[2])==hour_update)
{
if(BCD2HEX(RTC_ARR[1])==min_update)
{
LCD_clear();
LCD_puts("Alarm");
led=1;
for(i=0;i<100;i++)
for(j=0;j<=1000;j++);
}
// LCD_clear();
}
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?