yviswanathbe
Full Member level 4
Hi friends,
I am doing a Digital Clock using RTC DS1307 and 89C4051 micro controller.
Time is displayed on LCD and different alarms can be set through 3 switches.
I have written the following code for updating RTC registers first time. Only minutes code is shown
I have added so many conditions because, when i enter the data from the switches(Increment/decrement), i am storing the value in a integer type. But we need to write BCD value to RTC DS1307. Suppose if i want to update the Minute register with 19, with out the above conditions it is updating as 11.
I hope you all understand my query.
I feel the above code is not efficient, i want to write it with out so many if conditions. Can somebody help me in this regard please?
Thanks and Regards,
Viswanath
I am doing a Digital Clock using RTC DS1307 and 89C4051 micro controller.
Time is displayed on LCD and different alarms can be set through 3 switches.
I have written the following code for updating RTC registers first time. Only minutes code is shown
Code:
//Minutes
min++;
if((min>15)&&(min<20))
{
onmin=min+6;
}
else if((min>=20) &&(min<30))
{
onmin=min+12;
}
else if((min>=30) &&(min<40))
{
onmin=min+18;
}
else if((min>=40) &&(min<50))
{
onmin=min+24;
}
else if((min>=50) &&(min<60))
{
onmin=min+30;
}
else
{
onmin=min;
}
I have added so many conditions because, when i enter the data from the switches(Increment/decrement), i am storing the value in a integer type. But we need to write BCD value to RTC DS1307. Suppose if i want to update the Minute register with 19, with out the above conditions it is updating as 11.
I hope you all understand my query.
I feel the above code is not efficient, i want to write it with out so many if conditions. Can somebody help me in this regard please?
Thanks and Regards,
Viswanath