Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 13 | jlesech | 1 | /**************************************************************************//** |
| 2 | * \brief EEPROM 24C01 / 24C02 library for Arduino - Demonstration program |
||
| 3 | * \author Copyright (C) 2012 Julien Le Sech - www.idreammicro.com |
||
| 4 | * \version 1.0 |
||
| 5 | * \date 20120217 |
||
| 6 | * |
||
| 7 | * This file is part of the EEPROM 24C01 / 24C02 library for Arduino. |
||
| 8 | * |
||
| 9 | * This library is free software: you can redistribute it and/or modify it under |
||
| 10 | * the terms of the GNU Lesser General Public License as published by the Free |
||
| 11 | * Software Foundation, either version 3 of the License, or (at your option) any |
||
| 12 | * later version. |
||
| 13 | * |
||
| 14 | * This library is distributed in the hope that it will be useful, but WITHOUT |
||
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
||
| 16 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
||
| 17 | * details. |
||
| 18 | * |
||
| 19 | * You should have received a copy of the GNU Lesser General Public License |
||
| 20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
||
| 21 | ******************************************************************************/ |
||
| 22 | |||
| 23 | /**************************************************************************//** |
||
| 24 | * \file WriteReadBytes.ino |
||
| 25 | ******************************************************************************/ |
||
| 26 | |||
| 27 | /****************************************************************************** |
||
| 28 | * Header file inclusions. |
||
| 29 | ******************************************************************************/ |
||
| 30 | |||
| 31 | #include <Wire.h> |
||
| 32 | |||
| 33 | #include <Eeprom24C01_02.h> |
||
| 34 | |||
| 35 | /****************************************************************************** |
||
| 36 | * Private macro definitions. |
||
| 37 | ******************************************************************************/ |
||
| 38 | |||
| 39 | /**************************************************************************//** |
||
| 40 | * \def EEPROM_ADDRESS |
||
| 41 | * \brief Address of EEPROM memory on TWI bus. |
||
| 42 | ******************************************************************************/ |
||
| 43 | #define EEPROM_ADDRESS 0x50 |
||
| 44 | |||
| 45 | /****************************************************************************** |
||
| 46 | * Private variable definitions. |
||
| 47 | ******************************************************************************/ |
||
| 48 | |||
| 49 | static Eeprom24C01_02 eeprom(EEPROM_ADDRESS); |
||
| 50 | |||
| 51 | /****************************************************************************** |
||
| 52 | * Public function definitions. |
||
| 53 | ******************************************************************************/ |
||
| 54 | |||
| 55 | /**************************************************************************//** |
||
| 56 | * \fn void setup() |
||
| 57 | * |
||
| 58 | * \brief |
||
| 59 | ******************************************************************************/ |
||
| 60 | void setup() |
||
| 61 | { |
||
| 62 | // Initialize serial communication. |
||
| 63 | Serial.begin(9600); |
||
| 64 | |||
| 65 | // Initiliaze EEPROM library. |
||
| 66 | eeprom.initialize(); |
||
| 67 | |||
| 68 | // Declare byte arrays. |
||
| 69 | byte inputBytes[94] = { 0 }; |
||
| 70 | byte outputBytes[94] = { 0 }; |
||
| 71 | |||
| 72 | // Fill input array with printable characters. See ASCII table for more |
||
| 73 | // details. |
||
| 74 | for (byte i = 0; i < 94; i++) |
||
| 75 | { |
||
| 76 | inputBytes[i] = i + 33; |
||
| 77 | } |
||
| 78 | |||
| 79 | // Write input array to EEPROM memory. |
||
| 80 | Serial.println("Write bytes to EEPROM memory..."); |
||
| 81 | eeprom.writeBytes(0, 94, inputBytes); |
||
| 82 | |||
| 83 | // Read array with bytes read from EEPROM memory. |
||
| 84 | Serial.println("Read bytes from EEPROM memory..."); |
||
| 85 | eeprom.readBytes(0, 94, outputBytes); |
||
| 86 | |||
| 87 | // Print read bytes. |
||
| 88 | Serial.println("Read bytes:"); |
||
| 89 | for (byte i = 0; i < 94; i++) |
||
| 90 | { |
||
| 91 | Serial.write(outputBytes[i]); |
||
| 92 | Serial.print(" "); |
||
| 93 | } |
||
| 94 | Serial.println(""); |
||
| 95 | } |
||
| 96 | |||
| 97 | /**************************************************************************//** |
||
| 98 | * \fn void loop() |
||
| 99 | * |
||
| 100 | * \brief |
||
| 101 | ******************************************************************************/ |
||
| 102 | void loop() |
||
| 103 | { |
||
| 104 | |||
| 105 | } |