fork download
  1. #ifndef F_CPU
  2. #define F_CPU 16000000UL
  3. #endif
  4.  
  5. #include <avr/io.h>
  6. #include <util/delay.h>
  7. #include <inttypes.h>
  8.  
  9. #include "include/i2cmaster.h"
  10.  
  11. #define Dev24LC08B 0xA0
  12.  
  13. int main(void){
  14. uint8_t readbyte;
  15.  
  16. DDRB = 0x00;
  17. PORTB = 0x0F;
  18.  
  19. i2c_init();
  20.  
  21. if( i2c_start(Dev24LC08B + I2C_WRITE) ){//check if device is present
  22. i2c_stop();
  23. return -1;
  24. }else{
  25. //write data to eeprom
  26. i2c_write(0x00);//send address where to save data
  27. i2c_write(0x01);//send data to write in the previous address
  28. i2c_write(0x02);//send data to write in the next address
  29. i2c_write(0x04);//send data to write in the next address
  30. i2c_write(0x08);//send data to write in the next address
  31. i2c_stop();
  32.  
  33. //read data from eeprom
  34.  
  35. //send write command to set the address where to start reading
  36. i2c_start_wait(Dev24LC08B + I2C_WRITE);
  37. i2c_write(0x00);
  38.  
  39. //send a read command and read the bytes that were previously written to eeprom
  40. i2c_rep_start(Dev24LC08B + I2C_READ);
  41. readbyte = i2c_readAck();
  42. PORTB = readbyte;
  43. _delay_ms(500);
  44. readbyte = i2c_readAck();
  45. PORTB = readbyte;
  46. _delay_ms(500);
  47. readbyte = i2c_readAck();
  48. PORTB = readbyte;
  49. _delay_ms(500);
  50. readbyte = i2c_readNak();
  51. PORTB = readbyte;
  52. _delay_ms(500);
  53. i2c_stop();
  54. }
  55.  
  56. while(0x01);
  57. return 0;
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:5:20: fatal error: avr/io.h: No such file or directory
compilation terminated.
stdout
Standard output is empty