Trouble simulating DS1307 RTC chip

andrewgodfrey

New Member
Hi.
I am planning to design a countdown timer with a picaxe 18x ,7 segment displays and a DS1307 real time clock chip.
As I do not yet have a DS1307,I have been experimenting with the Picaxe VSM program.

The program below has replaced the sample program that comes with the VSM program called "AXE110 datalogger.bas", and I have been using the schematic of the same name.


When I run the program, the lcd display shows hours:min:sec.

But the seconds value can suddenly jump several seconds and count to 100 instead of only 59.

Have I made a mistake with my program, or is there a bug in the VSM simulator?



Code:
i2cslave %11010000, i2cslow, i2cbyte
    
writei2c 0,($00,$00,$1,$03,$25,$12,$03,$10)  'Set time to 1:00:00 am on 25/12/03
        
Showtime:
 readi2c 0,(b0,b1,b2)
 serout 6,t2400,(254,128,#b2,":",#b1,":",#b0) 
goto Showtime

Thanks,
Russell.
 

hippy

Ex-Staff (retired)
The DS1307 values are held as BCD ( binary coded decimal ) where each byte is split into two 4-bit nibbles each of which represent a digit; so 12 is held as $12 which is two separate digits $1 and $2. That $12 is 18 in decimal which is what the # in the SEROUT commands give. You need to convert BCD digit pairs to decimal digits before using them ...

b0 = $12
BcdToAscii b0, b11, b12, b13
SerOut 6, T2400, ( b11, b12, b13 )

should show "0", "1" and "2".
 

andrewgodfrey

New Member
Thanks for the reply. It did help me understand the data output by the DS1307.
But the code you supplied actually gave me a syntax error using Picaxe VSM.

Would you please be able to supply code to convert the seconds value read from the DS1307 into decimal.
I expect this code would then also convert minutes and hours with a little modification.

I was able to get the folowing code to show "12" on the LCD display

Code:
start:

b0 = $12
BcdToAscii b0, b11, b12
SerOut 6, T2400, (254,128, b11, b12)

goto start
 

hippy

Ex-Staff (retired)
My mistake, and apologies for that; I confused BCDTOASCII with the syntax of BINTOASCII. As you have it is how it should be.
 
Top