Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

connecting Ds1307 to 16F873A

Status
Not open for further replies.

amindzo

Member
Hi,
I have a big problem with this. I want to make aclock with Ds1307 and 16F873A. I can show thw time on lcd but when minute goes to 57 ,after that it jump to 64 and it continioued to 89 and after that minute resets and hour added . this problem occur for second and hour too.
please help me with this problem?
I wrote the program in picbasic ver2.41.
I used i2cread and i2cwrite instructions . please wirte me the correct program in picbasic.
please help me with picbasic

This is my program . Is it right or not?

define OSC 4
include"modedefs.bas"
' Set LCD Data port
DEFINE LCD_DREG PORTC
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTC
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTC
' Set LCD Enable bit
DEFINE LCD_EBIT 0
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2

pause 100

SDA var PORTB.5
SCL var PORTB.7
DB0 var byte[8]

CMCON = %00000111 ' Comparators = off

pause 1000

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=",#DB0[2],":",#DB0[1]
pause 2000
goto read_1307
end

Write_1307:
' Set time & date to 15:55:00 Tuesday 6th of July 2004
I2CWRITE SDA,SCL,$D0,$00,[00,55,15,2,6,7,4,$90] ' Write to DS1307
RETURN ' Sec Min Hr Day D M Y Control



Amin Derazgisoo
 
Last edited:
DS1307 use the Hexadecimal... so just change your LCDOUT to
Code:
lcdout $fe,1,"Time=",HEX2 DB0[2],":",HEX2 DB0[1]

Same for all your setting 55 should be $55 and so on.

In your case 89 decimal is 59Hexadecimal... no problem.
 
Last edited:
a minor quibble - it uses BCD, not hex. if you are doing math on the time, you will need to factor that in.

however, if you print it as hex it will do the right thing.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top