0% found this document useful (0 votes)
93 views

Program For Alarm Clock

This program is for a serial real time clock with an alarm function. It uses I2C communication to set the time on the real time clock by writing the hour, minute and second values. It also reads the current time from the real time clock by reading the hour, minute and second registers. The program then continuously checks the current time and compares it to a set alarm time, outputting an "ALARM SET!!!" message if the current time matches the alarm time.

Uploaded by

Vijay Gurusamy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

Program For Alarm Clock

This program is for a serial real time clock with an alarm function. It uses I2C communication to set the time on the real time clock by writing the hour, minute and second values. It also reads the current time from the real time clock by reading the hour, minute and second registers. The program then continuously checks the current time and compares it to a set alarm time, outputting an "ALARM SET!!!" message if the current time matches the alarm time.

Uploaded by

Vijay Gurusamy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM FOR ALARM CLOCK

//This Program is for Serial Real time Clock with alarm


//SCL - RC3
//SDA - RC4
//DEVICE ADDRESS - 0XA0 - 0XA1
#include <16F877A.H>
#use delay(clock=20000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
#use I2C(MASTER,sda=PIN_C4,scl=PIN_C3)
unsigned int time[]={0x30,0x55,0x12};
unsigned int readtime[0x03];
unsigned long int hour,second,minute;
int i,j;
void set_rtc_time()
{
for (i=2;i<=4;i++)
{
i2c_start();
i2c_write(0xa0 | 0x00);
i2c_write(i);
i2c_write(time[(i-2)]);
i2c_stop();
}
}
void get_rtc_time()
{
for (i=2;i<=4;i++)
{
i2c_start();
i2c_write(0xa0);
i2c_write(i);
i2c_start();
i2c_write(0xa0 | 0x01);
readtime[(i-2)]=i2c_read(0);
i2c_stop();
}
}
void alarm_set()
{
output_b(0xff);
if(minute==0x57)
{
if((second>=0x10)&&(second<=0x14))
{
printf("\n");
printf("ALARM SET!!!");

}
}
}
void main()
{
set_rtc_time();
while(1)
{
get_rtc_time();
hour = readtime[2];
minute= readtime[1];
second=readtime[0];
printf(" Time : %x : %x : %x \n\r",readtime[2],readtime[1],readtime[0]);
alarm_set();
}
}

You might also like