View Full Version : Pcf 8583
  
srspinho
- 16th April 2004, 19:51
Hi Friends,
I´m trying to use the Phillips PCF 8583 in my project.
But, after some tests, I discovered a strange problem.
After 59 minutes and 59 seconds, instead of going to 01:00:00 the RTC goes to 81:00:00 
And, when I decode the data to calculate the elapsed time in seconds, I got a completely wrong result.
I have never noticed that problem before because I had never used this RTC as a chronometer as I´m doing now.
I´m sending a small code I wrote to test the RTC.
The pin A0  of 8583 is grounded.
Have ever you seen this problem ?
Thank you 
Sérgio Pinheiro
=====================  Test Code ================
Define LCD_DREG PORTA 
Define LCD_DBIT 0 
Define LCD_RSREG PORTB 
Define LCD_RSBIT 4 
Define LCD_EREG PORTB 
Define LCD_EBIT 5 
SDA               var PORTB.1                 ' I2C data pin
SCL               var PORTB.2                 ' I2C clock pin
H                 var byte
M                 var Byte
S                 var Byte
Pause 500
I2CWrite SDA,SCL, %10100001,2,[0,0,0] 
pause 100 
LOOP:
           
I2CRead SDA, SCL, %10100001,2,[S,M,H]
pause 100
lcdout $FE, 2, Hex2(h),":",Hex2(M),":",Hex2(S)
goto LOOP
END
Darrel Taylor
- 16th April 2004, 21:36
Hi Sérgio,
Bit 7 of the hour register indicates if the device is in 12 or 24 hour mode.  Also Bit 6 is the am/pm indicator, if in 12hour mode.  They should be masked out to display a valid hour reading.
H = H & %00111111  ' Mask out hour mode flags
Of course, that doesn't explain why it changes all of the sudden.  It should power up in the 24 hour mode, bit7=0.  Here's a couple things to think about.
The CONTROL byte of the I2CREAD command should always have a 0 in the lowest bit.  Yours is set to 1.  So, instead of %10100001, it should be 10100000.  PBP automaticaly sets that bit depending on whether it's a read or a write, but in the manual, it states that this bit "should be kept clear"
The PCF8583 is a 100khz device.  If your OSC speed is greater than 8mhz you may need to use DEFINE I2C_SLOW 1
HTH,
   Darrel
gzorzi
- 19th April 2004, 08:55
I use this routine and work
S var byte
M var byte
H var byte
symbol SCL = portc.3
symbol SDA = portd.0
DecimaleSec var byte
DecimaleMin var byte
DecimaleOra var byte
S1 var byte
S2 var byte
M1 var byte
M2 var byte
H1 var byte
H2 var byte
I2CREAD SDA,SCL,%10100001,2,[S]
I2CREAD SDA,SCL,%10100001,3,[M]
I2CREAD SDA,SCL,%10100001,4,[H]
You must convert BCD format
DecimaleSec = ((S >> 4) * 10) + (S & $0f)
S1 = DecimaleSec dig 1
S2 = DecimaleSec dig 0
DecimaleMin = ((M >> 4) * 10) + (M & $0f)
M1 = DecimaleMin dig 1
M2 = DecimaleMin dig 0
DecimaleOra = ((H >> 4) * 10) + (H & $0f)
H1 = DecimaleOra dig 1
H2 = DecimaleOra dig 0
LCDOUT dec(H1),dec(H2),":",dec(M1),dec(M2),":",Dec(S1),dec(S2)
srspinho
- 19th April 2004, 14:18
Hi friends,
After the changes suggested by Darrel, the RTC is working fine.
It´s strange the fact of the RTC start working in 12 hour mode.
I have already used this RTC before and I had never had problem before.
But now it´s fixed !
Thanks Darrel e Gzorzi for your answers !
regards 
Sérgio Pinheiro
lupuccio
- 15th June 2005, 13:37
Please.... i'm new and i'd like to know how to set time in pcf8583 which command i need to use ?
busin %10100001,0,2,[hour,min,sec] 'for read ecc
but for change time and rewrite in 8583 ?
ffambrin
- 26th February 2006, 20:41
Hi, my name's Francisco Fambrini, and my code to adjust PCF8583 writed at Melabs PicBasicPRO Compiler (target:PIC 16F877) is above.
Please, visit my website: www.fdai.net
'************************************************* ***************
'                      PCF 8583  APREDENDO_1.0
'                 programa para testar o chip PCF8583
'                 na placa do Distribuidor de Energia
'                              26/Fev/2006
'************************************************* ***************
define OSC 20
DEFINE ADC_BITS 10 
define ADC_CLOCK 1
DEFINE LCD_DREG PORTD 
DEFINE LCD_DBIT 4 
DEFINE LCD_RSREG PORTD
DEFINE LCD_RSBIT 2 
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 3 
DEFINE LCD_BITS 4  
DEFINE LCD_LINES 2
symbol SCL = PORTC.3    ' I2C clock
symbol SDA = PORTC.5    ' I2C data
symbol UP = PORTA.4
SYMBOL DOWN = PORTA.3
SYMBOL ENTER = PORTA.2
SYMBOL SEL = PORTA.1
;*******************************************
;         Configuração do PIC
;*******************************************
 TRISA=%00111111
 TRISB=%00000000
 TRISC=%00100000
 TRISD=%00000000
 ADCON1 = $0E 'Configura somente RA0 como entrada de AD 
'******************************************
 PORTB=%00000000
 PORTC=%00000000
 PORTD=%00000000
'*****************************************
'------------------------
' VARIAVEIS DO PROGRAMA
HOUR VAR BYTE
MINUTE VAR BYTE
DAY VAR BYTE
MONTHY VAR BYTE
YEAR VAR BYTE
S VAR BYTE
M VAR BYTE
H VAR BYTE
D var byte
Mn var byte
Y var byte
TEMPO VAR WORD
'-----------------------
lcdout $fe,1 'limpa o display
Pause 500
lcdout "PCF8583 Aprender"
Lcdout $fe,$c0
LCDOUT "FDAI Eletronica"
Pause 1500
lcdout $fe,1 'limpa o display
Pause 100
Main:
I2CREAD SDA,SCL,%10100001,2,[S]
I2CREAD SDA,SCL,%10100001,3,[M]
I2CREAD SDA,SCL,%10100001,4,[H]
I2CREAD SDA,SCL,%10100001,5,[D]
I2CREAD SDA,SCL,%10100001,6,[Mn]
I2CREAD SDA,SCL,%10100001,7,[Y]
IF PORTA.1=0 THEN GOSUB ACERTAR
lcdout $fe,1 'Limpa o LCD 
lcdout $fe,2 'cursor n primeira posição
lcdout "Hora: ", hex(H),":", hex2(M),":", hex2(S)
lcdout $fe,$c0  'segunda linha do display
lcdout "Data: ", hex2(D),".", hex2(Mn),".20",hex2(Y)
IF PORTA.1=0 THEN GOSUB ACERTAR
Pause 500
goto Main  'VOLTA PARA O LOOP PRINCIPAL
'************************************************* *****************
' Rotina de ajuste do relogio RTC
ACERTAR:
lcdout $fe,1
Lcdout "Acertar hora"
Pause 1000
TEMPO = 1000
'Verifica se algum botao de ajuste foi pressionado:
'------------------------
VER_BOTOES:
        IF TEMPO =0 THEN 
        GOSUB GRAVAR_HORARIO
        RETURN
        ENDIF
        
      
        tempo = tempo -1
        ' Checa se algum botao de ajuste de h/min foi pressionado
        If PORTA.3 = 0 Then decmin
        If PORTA.4 = 0 Then incmin      ' Last 2 buttons set minute
        If PORTA.1 = 0 Then dechr
        If PORTA.2 = 0 Then inchr       ' First 2 buttons set hour
        pause 50
Goto VER_BOTOES   
'*************************************************
' Increment minutes
incmin: minute = minute + 1
        If minute >= 60 Then
                minute = 0
        Endif
        Goto debounce
' Increment hours
inchr:  hour = hour + 1
        If hour >= 24 Then
                hour = 0
        Endif
        Goto debounce
' Decrement minutes
decmin: minute = minute - 1
        If minute >= 60 Then
                minute = 59
        Endif
        Goto debounce
' Decrement hours
dechr:  hour = hour - 1
        If hour >= 24 Then
                hour = 23
        Endif
        goto debounce
'************************************
'essa é uma parte da rotina de acerto do relogio
debounce:  'atualiza o relogio na tela na hora do acerto do relogio
pause 200
tempo= 90
lcdout $fe,1
Lcdout $fe,2
Lcdout "Acerte Horario:"
lcdout $fe,$c0
Lcdout dec2 hour, ":", dec2 minute, ":00"
goto VER_BOTOES
'************************************
'*************************************
GRAVAR_HORARIO:
'Converte para Hexadecimal
DAY = 26
MONTHY = 4
YEAR=06
M = MINUTE/10*16 + MINUTE//10
H= hour/10*16 + hour//10
D= DAY/10*16 + DAY//10
Mn= MONTHY/10*16 + MONTHY//10
Y = YEAR/10*16 + YEAR//10
I2cwrite SDA,SCL,%10100001,2,[0]
I2Cwrite SDA,SCL,%10100001,3,[M]
I2Cwrite SDA,SCL,%10100001,4,[H]
I2CWRITE SDA,SCL,%10100001,5,[D]
I2CWRITE SDA,SCL,%10100001,6,[Mn]
I2CWRITE SDA,SCL,%10100001,7,[Y]
 RETURN
'************************************
End
 
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.