nlgplay for mbed

Dependencies:   SDFileSystemEx mbed

Committer:
bkc_mbed
Date:
Wed Sep 17 23:29:07 2014 +0000
Revision:
11:68032f2a11b9
Parent:
7:7e183b33c3f9
added com mode.(untested)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bkc_mbed8:88c89fd324bd 1/*
bkc_mbed8:88c89fd324bd 2 * lcd.cpp : AQM0802A mini library
bkc_mbed8:88c89fd324bd 3 *
bkc_mbed8:88c89fd324bd 4 * Based on LCD module "AQM0802A-RN-GBW" sample program
bkc_mbed8:88c89fd324bd 5 * Copyright (c) 2013 Yoshihiro TSUBOI
bkc_mbed8:88c89fd324bd 6 *
bkc_mbed8:88c89fd324bd 7 * Original Arduino version was developed by
bkc_mbed8:88c89fd324bd 8 * Copyright (c) 2013 Masahiro WAKAYAMA at SWITCH SCIENCE
bkc_mbed8:88c89fd324bd 9 *
bkc_mbed8:88c89fd324bd 10 * Released under the MIT License: http://mbed.org/license/mit
bkc_mbed8:88c89fd324bd 11 *
bkc_mbed8:88c89fd324bd 12 */
bkc_mbed8:88c89fd324bd 13
bkc_mbed0:2053640461b5 14#include "mbed.h"
bkc_mbed0:2053640461b5 15
bkc_mbed0:2053640461b5 16I2C i2c(dp5, dp27); // sda, scl
bkc_mbed0:2053640461b5 17
bkc_mbed0:2053640461b5 18const int AQM0802_addr = 0x7C;
bkc_mbed0:2053640461b5 19
bkc_mbed0:2053640461b5 20void lcd_cmd(char x)
bkc_mbed0:2053640461b5 21{
bkc_mbed0:2053640461b5 22 char data[2];
bkc_mbed0:2053640461b5 23 data[0] = 0x00; // CO = 0,RS = 0
bkc_mbed0:2053640461b5 24 data[1] = x;
bkc_mbed0:2053640461b5 25 i2c.write(AQM0802_addr, data, 2);
bkc_mbed0:2053640461b5 26}
bkc_mbed0:2053640461b5 27
bkc_mbed0:2053640461b5 28void lcd_contdata(char x)
bkc_mbed0:2053640461b5 29{
bkc_mbed0:2053640461b5 30 char data[2];
bkc_mbed0:2053640461b5 31 data[0] = 0xC0; //0b11000000 CO = 1, RS = 1
bkc_mbed0:2053640461b5 32 data[1] = x;
bkc_mbed0:2053640461b5 33 i2c.write(AQM0802_addr, data, 2);
bkc_mbed0:2053640461b5 34}
bkc_mbed0:2053640461b5 35
bkc_mbed0:2053640461b5 36void lcd_lastdata(char x)
bkc_mbed0:2053640461b5 37{
bkc_mbed0:2053640461b5 38 char data[2];
bkc_mbed0:2053640461b5 39 data[0] = 0x40; //0b11000000 CO = 0, RS = 1
bkc_mbed0:2053640461b5 40 data[1] = x;
bkc_mbed0:2053640461b5 41 i2c.write(AQM0802_addr, data, 2);
bkc_mbed0:2053640461b5 42}
bkc_mbed0:2053640461b5 43
bkc_mbed7:7e183b33c3f9 44void lcd_printStrFill(const char *s)
bkc_mbed7:7e183b33c3f9 45{
bkc_mbed7:7e183b33c3f9 46 int idx = 0;
bkc_mbed7:7e183b33c3f9 47 for(idx = 0; idx < 8; idx++)
bkc_mbed7:7e183b33c3f9 48 {
bkc_mbed7:7e183b33c3f9 49 if(idx < 7) {
bkc_mbed7:7e183b33c3f9 50 lcd_contdata(*s);
bkc_mbed7:7e183b33c3f9 51 } else {
bkc_mbed7:7e183b33c3f9 52 lcd_lastdata(*s);
bkc_mbed7:7e183b33c3f9 53 }
bkc_mbed7:7e183b33c3f9 54 if (*s) s++;
bkc_mbed7:7e183b33c3f9 55 }
bkc_mbed7:7e183b33c3f9 56}
bkc_mbed7:7e183b33c3f9 57
bkc_mbed7:7e183b33c3f9 58
bkc_mbed0:2053640461b5 59void lcd_printStr(const char *s)
bkc_mbed0:2053640461b5 60{
bkc_mbed1:ec416e6d5739 61 int idx = 0;
bkc_mbed1:ec416e6d5739 62 while(*s && idx < 8) {
bkc_mbed0:2053640461b5 63 if(*(s + 1)) {
bkc_mbed0:2053640461b5 64 lcd_contdata(*s);
bkc_mbed0:2053640461b5 65 } else {
bkc_mbed0:2053640461b5 66 lcd_lastdata(*s);
bkc_mbed0:2053640461b5 67 }
bkc_mbed0:2053640461b5 68 s++;
bkc_mbed1:ec416e6d5739 69 idx++;
bkc_mbed0:2053640461b5 70 }
bkc_mbed0:2053640461b5 71}
bkc_mbed0:2053640461b5 72
bkc_mbed0:2053640461b5 73void lcd_setContrast(unsigned char c) {
bkc_mbed0:2053640461b5 74 lcd_cmd(0x39);
bkc_mbed0:2053640461b5 75 lcd_cmd(0x70 | (c & 0x0f)); // contrast Low
bkc_mbed0:2053640461b5 76 lcd_cmd(0x5C | ((c >> 4) & 0x03)); // contast High/icon/power
bkc_mbed0:2053640461b5 77 lcd_cmd(0x38);
bkc_mbed0:2053640461b5 78}
bkc_mbed0:2053640461b5 79
bkc_mbed0:2053640461b5 80void lcd_printHex(unsigned char num)
bkc_mbed0:2053640461b5 81{
bkc_mbed0:2053640461b5 82 lcd_contdata(num);
bkc_mbed0:2053640461b5 83}
bkc_mbed0:2053640461b5 84
bkc_mbed0:2053640461b5 85void lcd_init() {
bkc_mbed0:2053640461b5 86 int cont = 0;
bkc_mbed0:2053640461b5 87 wait(0.04);
bkc_mbed0:2053640461b5 88 // LCD initialize
bkc_mbed0:2053640461b5 89 lcd_cmd(0x38); // function set
bkc_mbed0:2053640461b5 90 lcd_cmd(0x39); // function set
bkc_mbed0:2053640461b5 91 lcd_cmd(0x04); // EntryModeSet
bkc_mbed0:2053640461b5 92 lcd_cmd(0x14); // interval osc
bkc_mbed0:2053640461b5 93 lcd_cmd(0x70 | (cont & 0xF)); // contrast Low
bkc_mbed0:2053640461b5 94 lcd_cmd(0x5C | ((cont >> 4) & 0x3)); // contast High/icon/power
bkc_mbed0:2053640461b5 95 lcd_cmd(0x6C); // follower control
bkc_mbed0:2053640461b5 96 wait(0.2);
bkc_mbed0:2053640461b5 97 lcd_cmd(0x38); // function set
bkc_mbed0:2053640461b5 98 lcd_cmd(0x0C); // Display On
bkc_mbed0:2053640461b5 99 lcd_cmd(0x01); // Clear Display
bkc_mbed0:2053640461b5 100 wait(0.2); // need additional wait to Clear Display
bkc_mbed0:2053640461b5 101
bkc_mbed0:2053640461b5 102 lcd_setContrast(36);
bkc_mbed0:2053640461b5 103
bkc_mbed0:2053640461b5 104}
bkc_mbed0:2053640461b5 105
bkc_mbed0:2053640461b5 106void lcd_setCursor(unsigned char x,unsigned char y) {
bkc_mbed0:2053640461b5 107 lcd_cmd(0x80 | (y * 0x40 + x));
bkc_mbed0:2053640461b5 108}
bkc_mbed0:2053640461b5 109
bkc_mbed1:ec416e6d5739 110
bkc_mbed1:ec416e6d5739 111void lcd_printStrY(int y,const char *s)
bkc_mbed1:ec416e6d5739 112{
bkc_mbed7:7e183b33c3f9 113 lcd_setCursor(0, y);
bkc_mbed7:7e183b33c3f9 114 lcd_printStrFill(s);
bkc_mbed1:ec416e6d5739 115}
bkc_mbed1:ec416e6d5739 116
bkc_mbed1:ec416e6d5739 117void lcd_printStrYscr(int y,const char *s)
bkc_mbed1:ec416e6d5739 118{
bkc_mbed1:ec416e6d5739 119 int cnt = strlen(s) - 7;
bkc_mbed1:ec416e6d5739 120 if (cnt <= 0)
bkc_mbed1:ec416e6d5739 121 cnt = 1;
bkc_mbed1:ec416e6d5739 122
bkc_mbed1:ec416e6d5739 123 for(int i = 0; i < cnt; i++)
bkc_mbed1:ec416e6d5739 124 {
bkc_mbed1:ec416e6d5739 125 lcd_setCursor(0, y);
bkc_mbed1:ec416e6d5739 126 lcd_printStr(s + i);
bkc_mbed1:ec416e6d5739 127 wait(0.5);
bkc_mbed1:ec416e6d5739 128 }
bkc_mbed1:ec416e6d5739 129}
bkc_mbed1:ec416e6d5739 130
bkc_mbed1:ec416e6d5739 131
bkc_mbed1:ec416e6d5739 132void lcd_printStr2(const char *s, const char *s2)
bkc_mbed1:ec416e6d5739 133{
bkc_mbed1:ec416e6d5739 134 lcd_setCursor(0,0);
bkc_mbed7:7e183b33c3f9 135 lcd_printStrFill(s);
bkc_mbed1:ec416e6d5739 136 lcd_setCursor(0,1);
bkc_mbed7:7e183b33c3f9 137 lcd_printStrFill(s2);
bkc_mbed1:ec416e6d5739 138}
bkc_mbed1:ec416e6d5739 139
bkc_mbed0:2053640461b5 140void lcd_cls(void)
bkc_mbed0:2053640461b5 141{
bkc_mbed0:2053640461b5 142 lcd_setCursor(0, 0);
bkc_mbed7:7e183b33c3f9 143 lcd_printStrFill("");
bkc_mbed0:2053640461b5 144 lcd_setCursor(0, 1);
bkc_mbed7:7e183b33c3f9 145 lcd_printStrFill("");
bkc_mbed0:2053640461b5 146}
bkc_mbed0:2053640461b5 147