I am using a rtcc that uses the first 6 bits in the register to counts the hours in bcd. I need to convert to from bcd to binary to display on the lcd, and from binary to bcd to set the time. How do I do this?
Wish I could help, but I am still married to Assembly and the enhanced mid-range group.
There are several algorithms for doing BCD to binary and back. PICList.com may have some in C; although, it is oriented to Assembly. Wikipedia has a pretty good description of the algorithms, if you want to roll your own, but I suspect you will find far more efficient approaches here or on Google.
I am trying to implement the above code. I am reading from the rtcc over i2c in to Time[0] convert from bcd to dec and then into hh to be displayed on the lcd but all the ways I know to do it I get an error.
Nigel... No need! You have ASM code for software I2C and I have done the C variant..
I have written my own I2C functions, but I do the whole thing as a one... ie.. The readclock(); writeclock(); functions take character pointers and do the BCD2BIN and visa~versa all in one...