PDA

View Full Version : 8583 rtc date problem



crazyhellos
- 14th February 2007, 20:42
Hi everyone,

I'm dutch so please forgive me my englisch. I've programmed a working rtc 8583 but I've still got one problem in my coding. Time (h,m,s) are working fine and
adjusting them also. The problem is in de date (d,m,y). I'm reading 05 for the
days and 06 for the months what should be good I think. Now comes the strange thing. My days are going like 1,2,2,3,4 etc. So day three is missing and has become a 2. The rest of the days are working fine, but if the daycounter comes on 30 the counting stops and nothing is going upwards. I've tryed a lot of things, but I cant find what I'm doing wrong in my coding.I hope some of you see what I'm doing wrong. The only thing I can think of is that is must set register 00 bit 3 to 1 so that read date and month are directly, but I dont kwow how.

I also cant figure out is how to include the yearcounting. The years are in 4 so
ready for every leapyear. How must I set this rigister.

Ps everything is on a 16F628A and a 4x20 lcd.

Here's my coding (dutch)

Jerson
- 15th February 2007, 03:52
Hi everyone,
I also cant figure out is how to include the yearcounting. The years are in 4 so
ready for every leapyear. How must I set this rigister.

Ps everything is on a 16F628A and a 4x20 lcd.

Here's my coding (dutch)

I think this is not PicBasicPro code. However, the date and year are combined into 1 byte, the month is another byte. Remember, the format is BCD. This is a small fragment of my code that handles the date.


' read the RTC date in BCD format
RTC_GetDate:
I2Cread SDA, SCL, $A2, DayYear, [gr[0]]
Date[0] = gr[0] & $3f
Date[2] = gr[0] >> 6
I2Cread SDA, SCL, $A2, Month, [Date[1]]

' if the RTC year has advanced, advance the baseyear too
I2Cread SDA, SCL, $A2, LastYear, [gr[0]]
if Date[2] <> gr[0] then
I2Cwrite SDA,SCL, $A2, LastYear, [Date[2]] ' record the current rTC year

I2Cread SDA, SCL, $A2, BaseYear, [gr[0]]
gr[0] = gr[0] + 1 ' advance the baseyear
I2Cwrite SDA,SCL, $A2, BaseYear, [gr[0]]
endif

' add the baseyear to the Current RTC year
I2Cread SDA, SCL, $A2, BaseYear, [gr[0]]
Date[2] = Date[2] + gr[0]
return

' Set date in BCD format
RTC_SetDate:
' Store the lastyear
gr[0] = Date[2] & 3 ' the RTC year
I2Cwrite SDA,SCL, $A2, LastYear, [gr[0]]
gr[0] = (gr[0] << 6)+(Date[0] & $3f)
I2Cwrite SDA, SCL, $A2, DayYear, [gr[0],Date[1]]

' store the baseyear
gr[0] = Date[2] & $fc ' the lowest 2 bits are in the RTC year
I2Cwrite SDA,SCL, $A2, BaseYear, [gr[0]]
return


Jerson

crazyhellos
- 18th February 2007, 15:03
Hai jerson,

Thanks for your repley. I'm sorry, but I dont still get it how I must do it. The
year isn't that important for my application, because i can make that in my
chip, although it would be more easy for me to let the chip do the work.

The problem is still that I cant get the months and days of the chip in the
correct way, so I hope that you can show me how you have done it. I dont
want to copy it, i want to understand it what i'm doing wrong. You may mail
me your source if you dont want it to be read by everyone.

Hopefully you can help, because i cant get any furhter with this project.

Ps it is going be be a 20x4 lcd for in my car with time, date and temp.

Jerson
- 18th February 2007, 15:27
Hai jerson,

Thanks for your repley. I'm sorry, but I dont still get it how I must do it.
CrazyHellos

The address I have used for the RTC is $A2 because the pin 3 is tied to Vcc in my board. gr[0] is a register I have defined in my program; you may rename it to whatever you like.

Rest of the program is self explaining if you refer the datasheet for the RTC. However, you must remember, all registers of the RTC are in BCD format. Not binary. So, a month of 12 (december) should be entered as $12 or decimal(18). Maybe this is where you have the problem.

Regarding sharing my code, I have already shared the relevant part. Beyond this, I am sorry, you will have to work it out. The joy you get when your own code works will be something you will cherish.
Jerson

crazyhellos
- 19th February 2007, 15:28
thanks for your explenation about your code, its more clear to me now. I'm going
to workt on it and if I have dont it i wil let you know, thanks