    CodeVisionAVR  CodeWizardAVR,   I2C!   , 
        5 
- LM75
- DS1621
- PCF8563
- PCF8583
- DS1307
      ,   "   ",
          :

// I2C Bus functions
#asm
.equ __i2c_port=0x12 ;PORTD //     D
.equ __sda_bit=0 // sda  pcf8583      0
.equ __scl_bit=1 // scl  pcf8583      1
#endasm
#include <i2c.h> 

// PCF8583 Real Time Clock functions
#include <pcf8583.h> 

     

void main(void) {
unsigned char h,m,s,hs;
/* initialize the I2C bus */
i2c_init(); // 
/* initialize the RTC 0,
no dated alarm */
rtc_init(0,0);
/* read time from RTC 0*/
rtc_get_time(0,&h,&m,&s,&hs);
/* ........ */
}

    pcf8583.h

unsigned char rtc_read(unsigned char chip, unsigned char address) -    ,   PCF8583 SRAM.
void rtc_write(unsigned char chip, unsigned char address, unsigned char data) -       PCF8583 SRAM. 
unsigned char rtc_get_status(unsigned char chip) -      () PCF8583.      __ rtc_status  __ rtc_alarm  . __ rtc_status     () PCF8583. __ rtc_alarm    1,   . 
void rtc_get_time(unsigned char chip, unsigned char *hour, unsigned char *min, unsigned char *sec, unsigned char *hsec) -     . *hour, *min, *sec  *hsec   ,     , ,    . 
void rtc_set_time(unsigned char chip, unsigned char hour, unsigned char min, unsigned char sec, unsigned char hsec) -     .    , ,    .
void rtc_get_date(unsigned char chip, unsigned char *date, unsigned char *month, unsigned *year) -     .  - ,     ,   .
void rtc_set_date(unsigned char chip, unsigned char date, unsigned char month, unsigned year) -     .
void rtc_alarm_off(unsigned char chip) -     .
void rtc_alarm_on(unsigned char chip) -    .
void rtc_get_alarm_time(unsigned char chip, unsigned char *hour, unsigned char *min, unsigned char *sec, unsigned char *hsec) -    . 
void rtc_set_alarm_time(unsigned char chip, unsigned char hour, unsigned char min, unsigned char sec, unsigned char hsec) -    .
void rtc_get_alarm_date(unsigned char chip, unsigned char *date, unsigned char *month) -    . 
void rtc_set_alarm_date(unsigned char chip, unsigned char date, unsigned char month) -    . 
    i2c.h
void i2c_init(void) -     I2C.  -  ,        I2C.
unsigned char i2c_start(void) -  .    I2C. 0 - , 1 - .
void i2c_stop(void) -  .
unsigned char i2c_read(unsigned char ack) -    . Ack ,         ,   . 
unsigned char i2c_write(unsigned char data) -  .  1,  , 0  . 
void rtc_init(unsigned char chip, unsigned char dated_alarm) -     PCF8583.      I2C    ( i2c_init).   I2C    ,      .    PCF8583,       I2C - ,      0  1.

,   Atmel 24C02 256 byte I2C EEPROM: 
/* the I2C bus is connected to 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 I2C Functions */
#include <i2c.h>
/* function declaration for delay_ms */
#include <delay.h>
#define EEPROM_BUS_ADDRESS 0xa0
/* read a byte from the EEPROM */
unsigned char eeprom_read(unsigned char address) {
unsigned char data;
i2c_start();
i2c_write(EEPROM_BUS_ADDRESS);
i2c_write(address);
i2c_start();
i2c_write(EEPROM_BUS_ADDRESS | 1);
data=i2c_read(0);
i2c_stop();
return data;
}
/* write a byte to the EEPROM */
void eeprom_write(unsigned char address, unsigned char data) {
i2c_start();
i2c_write(EEPROM_BUS_ADDRESS);
i2c_write(address);
i2c_write(data);
i2c_stop();

/* 10ms delay to complete the write operation */
delay_ms(10);
}
void main(void) {
unsigned char i;

/* initialize the I2C bus */
i2c_init();
/* write the byte 55h at address AAh */
eeprom_write(0xaa,0x55);
/* read the byte from address AAh */
i=eeprom_read(0xaa);
while (1); /* loop forever */
}

    CodeVisionAVR.