I thought I would start a new thread as the other one based on the RTC giving strange readings seems to be something with the BDC conversions.
I have tried the following to set the time / date to a DS1307 RTC chip within my main section of code.
This works a treat - however I want to be able to set the values in the I2CWRITE string and have a routine that places the decimal values of 00 to 23 for hours and 00-59 for minutes into two variables SetHour and SetMinCode:gosub write_1307 read_1307: ' Read time Secs,Mins,Hours,Day,Date,Month,Year,Control I2CREAD SDA,SCL,$D1,$00,[STR DB0\8] ' Read 8 bytes from DS1307 lcdout $fe,1,"Time=",hex2 DB0[2],":",hex2 DB0[1],":",hex2 DB0[0] 'bit 0=sec, bit 1=min, bit 2=hrs lcdout $fe,$c0,"Date=",hex2 DB0[4],":",hex2 DB0[5],":",hex2 db0[6] 'bit 4=day, bit 5=month, bit 6=year goto read_1307 ******************************************** Write_1307: ' format: Sec Min Hr Day D M Y Control . EG to Set time & date to 19:00:00 14th Feb 2010 I2CWRITE SDA,SCL,$D0,$00,[$00,$00,$19,$7,$14,$2,$10,$90] ' Write to DS1307 pause 10 RETURN '
From what I understand PBO has a command / modifier IHEX, but I'm not sure on how to use it. Basically what I would like to do is take those decimal values in the two variables sethour and setmin and convert them to HEX and then place it to the relevant byte that gets written to the RTC... something likeCode:time: LCDOUT $FE,1 LCDOUT $FE,2,"Set Time" inp3: IF H_butt = 0 THEN GOSUB IncHours IF M_butt = 0 THEN GOSUB IncMinutes SetHour=Hours SetMin=Minutes LCDOUT $FE,$C0,#SetHour DIG 1,#SetHour DIG 0,":",#SetMin DIG 1,#SetMin DIG 0 pause 200 If S_butt = 0 then pause 250 goto savetime endif goto inp3
Code:DB0[2] = IHEX sethour DB0[1] = IHEX setmin
The current version uses a BCD conversion... but this is where I think the issues I had detailed in the previous thread lay, - is there a simple way that will convert the values and write them to the relevant bytes for the 1307 ?




Bookmarks