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

Driver for RTC PCF8583

 
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

Driver for RTC PCF8583
PostPosted: Sun Feb 05, 2006 10:15 am     Reply with quote

I will display the current time and date on a lcd display

But i can't get it to work
Did someone a sample code for this?
The Puma



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

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 11:40 am     Reply with quote

These are the defines
#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)

// 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 Control/Status Register (RESET STATE: 0000 0000)
typedef struct {
byte TIMER_FLAG :1; // 50% duty factor seconds flag if ALARM_ENABLE bit is 0
byte ALARM_FLAG :1; // 50% duty factor minutes flag if ALARM_ENABLE bit is 0
byte ALARM_ENABLE :1; // 0 -> alarm disabled, 1 -> enable alarm
byte MASK_FLAG :1; // 0 -> read locations 05 to 06 unmasked, 1 -> read date and month count directly
byte FUNCTION_MODE :2; // 00 -> clock mode 32.768 kHz, 01 -> clock mode 50 Hz, 10 -> event-counter mode, 11 -> test modes
byte HOLD_COUNT :1; // 0 -> count, 1 -> store and hold last count in capture latches
byte STOP_COUNT :1; // 0 -> count pulses, 1 -> stop counting, reset divider
} CTRLSTATUSREG;

// <CtrlStatusReg> bit settings
// Alarm enable bit settings
#define ALARM_OFF 0x00
#define ALARM_ON 0x01
// Mask flag settings
#define MASK_FLAG_OFF 0x00
#define MASK_FLAG_ON 0x01
// Function mode settings
#define CLOCK_32_768KHZ 0x00
#define CLOCK_50HZ 0x01
#define EVENT_COUNTER 0x02
#define TEST_MODES 0x03
// Hold last count settings
#define COUNT 0x00
#define STORE_HOLD_LAST_COUNT 0x01
// Stop count settings
#define COUNT_PULSES 0x00
#define STOP_COUNTING 0x01
// Used in 'byte PCF8583_Counter(byte Status)'
#define COUNTER_OFF 0x00
#define COUNTER_ON 0x01

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

// 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;

// Defines weekdaysmonths register (RESET STATE: 0000 0001)
typedef struct {
byte UNIT_MONTHS_BCD:4; // Unit months BCD format
byte TEN_MONTHS :1; // Ten months
byte WEEKDAYS :3; // Weekdays, 0 to 6 binary, reads as 0 if mask flag is set
} WEEKDAYSMONTHSREG;

// Defines Alarm control register, clock mode (RESET STATE: 0000 0000)
typedef struct {
byte TIMER_FUNCTION :3; // 000 -> timer, 001 -> hundr.of seconds, 010 -> seconds, 011 -> minutes, 100 -> hours, 101 -> days
byte TIMER_INTERRUPT_ENABLE :1; // 0 -> timer flag (no interrupt), 1 -> timer flag (interrupt)
byte CLOCK_ALARM_FUNCTION :2; // 00 -> no alarm clock, 01 -> daily alarm, 10 -> weekday alarm 11 -> dated alarm
byte TIMER_ALARM_ENABLE :1; // 0 -> no timer alarm, 1 -> timer alarm
byte ALARM_INTERRUPT_ENABLE :1; // 0 -> alarm flag (no interrupt), 1 -> alarm flag (interrupt)
} ALARMCTRLREG;

// <AlarmCtrlReg> bit settings
// Timer Function settings
#define NO_TIMER 0x00
#define HUNDREDTHS_OF_SECONDS 0x01
#define SECONDS 0x02
#define MINUTES 0x03
#define HOURS 0x04
#define DAYS 0x05

// Timer Interrupt settings
#define TIMER_FLAG_NO_INTERRUPT 0x00
#define TIMER_FLAG_INTERRUPT 0x01

// Clock Alarm Function settings
#define NO_CLOCK_ALARM 0x00
#define DAILY_ALARM 0x01
#define WEEKDAY_ALARM 0x02
#define DATED_ALARM 0x03

// Timer Alarm Enable settings
#define NO_TIMER_ALARM 0x00
#define TIMER_ALARM 0x01

// Alarm Interrupt Enable settings
#define ALARM_FLAG_NO_INTERRUPT 0x00
#define ALARM_FLAG_INTERRUPT 0x01

// Alarm WeekDays settings
#define SUNDAY 0x01
#define MONDAY 0x02
#define TUESDAY 0x04
#define WEDNESDAY 0x08
#define THURSDAY 0x10
#define FRIDAY 0x20
#define SATURDAY 0x40
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 4:15 pm     Reply with quote

Instead of constantly asking for drivers, you should learn to use Google.
Because the CCS compiler has been in existence for several years now,
there is tons of code out there for it.

The best way to search for a driver written in CCS is to search for the
chip name, and then search for built-in CCS functions that will likely be
used in the driver. Because the PCF8583 is a i2c chip, search for CCS
i2c functions.

For example, go to http://www.google.com and type in:

PCF8583 i2c_start() i2c_stop()

Then look at the list of hits. Right at the top of the page, you'll see
Peter Anderson's code. His code is not the best, in my opinion, because
he doesn't use all the CCS functions. He writes his own functions.

So look farther down the list of hits. There is one called "propklok.c".
That one is definitely written in CCS, and it uses the CCS i2c functions.
I don't know if it works. You should compare it to the PCF8583 data
sheet, and also to Peter Anderson's code, to see if it looks correct.

Using Google, you can find drivers more easily than by asking for
them on this forum.
The Puma



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

View user's profile Send private message

PostPosted: Tue Feb 07, 2006 12:46 pm     Reply with quote

Thanks PCM programmer,

But can you help me to display the year on a lcd with the above defines.
I you can help me with this first step then can i make the next steps on myself
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 07, 2006 12:53 pm     Reply with quote

I don't want to write drivers. I gave you the name of the sample
driver, called Propklok.c, which is on the net. You should study it
and write your own driver.
The Puma



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

View user's profile Send private message

PostPosted: Sat Jul 22, 2006 3:53 am     Reply with quote

I can't get this thing running?

How can i get the year on a lcd?
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