How to use EEPROM in TG-LPC11U35-501

Dependencies:   AQM0802 EEPROM mbed

Files at this revision

API Documentation at this revision

Comitter:
yasuyuki
Date:
Thu Jun 26 13:48:05 2014 +0000
Parent:
0:8dfee9f6df54
Commit message:
lib

Changed in this revision

AQM0802.cpp Show diff for this revision Revisions of this file
AQM0802.h Show diff for this revision Revisions of this file
AQM0802.lib Show annotated file Show diff for this revision Revisions of this file
EEPROM.cpp Show diff for this revision Revisions of this file
EEPROM.h Show diff for this revision Revisions of this file
EEPROM.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 8dfee9f6df54 -r b72b39a47d1a AQM0802.cpp
--- a/AQM0802.cpp	Sun Jun 22 09:57:23 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
-//**********************
-// AQM0802.cpp for mbed
-//
-// AQM0802 lcd(P0_5,P0_4);
-// or
-// I2C i2c(P0_5,P0_4);
-// AQM0802 lcd(i2c);
-//
-// (C)Copyright 2014 All rights reserved by Y.Onodera
-// http://einstlab.web.fc2.com
-//**********************
-
-#include "mbed.h"
-#include "AQM0802.h"
-
-AQM0802::AQM0802 (PinName sda, PinName scl) : _i2c(sda, scl) {
-    init();
-}
-AQM0802::AQM0802 (I2C& p_i2c) : _i2c(p_i2c) {
-    init();
-}
-
-void AQM0802::put(unsigned char a, unsigned char b)
-{
-    buf[0]=a;
-    buf[1]=b;
-    _i2c.write(AQM0802_ADDR, buf, 2);
-}
-
-
-void AQM0802::get(unsigned char a)
-{
-    buf[0] = a;
-    _i2c.write(AQM0802_ADDR, buf, 1, true); // no stop, repeated
-    _i2c.read( AQM0802_ADDR, buf, 1);
-
-}
-
-void AQM0802::cls()
-{
-    // Clear Display = 0x01
-    put(CMD, 0x01);
-    // Wait 1.08ms
-    wait_ms(2);
-
-}
-
-void AQM0802::locate(int x, int y)
-{
-
-    // 8x2
-    put(CMD, 0x80 + y*0x40 + x);
-
-}
-
-void AQM0802::print(const char *a)
-{
-
-    while(*a != '\0')
-    {
-        put(DAT, *a);
-        a++;
-    }
-
-}
-
-void AQM0802::init()
-{
-    // Wait 40ms
-    wait_ms(100);
-    // Function set = 0x38
-    put(CMD, 0x38);
-    // Wait 26.3us
-    wait_ms(1);
-    // Function set = 0x39
-    put(CMD, 0x39);
-    // Wait 26.3us
-    wait_ms(1);
-    // Internal OSC frequency = 0x14
-    put(CMD, 0x14);
-    // Wait 26.3us
-    wait_ms(1);
-    // Contrast set = 0x70
-    put(CMD, 0x70);
-    // Wait 26.3us
-    wait_ms(1);
-    // Power/ICON/Contrast control = 0x56
-    put(CMD, 0x56);
-    // Wait 26.3us
-    wait_ms(1);
-    // Follower control = 0x6C
-    put(CMD, 0x6C);
-    // Wait 200ms
-    wait_ms(200);
-    // Function set = 0x38
-    put(CMD, 0x38);
-    // Wait 26.3us
-    wait_ms(1);
-    // Display ON/OFF control = 0x0C
-    put(CMD, 0x0C);
-    // Wait 26.3us
-    wait_ms(1);
-    // Clear Display = 0x01
-    put(CMD, 0x01);
-    // Wait 1.08ms
-    wait_ms(2);
-
-}
-
-
-
diff -r 8dfee9f6df54 -r b72b39a47d1a AQM0802.h
--- a/AQM0802.h	Sun Jun 22 09:57:23 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-//**********************
-// AQM0802.h for mbed
-//
-// (C)Copyright 2014 All rights reserved by Y.Onodera
-// http://einstlab.web.fc2.com
-//**********************
-
-#ifndef AQM0802_H_
-#define AQM0802_H_
-
-#define AQM0802_ADDR    0x7c
-#define CMD 0x00
-#define DAT 0x40
-
-#include "mbed.h"
-
-//class AQM0802: public Stream{
-class AQM0802{
-public:
-    AQM0802 (PinName sda, PinName scl);
-    AQM0802 (I2C& p_i2c);
-    void init();
-
-    void put(unsigned char a, unsigned char b);
-    void get(unsigned char a);
-    void cls();
-    void locate (int x, int y);
-    void print (const char* a);
-
-protected:
-    
-    I2C _i2c;
-//    virtual int _putc(int value);
-//    virtual int _getc();
-
-    char buf[2];
-
-};
-
-
-#endif /* AQM0802_H_ */
-
diff -r 8dfee9f6df54 -r b72b39a47d1a AQM0802.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AQM0802.lib	Thu Jun 26 13:48:05 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/yasuyuki/code/AQM0802/#6fa303916aa8
diff -r 8dfee9f6df54 -r b72b39a47d1a EEPROM.cpp
--- a/EEPROM.cpp	Sun Jun 22 09:57:23 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-//**********************
-// EEPROM.cpp for TG-LPC11U35-501
-// TG-LPC11U35-501 has 4K EEPROM.
-// 
-// usage:
-// EEPROM eeprom;
-// char RAM[100]
-// eeprom.write(0, RAM, 100);
-// eeprom.read(0, RAM, 100);
-// eeprom.put(0, 0x00);
-// i=eeprom.get(0);
-//
-// note:
-// valid EEPROM address range is between 0 to 4031
-// top 64 bytes are reserved
-//
-// (C)Copyright 2014 All rights reserved by Y.Onodera
-// http://einstlab.web.fc2.com
-//**********************
-#include "EEPROM.h"
-
-int EEPROM::write( unsigned int EEPROM_addr, char *RAM_addr, unsigned int n ) {
-    command[0] = EEPROM_Write;
-    command[1] = EEPROM_addr;
-    command[2] = (unsigned int)RAM_addr;
-    command[3] = n;
-    command[4] = cclk_kHz;
- 
-    iap_entry( command, status );
- 
-    return ( (int)status[0] );
-}
-
-
-int EEPROM::read( unsigned int EEPROM_addr, char *RAM_addr, unsigned int n ) {
-    command[0] = EEPROM_Read;    
-    command[1] = EEPROM_addr;
-    command[2] = (unsigned int)RAM_addr;
-    command[3] = n;
-    command[4] = cclk_kHz;
- 
-    iap_entry( command, status );
- 
-    return ( (int)status[0] );
-}
-
-
-int EEPROM::put( unsigned int EEPROM_addr, char data ) {
-    dat[0]=data;
-    command[0] = EEPROM_Write;
-    command[1] = EEPROM_addr;
-    command[2] = (unsigned int)dat;
-    command[3] = 1;
-    command[4] = cclk_kHz;
- 
-    iap_entry( command, status );
- 
-    return ( (int)status[0] );
-}
-
-
-char EEPROM::get( unsigned int EEPROM_addr ) {
-    command[0] = EEPROM_Read;    
-    command[1] = EEPROM_addr;
-    command[2] = (unsigned int)dat;
-    command[3] = 1;
-    command[4] = cclk_kHz;
- 
-    iap_entry( command, status );
- 
-    return ( dat[0] );
-}
diff -r 8dfee9f6df54 -r b72b39a47d1a EEPROM.h
--- a/EEPROM.h	Sun Jun 22 09:57:23 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-//**********************
-// EEPROM.h for TG-LPC11U35-501
-//
-// (C)Copyright 2014 All rights reserved by Y.Onodera
-// http://einstlab.web.fc2.com
-//**********************
-
-#ifndef __ROMAPI_11U35_H_
-#define __ROMAPI_11U35_H_
-
-#include "mbed.h"
-
-typedef enum {
-    CMD_SUCCESS = 0,            // Command is executed successfully.
-    INVALID_COMMAND = 1,        // Invalid command.
-    SRC_ADDR_ERROR = 2,         // Source address is not on a word boundary.
-    DST_ADDR_ERROR = 3,         // Destination address is not on a correct boundary.
-    SRC_ADDR_NOT_MAPPED = 4,    // Source address is not mapped in the memory map.
-    DST_ADDR_NOT_MAPPED = 5,    // Destination address is not mapped in the memory map. 
-    COUNT_ERROR = 6,            // Byte count is not multiple of 4 or is not a permitted value.
-    INVALID_SECTOR = 7,         // Sector number is invalid.
-    SECTOR_NOT_BLANK = 8,       // Sector is not blank.
-    SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION = 9,    // Command to prepare sector for write operation was not executed.
-    COMPARE_ERROR =10,          // Source and destination data is not same.
-    BUSY = 11                   // flash programming hardware interface is busy.
-} IAPstatus;
-
-
-typedef enum {
-    Prepare_sector = 50,
-    Copy_RAM_flash = 51,
-    Erase_sector = 52,
-    Blank_check_sector = 53,
-    Read_Part_ID = 54,
-    Read_Boot_version = 55,
-    Compare = 56,
-    Reinvoke_ISP = 57,
-    Read_UID = 58,
-    Erase_page = 59,
-    EEPROM_Write = 61,
-    EEPROM_Read = 62
-} IAPcommand;
-
-
-#define IAP_LOCATION (0x1FFF1FF1UL)
-typedef void (*IAP)(unsigned int[], unsigned int[]);
-
-
-class EEPROM {
-public:
-    EEPROM() : iap_entry( reinterpret_cast<IAP>(IAP_LOCATION) ), cclk_kHz( SystemCoreClock / 1000 ) {}
-
-    int write( unsigned int EEPROM_addr, char *RAM_addr, unsigned int n );
-    int read( unsigned int EEPROM_addr, char *RAM_addr, unsigned int n );
-    int put( unsigned int EEPROM_addr, char data );
-    char get( unsigned int EEPROM_addr );
- 
-private:
-    IAP             iap_entry;
-    unsigned int    command[5];
-    unsigned int    status[4];
-    char            dat[1];
-    int             cclk_kHz;
-};
-
-
-#endif /* __ROMAPI_11U35_H_ */
diff -r 8dfee9f6df54 -r b72b39a47d1a EEPROM.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EEPROM.lib	Thu Jun 26 13:48:05 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/yasuyuki/code/EEPROM/#25e5bc71e65f