#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
#include <inttypes.h>
#include "include/i2cmaster.h"
#define Dev24LC08B 0xA0
int main(void){
uint8_t readbyte;
DDRB = 0x00;
PORTB = 0x0F;
i2c_init();
if( i2c_start(Dev24LC08B + I2C_WRITE) ){//check if device is present
i2c_stop();
return -1;
}else{
//write data to eeprom
i2c_write(0x00);//send address where to save data
i2c_write(0x01);//send data to write in the previous address
i2c_write(0x02);//send data to write in the next address
i2c_write(0x04);//send data to write in the next address
i2c_write(0x08);//send data to write in the next address
i2c_stop();
//read data from eeprom
//send write command to set the address where to start reading
i2c_start_wait(Dev24LC08B + I2C_WRITE);
i2c_write(0x00);
//send a read command and read the bytes that were previously written to eeprom
i2c_rep_start(Dev24LC08B + I2C_READ);
readbyte = i2c_readAck();
PORTB = readbyte;
_delay_ms(500);
readbyte = i2c_readAck();
PORTB = readbyte;
_delay_ms(500);
readbyte = i2c_readAck();
PORTB = readbyte;
_delay_ms(500);
readbyte = i2c_readNak();
PORTB = readbyte;
_delay_ms(500);
i2c_stop();
}
while(0x01);
return 0;
}
I2lmbmRlZiBGX0NQVQojZGVmaW5lIEZfQ1BVIDE2MDAwMDAwVUwKI2VuZGlmCgojaW5jbHVkZSA8YXZyL2lvLmg+CiNpbmNsdWRlIDx1dGlsL2RlbGF5Lmg+CiNpbmNsdWRlIDxpbnR0eXBlcy5oPgoKI2luY2x1ZGUgImluY2x1ZGUvaTJjbWFzdGVyLmgiCgojZGVmaW5lIERldjI0TEMwOEIgIDB4QTAKCmludCBtYWluKHZvaWQpewogICB1aW50OF90IHJlYWRieXRlOwoKICAgRERSQiA9IDB4MDA7CiAgIFBPUlRCID0gMHgwRjsKCiAgIGkyY19pbml0KCk7CgogICBpZiggaTJjX3N0YXJ0KERldjI0TEMwOEIgKyBJMkNfV1JJVEUpICl7Ly9jaGVjayBpZiBkZXZpY2UgaXMgcHJlc2VudAogICAgICBpMmNfc3RvcCgpOwogICA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