CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PCF8583 Clock ic

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PCF8583 Clock ic
PostPosted: Fri Jul 14, 2006 8:19 am     Reply with quote

Can someone help me with a code to display hours, minutes,seconds
and on the second line day, month, year

I tried several think but i have only mintes and seconds on the lcd
epideath



Joined: 07 Jun 2006
Posts: 47

View user's profile Send private message

PostPosted: Fri Jul 14, 2006 8:57 am     Reply with quote

please post some of your code.
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Jul 14, 2006 9:02 am     Reply with quote

Here is the code
Code:
#include <18F4620>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOBROWNOUT,NOPUT,NOLVP,DEBUG,NOSTVREN,NOPROTECT

#include <flex_lcd420>
#include <pcf8583>

void main() {
   lcd_init();
   while (TRUE) {
      Gettime();
      lcd_gotoxy(1,1);
      printf(lcd_putc,"Seconds: %01u%01u:%01u%01u",time[2],time[3],time[0],time[1]);
      delay_ms(50);
   }
}



Code:

#ifndef PCF8583_SDA

#define PCF8583_SDA PIN_C4
#define PCF8583_SCL PIN_C3

#endif

#use i2c(master,sda=PCF8583_SDA,scl=PCF8583_SCL,FORCE_HW,RESTART_WDT)


// Defines address for Read and Write ON I2C BUS
#define PCF8583_ADDR_WRITE      0xA0
#define PCF8583_ADDR_READ       0xA1

// Defines internal registers
#define CONTROL_STATUS_REG      0x00
#define HUNDREDTH_OF_SEC_REG    0x01
#define SECONDS_REG             0x02
#define MINUTES_REG             0x03
#define HOURS_REG               0x04
#define YEAR_DATE_REG           0x05
#define WEEKDAYS_MONTHS_REG     0x06
#define TIMER_REG               0x07
#define ALARM_CONTROL_REG       0x08
#define ALARM_HUNDREDTH_OF_SEC  0x09
#define ALARM_SECONDS           0x0A
#define ALARM_MINUTES           0x0B
#define ALARM_HOURS             0x0C
#define ALARM_DATE              0x0D
#define ALARM_MONTH             0x0E
#define ALARM_TIMER             0x0F
#define FREE_RAM_START          0x10
#define FREE_RAM_END            0xFF

// Defines seconds register (RESET STATE: ???? ????)
struct {
    byte UNITS_BCD      :4;     // Unit seconds BCD format
    byte TENS           :3;     // Ten seconds, 0 to 5 binary
    byte NOT_UNUSED     :1;     // NOT USED
} SECONDSREG;

// Defines minutes register (RESET STATE: ???? ????)
struct {
    byte UNITS_BCD      :4;     // Unit minutes BCD format
    byte TENS           :3;     // Ten minutes, 0 to 5 binary
    byte NOT_UNUSED     :1;     // NOT USED
} MINUTESREG;

// Defines hours register (RESET STATE: 0000 0000)
typedef struct {
    byte UNITS_BCD      :4;     // Unit hours BCD format
    byte TENS           :2;     // Ten hours, 0 to 2 binary
    byte AM_PM_FLAG     :1;     // 0 -> AM, 1 -> PM
    byte FORMAT         :1;     // 0 -> 24h format, 1 -> 12h format
} HOURSREG;

// Defines yeardate register (RESET STATE: 0000 0001)
typedef struct {
    byte UNIT_DAYS_BCD  :4;     // Unit days BCD format
    byte TEN_DAYS       :2;     // Ten days, 0 to 3 binary
    byte YEAR           :2;     // 0 to 3 binary, reads as 0 if the mask flag is set
} YEARDATEREG;


byte time[4];

byte decD2hexD(byte value) {
   return(value%10+16*(value/10));
}

byte hexD2decD(byte value) {
   return(value%16+10*(value/16));
}

byte pcf8583_read(byte address) {
   byte data;

   i2c_start();
   i2c_write(PCF8583_ADDR_WRITE);
   i2c_write(address);
   i2c_start();
   i2c_write(PCF8583_ADDR_READ);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}

void Gettime() {
   SECONDSREG=pcf8583_read(SECONDS_REG);
   MINUTESREG=pcf8583_read(MINUTES_REG);
   
   time[0]=hexd2decD(SECONDSREG.TENS);
   time[1]=hexd2decD(SECONDSREG.UNITS_BCD);
   time[2]=hexd2decD(MINUTESREG.TENS);
   time[3]=hexd2decD(MINUTESREG.UNITS_BCD);
}
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Jul 14, 2006 12:10 pm     Reply with quote

Take a look at M41T80
http://www.ccsinfo.com/forum/viewtopic.php?t=24125
It is also I2C and using BCD. This may just require a remaping of the register locations. See how I printed them.
Guest








PostPosted: Tue Jul 18, 2006 9:55 am     Reply with quote

Nobydy can help me with the code how to display the year field?
Please give me some support
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group