robosang WROTE:You are learning or we are learning ? You are simply copying the code and use it without studying it.
ONG WEI GIAP WROTE:i have compile the PIC16F876A, the source code i used is from the website itself.. everythings is well function, but it is in 24hrs mode.. it only display time and date. how can i change it to 12hrs with AM/PM indicator and display date and day?
// SET HOUR ===========================================================
while(sw0==1) //infinity loop if switch0 is not pressed
{
if(sw1==1) //if switch 1 is not pressed
{
lcd_goto(0); //maintain current hour value on LCD and make it blinking
send_dec(clkhrs,2);
delay(10000);
lcd_goto(1);
send_char(' ');
lcd_goto(0);
send_char(' ');
delay(10000);
}
if(sw1==0) //if switch 1 is pressed
{
while(sw1==0)continue; //wait switch1 to depress
if(clkhrs<=22)clkhrs++;
else clkhrs=0;
}
}
lcd_goto(0); //overwrite changed hour value on LCD
send_dec(clkhrs,2);
while(sw0==0)continue; //wait switch 0 to be depressed
void i2c_rtc_set_hours(unsigned char uc_value)
{
// The current value of the DS1307 RTC register.
unsigned char uc_current_register_value;
// Make sure the value is < 24 hours.
if (uc_value < 24) {
// Change the value into BCD.
uc_value = ((uc_value / 10) << 4) + (uc_value % 10);
// Read back the current value of register "Hours".
uc_current_register_value = uc_i2c_read(RTC_ADDRESS, 0x02);
[b]// We only interested in the 12-hour/24-hour mode bit, mask out the others.
uc_current_register_value &= 0x40;
[/b]
// Write to the I2C RTC.
uc_i2c_write(RTC_ADDRESS, 0x02, uc_current_register_value | uc_value);
}
}
Users browsing this forum: No registered users and 12 guests