How to use EEPROM in TG-LPC11U35-501

Dependencies:   AQM0802 EEPROM mbed

Committer:
yasuyuki
Date:
Sun Jun 22 09:57:23 2014 +0000
Revision:
0:8dfee9f6df54
first revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yasuyuki 0:8dfee9f6df54 1 //**********************
yasuyuki 0:8dfee9f6df54 2 // AQM0802.cpp for mbed
yasuyuki 0:8dfee9f6df54 3 //
yasuyuki 0:8dfee9f6df54 4 // AQM0802 lcd(P0_5,P0_4);
yasuyuki 0:8dfee9f6df54 5 // or
yasuyuki 0:8dfee9f6df54 6 // I2C i2c(P0_5,P0_4);
yasuyuki 0:8dfee9f6df54 7 // AQM0802 lcd(i2c);
yasuyuki 0:8dfee9f6df54 8 //
yasuyuki 0:8dfee9f6df54 9 // (C)Copyright 2014 All rights reserved by Y.Onodera
yasuyuki 0:8dfee9f6df54 10 // http://einstlab.web.fc2.com
yasuyuki 0:8dfee9f6df54 11 //**********************
yasuyuki 0:8dfee9f6df54 12
yasuyuki 0:8dfee9f6df54 13 #include "mbed.h"
yasuyuki 0:8dfee9f6df54 14 #include "AQM0802.h"
yasuyuki 0:8dfee9f6df54 15
yasuyuki 0:8dfee9f6df54 16 AQM0802::AQM0802 (PinName sda, PinName scl) : _i2c(sda, scl) {
yasuyuki 0:8dfee9f6df54 17 init();
yasuyuki 0:8dfee9f6df54 18 }
yasuyuki 0:8dfee9f6df54 19 AQM0802::AQM0802 (I2C& p_i2c) : _i2c(p_i2c) {
yasuyuki 0:8dfee9f6df54 20 init();
yasuyuki 0:8dfee9f6df54 21 }
yasuyuki 0:8dfee9f6df54 22
yasuyuki 0:8dfee9f6df54 23 void AQM0802::put(unsigned char a, unsigned char b)
yasuyuki 0:8dfee9f6df54 24 {
yasuyuki 0:8dfee9f6df54 25 buf[0]=a;
yasuyuki 0:8dfee9f6df54 26 buf[1]=b;
yasuyuki 0:8dfee9f6df54 27 _i2c.write(AQM0802_ADDR, buf, 2);
yasuyuki 0:8dfee9f6df54 28 }
yasuyuki 0:8dfee9f6df54 29
yasuyuki 0:8dfee9f6df54 30
yasuyuki 0:8dfee9f6df54 31 void AQM0802::get(unsigned char a)
yasuyuki 0:8dfee9f6df54 32 {
yasuyuki 0:8dfee9f6df54 33 buf[0] = a;
yasuyuki 0:8dfee9f6df54 34 _i2c.write(AQM0802_ADDR, buf, 1, true); // no stop, repeated
yasuyuki 0:8dfee9f6df54 35 _i2c.read( AQM0802_ADDR, buf, 1);
yasuyuki 0:8dfee9f6df54 36
yasuyuki 0:8dfee9f6df54 37 }
yasuyuki 0:8dfee9f6df54 38
yasuyuki 0:8dfee9f6df54 39 void AQM0802::cls()
yasuyuki 0:8dfee9f6df54 40 {
yasuyuki 0:8dfee9f6df54 41 // Clear Display = 0x01
yasuyuki 0:8dfee9f6df54 42 put(CMD, 0x01);
yasuyuki 0:8dfee9f6df54 43 // Wait 1.08ms
yasuyuki 0:8dfee9f6df54 44 wait_ms(2);
yasuyuki 0:8dfee9f6df54 45
yasuyuki 0:8dfee9f6df54 46 }
yasuyuki 0:8dfee9f6df54 47
yasuyuki 0:8dfee9f6df54 48 void AQM0802::locate(int x, int y)
yasuyuki 0:8dfee9f6df54 49 {
yasuyuki 0:8dfee9f6df54 50
yasuyuki 0:8dfee9f6df54 51 // 8x2
yasuyuki 0:8dfee9f6df54 52 put(CMD, 0x80 + y*0x40 + x);
yasuyuki 0:8dfee9f6df54 53
yasuyuki 0:8dfee9f6df54 54 }
yasuyuki 0:8dfee9f6df54 55
yasuyuki 0:8dfee9f6df54 56 void AQM0802::print(const char *a)
yasuyuki 0:8dfee9f6df54 57 {
yasuyuki 0:8dfee9f6df54 58
yasuyuki 0:8dfee9f6df54 59 while(*a != '\0')
yasuyuki 0:8dfee9f6df54 60 {
yasuyuki 0:8dfee9f6df54 61 put(DAT, *a);
yasuyuki 0:8dfee9f6df54 62 a++;
yasuyuki 0:8dfee9f6df54 63 }
yasuyuki 0:8dfee9f6df54 64
yasuyuki 0:8dfee9f6df54 65 }
yasuyuki 0:8dfee9f6df54 66
yasuyuki 0:8dfee9f6df54 67 void AQM0802::init()
yasuyuki 0:8dfee9f6df54 68 {
yasuyuki 0:8dfee9f6df54 69 // Wait 40ms
yasuyuki 0:8dfee9f6df54 70 wait_ms(100);
yasuyuki 0:8dfee9f6df54 71 // Function set = 0x38
yasuyuki 0:8dfee9f6df54 72 put(CMD, 0x38);
yasuyuki 0:8dfee9f6df54 73 // Wait 26.3us
yasuyuki 0:8dfee9f6df54 74 wait_ms(1);
yasuyuki 0:8dfee9f6df54 75 // Function set = 0x39
yasuyuki 0:8dfee9f6df54 76 put(CMD, 0x39);
yasuyuki 0:8dfee9f6df54 77 // Wait 26.3us
yasuyuki 0:8dfee9f6df54 78 wait_ms(1);
yasuyuki 0:8dfee9f6df54 79 // Internal OSC frequency = 0x14
yasuyuki 0:8dfee9f6df54 80 put(CMD, 0x14);
yasuyuki 0:8dfee9f6df54 81 // Wait 26.3us
yasuyuki 0:8dfee9f6df54 82 wait_ms(1);
yasuyuki 0:8dfee9f6df54 83 // Contrast set = 0x70
yasuyuki 0:8dfee9f6df54 84 put(CMD, 0x70);
yasuyuki 0:8dfee9f6df54 85 // Wait 26.3us
yasuyuki 0:8dfee9f6df54 86 wait_ms(1);
yasuyuki 0:8dfee9f6df54 87 // Power/ICON/Contrast control = 0x56
yasuyuki 0:8dfee9f6df54 88 put(CMD, 0x56);
yasuyuki 0:8dfee9f6df54 89 // Wait 26.3us
yasuyuki 0:8dfee9f6df54 90 wait_ms(1);
yasuyuki 0:8dfee9f6df54 91 // Follower control = 0x6C
yasuyuki 0:8dfee9f6df54 92 put(CMD, 0x6C);
yasuyuki 0:8dfee9f6df54 93 // Wait 200ms
yasuyuki 0:8dfee9f6df54 94 wait_ms(200);
yasuyuki 0:8dfee9f6df54 95 // Function set = 0x38
yasuyuki 0:8dfee9f6df54 96 put(CMD, 0x38);
yasuyuki 0:8dfee9f6df54 97 // Wait 26.3us
yasuyuki 0:8dfee9f6df54 98 wait_ms(1);
yasuyuki 0:8dfee9f6df54 99 // Display ON/OFF control = 0x0C
yasuyuki 0:8dfee9f6df54 100 put(CMD, 0x0C);
yasuyuki 0:8dfee9f6df54 101 // Wait 26.3us
yasuyuki 0:8dfee9f6df54 102 wait_ms(1);
yasuyuki 0:8dfee9f6df54 103 // Clear Display = 0x01
yasuyuki 0:8dfee9f6df54 104 put(CMD, 0x01);
yasuyuki 0:8dfee9f6df54 105 // Wait 1.08ms
yasuyuki 0:8dfee9f6df54 106 wait_ms(2);
yasuyuki 0:8dfee9f6df54 107
yasuyuki 0:8dfee9f6df54 108 }
yasuyuki 0:8dfee9f6df54 109
yasuyuki 0:8dfee9f6df54 110
yasuyuki 0:8dfee9f6df54 111