jay_3189
Banned
- Joined
- Sep 19, 2013
- Messages
- 104
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 16
- Location
- Ahmedabad
- Activity points
- 0
I have written code for real time clock to display time in hyper terminal using c in keil IDE.
but I am not getting perfect time in hyper terminal as I have set through function.
my DS1307 Code is as below.
if you want to see my full code then follow the below link.
https://www.edaboard.com/threads/305721/
but I am not getting perfect time in hyper terminal as I have set through function.
my DS1307 Code is as below.
Code:
#define DS1307_ID 0xD0 // DS1307 ID
#define SEC_ADDRESS 0x00 // Address to access Ds1307 SEC register
#define DATE_ADDRESS 0x04 // Address to access Ds1307 DATE register
#define CONTROL 0x07 // Address to access Ds1307 CONTROL register
void main(void)
{
DS1307_Init();
DS1307_SetDate(12, 11, 13);
serial_init();
while(1)
{
DS1307_GetDate(0x04, 0x05, 0x06);//Address to access Date,Month,Year
delay_us(5000);
}
}
/*This function is used to set Date(dd,mm,yy) into the Ds1307 RTC.
Ds1307 ic is enabled by sending the DS1307 id on the I2C bus.
After selecting DS1307, select the RAM address 0x04 to point to day Initilze Day,Month and Year one after the other.
Stop the I2c communication.*/
void DS1307_SetDate(unsigned char DD, unsigned char MM, unsigned char YY)
{
I2C_Start(); // Start I2C communication
WriteI2C(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
WriteI2C(DATE_ADDRESS); // Request DAY RAM address at 04H
DD = dec_to_bcd(DD);
MM = dec_to_bcd(MM);
YY = dec_to_bcd(YY);
WriteI2C(DD); // Write date on RAM address 04H
WriteI2C(MM); // Write month on RAM address 05H
WriteI2C(YY); // Write year on RAM address 06h
I2C_Stop(); // Stop I2C communication after Setting the Date
}
/*This function is used to get the Date(y,m,d) from Ds1307 RTC.
Ds1307 ic is enabled by sending the DS1307 id on the I2C bus.
After selecting DS1307, select the RAM address 0x00 to point to DAY Get Day, Month, Year one after the other.
Stop the I2c communication*/
void DS1307_GetDate(unsigned char *D_ptr,unsigned char *M_ptr,unsigned char *Y_ptr)
{
I2C_Start(); // Start I2C communication
WriteI2C(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
WriteI2C(DATE_ADDRESS); // Request DAY RAM address at 04H
I2C_Stop(); // Stop I2C communication after selecting DAY Register
I2C_Start(); // Start I2C communication
WriteI2C(0xD1); // connect to DS1307( under Read mode) by sending its ID on I2c Bus
*D_ptr = ReadI2C(); SDA=0; SCL=1;
*M_ptr = ReadI2C(); SDA=0; SCL=1;
*Y_ptr = ReadI2C(); SDA=1; SCL=1;
*D_ptr = bcd_to_dec(*D_ptr);
*M_ptr = bcd_to_dec(*M_ptr);
*Y_ptr = bcd_to_dec(*Y_ptr);
printf("Date is in dd/mm/yy = %p/%p/%p\n", *D_ptr, *M_ptr, *Y_ptr);
I2C_Stop(); // Stop I2C communication after readin3g the Time
}
if you want to see my full code then follow the below link.
https://www.edaboard.com/threads/305721/