04-02-2009, 21:06
|
|
|
חבר מתאריך: 10.10.07
הודעות: 2,500
|
|
קטע קוד שכתבתי (ל DS1306, אך הרגיסטרים דומים):
המרה מ BCD ל HEX :
time[0] and time[1] are the hour and minutes registers in BCD
time[2] and time[3] are the same, but in HEX values
c is a temporary variable
c = ((time[0]>>4) & 0x0f) * 10;
c += (time[0] & 0x0f);
time[2] = c;
c = ((time[1]>>4) & 0x0f) * 10;
c += (time[1] & 0x0f);
time[3] = c;
המרה מ HEX ל BCD:
j = (time[2] / 10) & 0x0f;
c = (time[2] - (j * 10)) & 0x0f;
time[0] = (j<<4) + c;
j = (time[3] / 10) & 0x0f;
c = (time[3] - (j * 10)) & 0x0f;
time[1] = (j<<4) + c;
_____________________________________
Elim
|