Real Time Clock not working

Mundine

New Member
hi guys, i am trying to get my real time clock to work but i am not getting a good reponse, i just want to mention that i dont have the backup battery installed yet. here is my program

symbol seconds = b1
symbol mins = b2
symbol hour = b3
symbol day = b4
symbol date = b5
symbol month = b6
symbol year = b7
symbol control = b8
i2cslave %11010000, i2cslow, i2cbyte
pause 100
start_clock:
let seconds = $00
let mins = $00
let hour = $01
let day = $02
let date = $21
let month = $07
let year = $03
let control = %00010000
writei2c 0,(seconds,mins,hour,day,date,month,year,control)
debug b1
pause 2000
main:
readi2c 0,(seconds,mins,hour,day,date,month,year)
debug b1
pause 2000
goto main

once this is downloaded i get this response in debug
b4=2
b5=33
b8=16
then after about 1 second it changed to this
b8=16
this just stays like this for a while
if anyone could help it would be great, thanks
 

BeanieBots

Moderator
The datasheet says Vbat must be held between 2.0v and 3.5v for proper operation.
Your code looks OK so hopefully it will work OK when you fit the battery.
If you don't want to fit a battery, then generate the voltage with a potential divider or some dropping diodes.

Hang on. I've just double checked the variables you are looking at. Day,date and the control register! What changes are you expecting to see in these?
Are the seconds counting up OK?

Don't forget that the registers count in BCD so use the Hex values not decimal to get any sort of meaningful numbers.


Edited by - beaniebots on 03/09/2007 06:23:04
 

moxhamj

New Member
The only value that will be changing every few seconds will be b1 seconds.

The bcd/decimal thing is a real trap. If you display on debug using hex it sort of makes sense but essentially take a decimal number like 17, convert to hex = 11 then take the two hex values and these are actually the decimal values to display ie a 1 and a 1. The clock uses this format as it is ?easier to display but actually it isn't.

This code converts to real decimal numbers
BCDtoDecimal:' all clock values are 2 bcd numbers. If convert to hex they display correctly
' pass b13, returns b13
b12=b13 and %00001111
b11=b13 / 16 ' shifts right 4 places
b10=b11*10
b13=b10+b12
return

Oh and I think it really wants the battery fitted. The battery will last 10 years whether you fit it or not as the current draw is not much more than the leakage current so go ahead and fit it.

Edited by - Dr_Acula on 03/09/2007 07:34:36
 

MORA99

Senior Member
It can work without a battery, this is my test code from a few months back, I didnt mount a battery.

http://elektronik.codebin.dk/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=15&MMN_position=15:8
 
Top