PDA

View Full Version : ds 1307



jcleaver
- 2nd February 2007, 15:22
having trouble finding post useing thgis dallas clock chip in pic basic pro

searched under ds 1307 and rtc no listing
can someone supply thread

thanks

mister_e
- 2nd February 2007, 17:31
try with ds1307 in one word.

One nice code example HERE (http://www.melabs.com/resources/samples/submitted/MN1307.txt)

jcleaver
- 3rd February 2007, 02:40
great program must have taken a lot of work

any way to get a schematic diagram or hook up sheet??

mister_e
- 3rd February 2007, 14:08
Euh... i don't see why as almost everything is really well explained in the hardware assignment section of the code.

jcleaver
- 3rd February 2007, 16:13
ok will try that
one more question trying to use with a 16f877a
get error messag but compiles

102 crosses boundry at @800h
already got protype board for this setup for this chip

any ideas?

mister_e
- 3rd February 2007, 19:16
http://www.picbasic.co.uk/forum/showthread.php?t=555&highlight=crosses+boundary

It's just a warning, nothing important. If you're using MPASM to compile your code, just add

@ errorlevel -306
and this will remove this stupid warning.

And, here's another endorsement
http://www.picbasic.co.uk/forum/showpost.php?p=102&postcount=1

At least, i don't feel alone :D

jcleaver
- 4th February 2007, 15:21
ok howeve i am not using mpsam
get lot more errors in program with this

thanks
for your help

BobK
- 4th February 2007, 15:36
Hi jcleaver,

You could save everyone alot of time and sanity if you would just post, for example, the errors you ARE getting and what compiler and assembler and version levels you are using. Perhaps even a screenshot of the list of errors from your program.

The program Mister-E referred you to was written for a 16F628. You are using a 16F877A. I apologize if I assume something here but you will have to make a number of setting changes to port over to the 877A. Analog ports on the 877A not on the 628, config fuse settings, etc.

We can help but give us the data we need!

BobK

jcleaver
- 4th February 2007, 22:01
did finally get something to work attached program but for some reason i am unable to duplicate this again seems to be the clock wont start
using pbp and mcs tried using mpspam with this but too many errors to count if someone could look over this listing and explain why the clock is not starting once itruns which i dont know how i got there it does what i want


thanks

' PicBasic Pro program to display result of
' 8-bit A/D conversion on LCD
'
' Connect analog input to channel-0 (RA0)
@ DEVICE pic16f877a, HS_OSC, WDT_ON, PWRT_ON, LVP_OFF, PROTECT_OFF

' Define LCD registers and bits
Define LCD_DREG PORTB ' Port for LCD Data
Define LCD_DBIT 4 ' Use upper 4 bits of Port
Define LCD_RSREG PORTB ' Port for RegisterSelect (RS) bit
Define LCD_RSBIT 3 ' Port Pin for RS bit
Define LCD_EREG PORTB ' Port for Enable (E) bit
Define LCD_EBIT 2 ' Port Pin for E bit
Define LCB_BITS 4 ' Using 4-bit bus
Define LCD_LINES 2 ' Using 2 line Display
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
Define LCD_DATAUS 50 ' Data Delay (uS)




DEFINE OSC 20
' Define ADCIN parameters
Define ADC_BITS 8 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
define loader_used 1
adval var byte ' Create adval to store result
AD33 VAR BYTE
W1 VAR WORD 'PUSHBUTTON
I VAR WORD
TRISA = %11111111 ' Set PORTA to all input
TRISD = %11111111 ' SET PORTD TO INPUT
ADCON1 = %00000010 ' Set PORTA analog
' Low PORTE.2 ' LCD R/W line low (W)
' Define I2C bus ports
B0 VAR BYTE
B1 VAR BYTE
B2 VAR BYTE
SDA VAR PORTC.4 'DS1307 SDA pin
SCL VAR PORTC.3 'DS1307 SCL pin
DEFINE I2C_SLOW 1
DEFINE I2C_HOLD 1
DEFINE I2C_SCLOUT 1
Pause 500 ' Wait .5 second
ADDR VAR BYTE
ADDR = 0
PAUSE 1000
CONT CON %11010000

secs var byte
mins var byte
hrs var byte
day var byte
date var byte
month var byte
year var byte
ctrl var byte



I2CWRITE SDA,SCL,CONT,ADDR,[$00,$59,$11,$03,$25, $12 ,$03, $10]
PAUSE 5000
I2CREAD SDA,SCL,CONT,ADDR ,[b2]
loop:

COUNT portd.1,750,w1
lcdout $fe,1
pause 1000

lcdout $fe,$80+4 ,"count: ", dec w1
pause 500
I2CREAD SDA,SCL,CONT,ADDR ,[secs,mins,hrs,day,date,month,year,ctrl]
pause 500
ADCIN 0, adval ' Read channel 0 to adval
ADCIN 1, AD33
Lcdout $fe, 1 ' Clear LCD
Lcdout "Value: ", # adval ' Display the decimal value
LCDOUT $FE,$C0, "VALUE : ", DEC AD33
Pause 500 ' Delay for .5 seconds
lcdout $fe,1 ' clear display
lcdout "min: ", hex mins
lcdout $FE,$C0,"secs: ",hex secs
pause 1000



Goto loop ' Do it forever
End

jcleaver
- 4th February 2007, 22:20
noticed all the values min sec ect go to 02 hex regardless of what my inital setting is

mister_e
- 4th February 2007, 22:55
Any Back-Up battery attached to this DS1307?


Backup Supply Input for Any Standard 3V Lithium Cell or Other Energy Source. Battery
voltage must be held between the minimum and maximum limits for proper operation.
Diodes in series between the battery and the VBAT pin may prevent proper operation. If a
backup supply is not required, VBAT must be grounded.

Any Pull-Up on SDA and SCL pins?

BobK
- 5th February 2007, 04:00
Hi jcleaver,

Do you have your RTC variables declared in your program? Look on page 2 or the Project MN1307 program about 1/2 way down.

Also do you have a statement "RTCSec.7 = 0". You need this to start the clock running. The clock chip powers up with RTCSec.7 = 1 which turns the osc off.

Your program could be returning the errors if you don't have the clock variables declared. Guessing at this point.

I see you have several segments to your program. You should take each one step by step. First get your LCD working. Something like a "Hello World". Then get the A/D portion working. Then add the clock program.

HTH,

BobK

jcleaver
- 5th February 2007, 15:46
was the bat conn not grounded appreicate all your help getting this going
thanks again

jcleaver
- 5th February 2007, 15:53
that solved the problem of everything going to 02 but the clock is still not running i am sending $00 to secs on inital start up do have pullup on scl and sda so i guess im not as far along as i thought

jcleaver
- 5th February 2007, 16:09
think i got it circuit board problem i hope
again thanks now i just have to add temp and i got this one done
let you know