Hello everyone ;
I'm trying to get my DS3231 working but no luck so far ... I've read already posted threads about this IC but they don't help ..
Here is the code I'm using on PIC16f628A
Code:
'****************************************************************
'* Name : RTC.BAS *
'* Author : Burak Günay *
'* Notice : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 8/9/2015 *
'* Version : 1.0 *
'* Notes : REAL TIME CLOCK WITH DS3231 *
'* : *
'****************************************************************
#config
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _LVP_OFF & _CP_OFF
#endconfig
'-------------------------------------------------------------------------
Define OSC 4
DEFINE LCD_EREG PORTA 'LCD Enable port
DEFINE LCD_EBIT 6 'LCD Enable port pin
DEFINE LCD_RSREG PORTA 'LCD RS port
DEFINE LCD_RSBIT 7 'LCD RS port pin
define LCD RWREG PORTA 'LCD R/W port
define LCD_RWBIT 4 'LCD R/W port pin
DEFINE LCD_DREG PORTB 'LCD data port
DEFINE LCD_DBIT 4 'LCD data port starts from pin x
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'LCD lines
'-------------------------------------------------------------------------
'-------------------------------------------------------------------------
PORTA=%00000000 : PORTB=%00000000
CMCON=%00000111 'Comparators off
OPTION_REG.7=0 'INTERNAL WEAK PULL-UPS OF PORTB ARE ENABLED.
TRISA=%00000000 : TRISB=%00000000
'-------------------------------------------------------------------------
'-------------------------------------------------------------------------
SDA VAR PORTB.0
SCL VAR PORTB.1
'-------------------------------------------------------------------------
i var byte
q var byte[7]
tens var byte
units var byte
tmp var byte
'-------------------------------------------------------------------------
lcdout $FE,1
pause 1000
Q[0]=0
Q[1]=50
Q[2]=20
Q[3]=1
Q[4]=8
Q[5]=9
Q[6]=15
GOSUB TOBCD
i2cwrite sda,scl,%11010000,$00,Q[0],Q[1],Q[2],Q[3],Q[4],Q[5],Q[6]
pause 500
MAIN:'>>>>>>>>>>>>>>>>>>>>>>>>>>>
i2cREAD SDA,SCL,%11010001,$00,Q[0],Q[1],Q[2],Q[3],Q[4],Q[5],Q[6]
GOSUB TODEC
LCDOUT $FE,$80, DEC2 Q[2],":",DEC2 Q[1],":",DEC2 Q[0]
LCDOUT $FE,$C0, DEC2 Q[4],":",DEC2 Q[5],":",DEC2 Q[6]
GOTO MAIN'<<<<<<<<<<<<<<<<<<<<<<<
'******************************DECIMAL TO BCD***********************************
TOBCD: 'Conversion to BCD
for i=0 to 6
TMP = Q[i] DIG 1 'Get TENS to temp variable
TENS = TMP << 4
UNITS = Q[i] DIG 0 'Get UNITS to units variable
Q[i] = TENS + UNITS
next i
RETURN
'**************************BCD TO DECIMAL SYSTEM********************************
TODEC:
for i=0 to 6
TMP = Q[i] & %01110000
TENS = TMP >> 4
UNITS = Q[i] & %00001111
Q[i] = TENS * 10 + UNITS
next i
RETURN
'*******************************************************************************
Where do I make the mistake .. I've read its datasheet and wrote a code accordingly step by step but there must be something I'm missing .. By the way I supply the pic and the DS3231 with 5V
Thanks in advance
Bookmarks