General area when it fits no where else

Moderator: Mmiscool

User avatar
By PhilTilson
#64083 In an attempt to implement comms between a RTC chip and the ESP, I accessed the "I2C Reading DS1321" example on the Examples page. It didn't work. And the reason is this:

Code: Select all[bcd]
a = d / 16
a = int(a)
a = a + 48
c = a * 16
b = d - c
b = b + 48
e = chr(a)
f = chr(b)
f = e & f
return

This is wrong! I won't go into the detail now - it's a useful quick exercise to find the problem! This, however, works - and is neater than the original!

Code: Select all[bcd]
a = int(d / 16)
c = a * 16
a = a + 48
b = d - c + 48
f$ = chr(a) & chr(b)
return

And no, the problem is not the f$ - I just use that because I prefer to identify my string variables!

Phil
User avatar
By trackerj
#64092 Another related post here, DEC-to-BCD, BCD-to-DEC ESPBasic subroutines:
http://www.esp8266.com/viewtopic.php?f=38&t=13806