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 pic

Status
Not open for further replies.

amindzo

Member
Hi,
i have connected DS1307 to pic16F873A. for reading and writing numbers to DS1307 , the numbers should be in hex mode.
so when i want to adjast the time with keyboard,first i put the nunmber for example 55 in a variable .
after that i write this number in DS1307 but it write to DS1307 in dec mode.
what should i do?
could you help me?
i use micro code studio picbasic pro2.41
i use i2cread and i2cwrite instructions.

this is my program:
note that i can put "$" sign befor number 55 in minute variable but imagine that i enter this number by keboard and it's
decimal. i try on this instruction but it's wrong:
I2CWRITE SDA,SCL,$D0,$00,[$sec,$minute,$hour,$2,$6,$7,$4,$90]
because i can't put $ sign befor variables.

something i should do with the instruction, but i don't know what should i do.
please help me?!

program:
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
ADCON1=7
pause 100
sec var byte
minute var byte
hour var byte
sec=0
minute=55
hour=$15
SDA var PORTA.0
SCL var PORTA.1
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=",hex2 DB0[2],":",hex2 DB0[1],":",hex2 DB0[0]
'lcdout $fe,$c0,"Date=",hex2 DB0[3],"-",hex2 DB0[5],"-",hex2 DB0[6]
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,[sec,minute,hour,$2,$6,$7,$4,$90] ' Write to DS1307
pause 10
RETURN ' Sec Min Hr Day D M Y Control
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top