I really like your idea on suggestion #2, but frankly i'm still a newbie on using interrupts just the same. Hi sadat007, many thanks for your immediate response. I hope that the code works with the following changes: Return(temp + (temp > 2) + (bcd_value & 0x0f)) Now return: (Tens * 8) + (Tens * 2) + Ones Shifting upper digit right by 1 is same as multiplying by 8. Get the tens digit by doing multiple subtractionĮlse // Get the ones digit by adding the remainder. Void ds1307_get_time(BYTE &hr, BYTE &min, BYTE &sec) Void ds1307_get_date(BYTE &day, BYTE &mth, BYTE &year, BYTE &dow) I2c_write(0x80) // REG 7 - Disable squarewave output pin I2c_write(0x00) // Start at REG 0 - Seconds Void ds1307_set_date_time(BYTE day, BYTE mth, BYTE year, BYTE dow, BYTE hr, BYTE min, BYTE sec) I2c_write(0x80) // Disable squarewave output pin I2c_write(bin2bcd(seconds)) // Start oscillator with current "seconds value Seconds = bcd2bin(i2c_read(0)) // Read current "seconds" in DS1307 #use i2c(master, sda=RTC_SDA, scl=RTC_SCL) / ds1307_get_date(day,mth,year,dow) Get the date /// / ds1307_set_date_time(day,mth,year,dow,hour,min,sec) Set the date/time /// / used when PIC loses power and DS1307 run from 3V BAT /// / ds1307_init() - Enable oscillator without clearing the seconds register -///
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |