RTC - To Write Some Initial Value To The Clock and Read Back
RTC - To Write Some Initial Value To The Clock and Read Back
back
Source Code :
#include<reg52.h>
#define NO_ACK 0
unsigned int j;
void start(void);
void stop(void);
bit in;
while(del--)
void start(void)
SDA = 1;
SCL = 1;
delay(100);
SDA = 0;
SCL = 0;
void stop(void)
{
SDA = 0;
SCL = 1;
delay(100);
SDA = 1;
SCL = 0;
bit ack = 0;
SDA = 1;
else
SDA = 0;
SCL = 1;
SCL = 0;
SDA = 1;
SCL = 1;
ack = SDA;
SCL = 0;
return(ack);
SCL = 1;
temp <<= 1;
if(SDA)
temp |= 0x01;
SCL = 0;
if(ack)
SDA = 0;
SCL = 1;
delay(100);
SCL = 0;
SDA = 1;
else
{
SDA = 1;
SCL = 1;
SCL = 0;
//P2 = 8;
return(temp);
buzz = 1;
SCL = 0;
start();
if(!(write(RTC_WRITE))) {
if(!write(CONTROL_REG)) {
if(!write(RTC_OFF)) {
start();
if(!write(RTC_WRITE)) {
if(!write(SECONDS_REG)) {
if(!(write(SECONDS_VAL))) {
start();
if(!write(RTC_WRITE)) {
if(!write(CONTROL_REG))
{
if(!write(RTC_ON))
P1 = 0x00;
stop();
while(1) {
start();
if(!write(RTC_WRITE)) {
if(!write(SECONDS_REG)) {
start();
if(!write(RTC_READ)) {
val = read(NO_ACK);
P1 = 0x01;
}
}
stop();
P2 = val ;
Output : A value is written into location 0x02 of the RTC and is read back and
the Control Register (0x00), the RTC is on. Therefore the value read
back and the value written in will differ by a small margin, as the clock
is running.