Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with PCF8583.

Status
Not open for further replies.

bpanjkov

Newbie level 3
Joined
Mar 20, 2005
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
pcf8583 year

I have problem with RTC.

Code:
'******************************************************************************
' Project: PCF
'
' This project is simple demonstration how to
' read date and time from PCF8583 RTC (real-time clock).
' The code can be used with any MCU that has MSSP module at portc.
'
' Date and time are printed at LCD. In order to use the example,
' address pin A0 of PCF8583 must be set to 0V.
'******************************************************************************

program pcf

dim Sec as byte
dim Min as byte
dim Hr  as byte
dim Day as byte
dim Mn  as byte
dim Year as byte
dim txt as char[15]

sub procedure Zero_fill(dim byref value as char[10])    ' fill text repesentation
  if length(value) = 1 then                         '      with leading zero
    value[2] = value[1]
    value[1] = 48
    value[0] = 2
  end if
end sub

' reads time and date information from RTC (PCF8583)
sub procedure Read_time(dim byref Sec as byte,
                        dim byref Min as byte,
                        dim byref Hr  as byte,
                        dim byref Day as byte,
                        dim byref Mn  as byte,
                        dim byref Year as byte)
   I2C_start
   I2C_Wr($A0)
   I2C_Wr(2)
   I2C_Repeated_Start
   I2C_Wr($A1)
   sec = I2C_Rd(1)
   while I2C_Is_Idle = 0  nop wend
   min = I2C_Rd(1)
   while I2C_Is_Idle = 0  nop wend
   hr = I2C_Rd(1)
   while I2C_Is_Idle = 0  nop wend
   day = I2C_Rd(1)
   while I2C_Is_Idle = 0  nop wend
   mn = I2C_Rd(0)
   while I2C_Is_Idle = 0  nop wend
   I2C_Stop
end sub

sub procedure Transform_time(dim byref Sec  as byte,
                             dim byref Min  as byte,
                             dim byref Hr   as byte,
                             dim byref Day  as byte,
                             dim byref Mn   as byte,
                             dim byref Year as byte)
  sec  =  ((sec and $F0) >> 4)*10 + (sec and $0F)   ' formats date and time
  min  =  ((min and $F0) >> 4)*10 + (min and $0F)
  hr   =  ((hr and $F0) >> 4)*10 + (hr and $0F)
  year =  ((day and $C0)) >> 6
  day  =  ((day and $30) >> 4)*10 + (day and $0F)
  mn   =  ((mn and $10) >> 4)*10 + (mn and $0F)
end sub

sub procedure Display_time(dim Sec  as byte,
                           dim Min  as byte,
                           dim Hr   as byte,
                           dim Day  as byte,
                           dim Mn   as byte,
                           dim Year as byte)
' output values to LCD display
   ByteToStr(day,txt)
   Zero_fill(txt)
   LCD_Out(1,6,txt)
   ByteToStr(mn,txt)
   Zero_fill(txt)
   LCD_Out(1,9,txt)
   LCD_Chr(1,15,52+year)
   ByteToStr(hr,txt)
   LCD_Out(2,6,txt)
   ByteToStr(min,txt)
   Zero_fill(txt)
   LCD_Out(2,9,txt)
   ByteToStr(sec,txt)
   Zero_fill(txt)
   LCD_Out(2,12,txt)
end sub

sub procedure Init
  OPTION_REG = $7F
  'TRISD = 0                 ' designate portd as output
  LCD_init(PORTB)            ' initialize LCD on portd
  I2C_init(100000)           ' initialize I2C
  txt = "Date:"             ' prepare and output static text on LCD
  LCD_Out(1,1,txt)     '
  Lcd_Chr(1,8,":")     '
  Lcd_Chr(1,11,":")
  txt = "Time:"
  LCD_Out(2,1,txt)
  Lcd_Chr(2,8,":")
  Lcd_Chr(2,11,":")
  txt = "200"
  LCD_Out(1,12,txt)
  Lcd_Cmd(LCD_CURSOR_OFF)
end sub


main:
  Init                                            ' perform initialization
  while true
    Read_Time(Sec, Min, Hr, Day, Mn, Year)        ' read time from RTC(PCF8583)
    Transform_Time(Sec, Min, Hr, Day, Mn, Year)   ' format data and time
    Display_Time(Sec, Min, Hr, Day, Mn, Year)     ' prepare and display on LCD
    Delay_ms(1000)                                ' wait 1s
  wend
end.

this program demonstrate working with PFC8583 from mikroelektronika. I make this device but dont work.

I connect:
SCL to RC3
SDA to RC4
A0 to GND

LCD to protB

please help me!




PS sorry on bad english!
 

probleme mit pcf8583

Hi bpanjkov,

Do you have pull up resistors on SDA and SCK? You should use 4.7K. If they're not there the clock won't work right.

BobK
 

pfc8583 rtc application

Yes I pull-up.

I forget say MCU is: 16f877A @ 4 MHz
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top