shanishp
Newbie level 6
hi
my project includes an RTC and LCD. I had read the rtc by i2c protocol and tries to out in an lcd. but iam getting some error
my output is
TIME : 1? : 2? :3?
a question mark is there when i tried to mask my received data from rtc with 0f .e some problems regarding the LSB (4 bits) of received data.
please help me.
the rtc is outing the data in BCD format, shall i need to convert it back into bcd by pic microcontroller
my routine to read the rtc is given below
void read_DS1307(void)
{
i2c_start();
i2c_write(0xd0);
i2c_write(0x00);
i2c_start();
i2c_write(0xd1);
data=i2c_read(1); // * reading seconds
sec=data;
disp[16]=48+((data & 0x70)>>4);
disp[17]=48+(data & 0x0F);
disp[15]=' ';
data=i2c_read(1); // * reading minutes
min=data;
disp[13]=48+((data & 0x70)>>4);
disp[14]=48+(data & 0x0F);
disp[12]=' ';
data=i2c_read(1); // * reading hour
hr=data;
disp[10]=48+((data & 0x30)>>4);
disp[11]=48+(data & 0x0F);
disp[9]=' ';
data=i2c_read(1); // * reading date
dt=data;
disp[7]=48+((data & 0x30)>>4);
disp[8]=48+(data & 0x0F);
disp[6]=' ';
data=i2c_read(1); // * reading month
mnt=data;
disp[4]=48+((data & 0x10)>>4);
disp[5]=48+(data & 0x0F);
disp[3]=' ';
data=i2c_read(0); // * reading year
yr=data;
disp[1]=48+((data & 0xF0)>>4);
disp[2]=48+(data & 0x0F);
disp[0]=' ';
i2c_stop();
}
my project includes an RTC and LCD. I had read the rtc by i2c protocol and tries to out in an lcd. but iam getting some error
my output is
TIME : 1? : 2? :3?
a question mark is there when i tried to mask my received data from rtc with 0f .e some problems regarding the LSB (4 bits) of received data.
please help me.
the rtc is outing the data in BCD format, shall i need to convert it back into bcd by pic microcontroller
my routine to read the rtc is given below
void read_DS1307(void)
{
i2c_start();
i2c_write(0xd0);
i2c_write(0x00);
i2c_start();
i2c_write(0xd1);
data=i2c_read(1); // * reading seconds
sec=data;
disp[16]=48+((data & 0x70)>>4);
disp[17]=48+(data & 0x0F);
disp[15]=' ';
data=i2c_read(1); // * reading minutes
min=data;
disp[13]=48+((data & 0x70)>>4);
disp[14]=48+(data & 0x0F);
disp[12]=' ';
data=i2c_read(1); // * reading hour
hr=data;
disp[10]=48+((data & 0x30)>>4);
disp[11]=48+(data & 0x0F);
disp[9]=' ';
data=i2c_read(1); // * reading date
dt=data;
disp[7]=48+((data & 0x30)>>4);
disp[8]=48+(data & 0x0F);
disp[6]=' ';
data=i2c_read(1); // * reading month
mnt=data;
disp[4]=48+((data & 0x10)>>4);
disp[5]=48+(data & 0x0F);
disp[3]=' ';
data=i2c_read(0); // * reading year
yr=data;
disp[1]=48+((data & 0xF0)>>4);
disp[2]=48+(data & 0x0F);
disp[0]=' ';
i2c_stop();
}