Download CodeVisionAVR User Manual

Transcript
CodeVisionAVR
4.12.4 Philips PCF8583 Real Time Clock Functions
These functions are intended for easy interfacing between C programs and the PCF8583 I2C bus real
time clock (RTC).
The prototypes for these functions are placed in the file pcf8583.h, located in the .\INC subdirectory.
This file must be #include -ed before using the functions.
The I2C bus functions prototypes are automatically #include -ed with the pcf8583.h.
Prior to #include -ing the pcf8583.h file, you must declare which microcontroller port and port bits are
used for communication with the PCF8583 through the I2C bus.
Example:
/* the I2C bus is connected to ATmega8515 PORTB */
/* the SDA signal is bit 3 */
/* the SCL signal is bit 4 */
#asm
.equ __i2c_port=0x18
.equ __sda_bit=3
.equ __scl_bit=4
#endasm
/* now you can include the PCF8583 Functions */
#include <pcf8583.h>
The PCF8583 Functions are:
void rtc_init(unsigned char chip, unsigned char dated_alarm)
this function initializes the PCF8583 chip.
Before calling this function the I2C bus must be initialized by calling the i2c_init function.
This is the first function that must be called prior to using the other PCF8583 Functions.
If more then one chip is connected to the I2C bus, then the function must be called for each one,
specifying accordingly the function parameter chip.
Maximum 2 PCF8583 chips can be connected to the I2C bus, their chip address can be 0 or 1.
The dated_alarm parameter specifies if the RTC alarm takes in account both the time and date
(dated_alarm=1), or only the time (dated_alarm=0).
Refer to the PCF8583 data sheet for more information.
After calling this function the RTC alarm is disabled.
unsigned char rtc_read(unsigned char chip, unsigned char address)
this function reads the byte stored in the PCF8583 SRAM.
void rtc_write(unsigned char chip, unsigned char address, unsigned char data)
this function stores the byte data in the PCF8583 SRAM.
When writing to the SRAM the user must take in account that locations at addresses 10h and 11h are
used for storing the current year value.
unsigned char rtc_get_status(unsigned char chip)
this function returns the value of the PCF8583 control/status register.
By calling this function the global variables __rtc_status and __rtc_alarm are automatically updated.
The __rtc_status variable holds the value of the PCF8583 control/status register.
The __rtc_alarm variable takes the value 1 if an RTC alarm occurred.
© 1998-2008 HP InfoTech S.R.L.
Page 156