SMS Scheduler that will automatically send and receive text messages using the Enfora 1308 GSM Modem. Please note that it uses a modified NetServices library and to set the baud rate for the GSM Modem to 19.2K.

Dependencies:   mbed

Committer:
mafischl
Date:
Thu Oct 13 18:01:31 2011 +0000
Revision:
1:5a7cce9994a3
Parent:
0:d9266031f832

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mafischl 0:d9266031f832 1 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
mafischl 0:d9266031f832 2 * Copyright (c) 2007-2010, sford, http://mbed.org
mafischl 0:d9266031f832 3 *
mafischl 0:d9266031f832 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mafischl 0:d9266031f832 5 * of this software and associated documentation files (the "Software"), to deal
mafischl 0:d9266031f832 6 * in the Software without restriction, including without limitation the rights
mafischl 0:d9266031f832 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mafischl 0:d9266031f832 8 * copies of the Software, and to permit persons to whom the Software is
mafischl 0:d9266031f832 9 * furnished to do so, subject to the following conditions:
mafischl 0:d9266031f832 10 *
mafischl 0:d9266031f832 11 * The above copyright notice and this permission notice shall be included in
mafischl 0:d9266031f832 12 * all copies or substantial portions of the Software.
mafischl 0:d9266031f832 13 *
mafischl 0:d9266031f832 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mafischl 0:d9266031f832 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mafischl 0:d9266031f832 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mafischl 0:d9266031f832 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mafischl 0:d9266031f832 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mafischl 0:d9266031f832 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mafischl 0:d9266031f832 20 * THE SOFTWARE.
mafischl 0:d9266031f832 21 */
mafischl 0:d9266031f832 22
mafischl 0:d9266031f832 23 #include "TextLCD.h"
mafischl 0:d9266031f832 24 #include "mbed.h"
mafischl 0:d9266031f832 25
mafischl 0:d9266031f832 26 TextLCD::TextLCD(PinName rs, PinName e, PinName d0, PinName d1,
mafischl 0:d9266031f832 27 PinName d2, PinName d3, LCDType type) : _rs(rs),
mafischl 0:d9266031f832 28 _e(e), _d(d0, d1, d2, d3),
mafischl 0:d9266031f832 29 _type(type) {
mafischl 0:d9266031f832 30
mafischl 0:d9266031f832 31 _e = 1;
mafischl 0:d9266031f832 32 _rs = 0; // command mode
mafischl 0:d9266031f832 33
mafischl 0:d9266031f832 34 wait(0.015); // Wait 15ms to ensure powered up
mafischl 0:d9266031f832 35
mafischl 0:d9266031f832 36 // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
mafischl 0:d9266031f832 37 for (int i=0; i<3; i++) {
mafischl 0:d9266031f832 38 writeByte(0x3);
mafischl 0:d9266031f832 39 wait(0.00164); // this command takes 1.64ms, so wait for it
mafischl 0:d9266031f832 40 }
mafischl 0:d9266031f832 41 writeByte(0x2); // 4-bit mode
mafischl 0:d9266031f832 42 wait(0.000040f); // most instructions take 40us
mafischl 0:d9266031f832 43
mafischl 0:d9266031f832 44 writeCommand(0x28); // Function set 001 BW N F - -
mafischl 0:d9266031f832 45 writeCommand(0x0C);
mafischl 0:d9266031f832 46 writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
mafischl 0:d9266031f832 47 cls();
mafischl 0:d9266031f832 48 }
mafischl 0:d9266031f832 49
mafischl 0:d9266031f832 50 void TextLCD::character(int column, int row, int c) {
mafischl 0:d9266031f832 51 int a = address(column, row);
mafischl 0:d9266031f832 52 writeCommand(a);
mafischl 0:d9266031f832 53 writeData(c);
mafischl 0:d9266031f832 54 }
mafischl 0:d9266031f832 55
mafischl 0:d9266031f832 56 void TextLCD::cls() {
mafischl 0:d9266031f832 57 writeCommand(0x01); // cls, and set cursor to 0
mafischl 0:d9266031f832 58 wait(0.00164f); // This command takes 1.64 ms
mafischl 0:d9266031f832 59 locate(0, 0);
mafischl 0:d9266031f832 60 }
mafischl 0:d9266031f832 61
mafischl 0:d9266031f832 62 void TextLCD::locate(int column, int row) {
mafischl 0:d9266031f832 63 _column = column;
mafischl 0:d9266031f832 64 _row = row;
mafischl 0:d9266031f832 65 }
mafischl 0:d9266031f832 66
mafischl 0:d9266031f832 67 int TextLCD::_putc(int value) {
mafischl 0:d9266031f832 68 if (value == '\n') {
mafischl 0:d9266031f832 69 _column = 0;
mafischl 0:d9266031f832 70 _row++;
mafischl 0:d9266031f832 71 if (_row >= rows()) {
mafischl 0:d9266031f832 72 _row = 0;
mafischl 0:d9266031f832 73 }
mafischl 0:d9266031f832 74 } else {
mafischl 0:d9266031f832 75 character(_column, _row, value);
mafischl 0:d9266031f832 76 _column++;
mafischl 0:d9266031f832 77 if (_column >= columns()) {
mafischl 0:d9266031f832 78 _column = 0;
mafischl 0:d9266031f832 79 _row++;
mafischl 0:d9266031f832 80 if (_row >= rows()) {
mafischl 0:d9266031f832 81 _row = 0;
mafischl 0:d9266031f832 82 }
mafischl 0:d9266031f832 83 }
mafischl 0:d9266031f832 84 }
mafischl 0:d9266031f832 85 return value;
mafischl 0:d9266031f832 86 }
mafischl 0:d9266031f832 87
mafischl 0:d9266031f832 88 int TextLCD::_getc() {
mafischl 0:d9266031f832 89 return -1;
mafischl 0:d9266031f832 90 }
mafischl 0:d9266031f832 91
mafischl 0:d9266031f832 92 void TextLCD::writeByte(int value) {
mafischl 0:d9266031f832 93 _d = value >> 4;
mafischl 0:d9266031f832 94 wait(0.000040f); // most instructions take 40us
mafischl 0:d9266031f832 95 _e = 0;
mafischl 0:d9266031f832 96 wait(0.000040f);
mafischl 0:d9266031f832 97 _e = 1;
mafischl 0:d9266031f832 98 _d = value >> 0;
mafischl 0:d9266031f832 99 wait(0.000040f);
mafischl 0:d9266031f832 100 _e = 0;
mafischl 0:d9266031f832 101 wait(0.000040f); // most instructions take 40us
mafischl 0:d9266031f832 102 _e = 1;
mafischl 0:d9266031f832 103 }
mafischl 0:d9266031f832 104
mafischl 0:d9266031f832 105 void TextLCD::writeCommand(int command) {
mafischl 0:d9266031f832 106 _rs = 0;
mafischl 0:d9266031f832 107 writeByte(command);
mafischl 0:d9266031f832 108 }
mafischl 0:d9266031f832 109
mafischl 0:d9266031f832 110 void TextLCD::writeData(int data) {
mafischl 0:d9266031f832 111 _rs = 1;
mafischl 0:d9266031f832 112 writeByte(data);
mafischl 0:d9266031f832 113 }
mafischl 0:d9266031f832 114
mafischl 0:d9266031f832 115 int TextLCD::address(int column, int row) {
mafischl 0:d9266031f832 116 switch (_type) {
mafischl 0:d9266031f832 117 case LCD20x4:
mafischl 0:d9266031f832 118 switch (row) {
mafischl 0:d9266031f832 119 case 0:
mafischl 0:d9266031f832 120 return 0x80 + column;
mafischl 0:d9266031f832 121 case 1:
mafischl 0:d9266031f832 122 return 0xc0 + column;
mafischl 0:d9266031f832 123 case 2:
mafischl 0:d9266031f832 124 return 0x94 + column;
mafischl 0:d9266031f832 125 case 3:
mafischl 0:d9266031f832 126 return 0xd4 + column;
mafischl 0:d9266031f832 127 }
mafischl 0:d9266031f832 128 case LCD16x2B:
mafischl 0:d9266031f832 129 return 0x80 + (row * 40) + column;
mafischl 0:d9266031f832 130 case LCD16x2:
mafischl 0:d9266031f832 131 case LCD20x2:
mafischl 0:d9266031f832 132 default:
mafischl 0:d9266031f832 133 return 0x80 + (row * 0x40) + column;
mafischl 0:d9266031f832 134 }
mafischl 0:d9266031f832 135 }
mafischl 0:d9266031f832 136
mafischl 0:d9266031f832 137 int TextLCD::columns() {
mafischl 0:d9266031f832 138 switch (_type) {
mafischl 0:d9266031f832 139 case LCD20x4:
mafischl 0:d9266031f832 140 case LCD20x2:
mafischl 0:d9266031f832 141 return 20;
mafischl 0:d9266031f832 142 case LCD16x2:
mafischl 0:d9266031f832 143 case LCD16x2B:
mafischl 0:d9266031f832 144 default:
mafischl 0:d9266031f832 145 return 16;
mafischl 0:d9266031f832 146 }
mafischl 0:d9266031f832 147 }
mafischl 0:d9266031f832 148
mafischl 0:d9266031f832 149 int TextLCD::rows() {
mafischl 0:d9266031f832 150 switch (_type) {
mafischl 0:d9266031f832 151 case LCD20x4:
mafischl 0:d9266031f832 152 return 4;
mafischl 0:d9266031f832 153 case LCD16x2:
mafischl 0:d9266031f832 154 case LCD16x2B:
mafischl 0:d9266031f832 155 case LCD20x2:
mafischl 0:d9266031f832 156 default:
mafischl 0:d9266031f832 157 return 2;
mafischl 0:d9266031f832 158 }
mafischl 0:d9266031f832 159 }