fork download
  1. /*
  2.  * Mega328_I2C_EEPROM.c
  3.  *
  4.  * Created: 10/30/2016 10:44:51 PM
  5.  * Author: jgmDESIGNS-Laptop
  6.  */
  7.  
  8. #ifndef F_CPU
  9. #define F_CPU 16000000UL
  10. #endif
  11. #include <avr/io.h>
  12. #include <stdio.h>
  13. #include <stdint.h>
  14. #include <stdlib.h>
  15. #include <util/delay.h>
  16. #include <avr/interrupt.h>
  17. #include <string.h>
  18. #include <avr/pgmspace.h>
  19.  
  20. #include "i2cmaster.h"
  21.  
  22.  
  23. #define Dev_24LC08B 0xA0 // device address of EEPROM 24LC88, see datasheet <---jgmdesigns changed device name and address for device - See datasheet
  24.  
  25.  
  26.  
  27. int main(void){
  28.  
  29. unsigned char ret;
  30.  
  31. DDRB = 0x0f; // use LOWER pins on port B for output <---jgmdesigns changed PINS USED
  32. PORTB = 0x0f; // (active HIGH LED's ) <---jgmdesigns changed to ACTIVE HIGH
  33.  
  34. i2c_init(); // init I2C interface
  35.  
  36. /* write 0x75 to eeprom address 0x05 (Byte Write) */
  37. ret = i2c_start(Dev_24LC08B+I2C_WRITE); // set device address and write mode
  38. if ( ret ){
  39. /* failed to issue start condition, possibly no device found */
  40. i2c_stop();
  41. PORTB=0x00; // activate all 8 LED to show error */
  42. }else{
  43. /* issuing start condition ok, device accessible */
  44. i2c_write(0x05); // write address = 5
  45. i2c_write(0x75); // ret=0 -> Ok, ret=1 -> no ACK
  46. i2c_stop(); // set stop conditon = release bus
  47.  
  48. /* write ok, read value back from eeprom address 0x05, wait until
  49.   the device is no longer busy from the previous write operation */
  50. i2c_start_wait(Dev_24LC08B+I2C_WRITE); // set device address and write mode
  51. i2c_write(0x05); // write address = 5
  52. i2c_rep_start(Dev_24LC08B+I2C_READ); // set device address and read mode
  53. ret = i2c_readNak(); // read one byte
  54. i2c_stop();
  55.  
  56. PORTB = ~ret; // output byte on the LED's
  57.  
  58. /* write 0x70,0x71,072,073 to eeprom address 0x00..0x03 (Page Write),
  59.   wait until the device is no longer busy from the previous write operation */
  60. i2c_start_wait(Dev_24LC08B+I2C_WRITE); // set device address and write mode
  61. i2c_write(0x00); // write start address = 0
  62. i2c_write(0x01); // write data to address 0 <---jgmdesigns changed value for demo
  63. i2c_write(0x02); // " " " " 1 <---jgmdesigns changed value for demo
  64. i2c_write(0x04); // " " " " 2 <---jgmdesigns changed value for demo
  65. i2c_write(0x08); // " " " " 3 <---jgmdesigns changed value for demo
  66. i2c_stop(); // set stop conditon = release bus
  67.  
  68. /* write ok, read value back from eeprom address 0..3 (Sequencial Read),
  69.   wait until the device is no longer busy from the previous write operation */
  70. i2c_start_wait(Dev_24LC08B+I2C_WRITE);// set device address and write mode
  71. i2c_write(0x00); // write address = 0
  72. i2c_rep_start(Dev_24LC08B+I2C_READ); // set device address and read mode
  73. ret = i2c_readAck(); // read one byte form address 0
  74. PORTB = ret; //<---jgmdesigns added output for display on LED's
  75. _delay_ms(750); //<---jgmdesigns changed - added delay for display on PORTB
  76. ret = i2c_readAck(); // " " " " " 1
  77. PORTB = ret; //<---jgmdesigns added output for display on LED's
  78. _delay_ms(750); //<---jgmdesigns changed - added delay for display on PORTB
  79. ret = i2c_readAck(); // " " " " " 2
  80. PORTB = ret; //<---jgmdesigns added output for display on LED's
  81. _delay_ms(750); //<---jgmdesigns changed - added delay for display on PORTB
  82. ret = i2c_readNak(); // " " " " " 3
  83. PORTB = ret; //<---jgmdesigns added output for display on LED's
  84. _delay_ms(750); //<---jgmdesigns changed - added delay for display on PORTB
  85. i2c_stop(); // set stop condition = release bus
  86.  
  87. //<---jgmdesigns changed - removed last PORT B write
  88. }
  89.  
  90. for(;;);
  91. }
  92.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:11:20: fatal error: avr/io.h: No such file or directory
compilation terminated.
stdout
Standard output is empty