
lcd,gsm
Revision 0:fb0aa840a7cd, committed 2013-05-01
- Comitter:
- HarishMekali
- Date:
- Wed May 01 05:36:38 2013 +0000
- Commit message:
- wsm
Changed in this revision
diff -r 000000000000 -r fb0aa840a7cd TextLCD.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.cpp Wed May 01 05:36:38 2013 +0000 @@ -0,0 +1,159 @@ +/* mbed TextLCD Library, for a 4-bit LCD based on HD44780 + * Copyright (c) 2007-2010, sford + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "TextLCD.h" +#include "mbed.h" + +TextLCD::TextLCD(PinName rs, PinName e, PinName d0, PinName d1, + PinName d2, PinName d3, LCDType type) : _rs(rs), + _e(e), _d(d0, d1, d2, d3), + _type(type) { + + _e = 1; + _rs = 0; // command mode + + wait(0.015); // Wait 15ms to ensure powered up + + // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus) + for (int i=0; i<3; i++) { + writeByte(0x3); + wait(0.00164); // this command takes 1.64ms, so wait for it + } + writeByte(0x2); // 4-bit mode + wait(0.000040f); // most instructions take 40us + + writeCommand(0x28); // Function set 001 BW N F - - + writeCommand(0x0C); + writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes + cls(); +} + +void TextLCD::character(int column, int row, int c) { + int a = address(column, row); + writeCommand(a); + writeData(c); +} + +void TextLCD::cls() { + writeCommand(0x01); // cls, and set cursor to 0 + wait(0.00164f); // This command takes 1.64 ms + locate(0, 0); +} + +void TextLCD::locate(int column, int row) { + _column = column; + _row = row; +} + +int TextLCD::_putc(int value) { + if (value == '\n') { + _column = 0; + _row++; + if (_row >= rows()) { + _row = 0; + } + } else { + character(_column, _row, value); + _column++; + if (_column >= columns()) { + _column = 0; + _row++; + if (_row >= rows()) { + _row = 0; + } + } + } + return value; +} + +int TextLCD::_getc() { + return -1; +} + +void TextLCD::writeByte(int value) { + _d = value >> 4; + wait(0.000040f); // most instructions take 40us + _e = 0; + wait(0.000040f); + _e = 1; + _d = value >> 0; + wait(0.000040f); + _e = 0; + wait(0.000040f); // most instructions take 40us + _e = 1; +} + +void TextLCD::writeCommand(int command) { + _rs = 0; + writeByte(command); +} + +void TextLCD::writeData(int data) { + _rs = 1; + writeByte(data); +} + +int TextLCD::address(int column, int row) { + switch (_type) { + case LCD20x4: + switch (row) { + case 0: + return 0x80 + column; + case 1: + return 0xc0 + column; + case 2: + return 0x94 + column; + case 3: + return 0xd4 + column; + } + case LCD16x2B: + return 0x80 + (row * 40) + column; + case LCD16x2: + case LCD20x2: + default: + return 0x80 + (row * 0x40) + column; + } +} + +int TextLCD::columns() { + switch (_type) { + case LCD20x4: + case LCD20x2: + return 20; + case LCD16x2: + case LCD16x2B: + default: + return 16; + } +} + +int TextLCD::rows() { + switch (_type) { + case LCD20x4: + return 4; + case LCD16x2: + case LCD16x2B: + case LCD20x2: + default: + return 2; + } +}
diff -r 000000000000 -r fb0aa840a7cd TextLCD.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.h Wed May 01 05:36:38 2013 +0000 @@ -0,0 +1,111 @@ +/* mbed TextLCD Library, for a 4-bit LCD based on HD44780 + * Copyright (c) 2007-2010, sford + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MBED_TEXTLCD_H +#define MBED_TEXTLCD_H + +#include "mbed.h" + +/** A TextLCD interface for driving 4-bit HD44780-based LCDs + * + * Currently supports 16x2, 20x2 and 20x4 panels + * + * @code + * #include "mbed.h" + * #include "TextLCD.h" + * + * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d0-d3 + * + * int main() { + * lcd.printf("Hello World!\n"); + * } + * @endcode + */ +class TextLCD : public Stream { +public: + + /** LCD panel format */ + enum LCDType { + LCD16x2 /**< 16x2 LCD panel (default) */ + , LCD16x2B /**< 16x2 LCD panel alternate addressing */ + , LCD20x2 /**< 20x2 LCD panel */ + , LCD20x4 /**< 20x4 LCD panel */ + }; + + /** Create a TextLCD interface + * + * @param rs Instruction/data control line + * @param e Enable line (clock) + * @param d0-d3 Data lines + * @param type Sets the panel size/addressing mode (default = LCD16x2) + */ + TextLCD(PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2); + +#if DOXYGEN_ONLY + /** Write a character to the LCD + * + * @param c The character to write to the display + */ + int putc(int c); + + /** Write a formated string to the LCD + * + * @param format A printf-style format string, followed by the + * variables to use in formating the string. + */ + int printf(const char* format, ...); +#endif + + /** Locate to a screen column and row + * + * @param column The horizontal position from the left, indexed from 0 + * @param row The vertical position from the top, indexed from 0 + */ + void locate(int column, int row); + + /** Clear the screen and locate to 0,0 */ + void cls(); + + int rows(); + int columns(); + +protected: + + // Stream implementation functions + virtual int _putc(int value); + virtual int _getc(); + + int address(int column, int row); + void character(int column, int row, int c); + void writeByte(int value); + void writeCommand(int command); + void writeData(int data); + + DigitalOut _rs, _e; + BusOut _d; + LCDType _type; + + int _column; + int _row; +}; + +#endif
diff -r 000000000000 -r fb0aa840a7cd main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 01 05:36:38 2013 +0000 @@ -0,0 +1,215 @@ + +#include "mbed.h" +#include "TextLCD.h" +TextLCD lcd(p25,p26, p21, p22, p23, p24); // rs, e, d4, d5, d6, d7 +Serial pc(USBTX,USBRX); + DigitalOut sensor1(p21); + DigitalOut sensor2(p22); + DigitalOut sensor3(p23); +AnalogIn s_1(p15); +AnalogIn s_2(p16); +AnalogIn s_3(p17); +AnalogIn s_4(p18); +AnalogIn s_5(p19); +AnalogIn b(p20); +LocalFileSystem local("local"); +char time1[16];//as our lcd is of 16 character it is so +char date[16]; +float a[6]; +int time_clock; +int j,k; +float avg_sensorvalue1=0,avg_sensorvalue2=0; +Timer timer; +char c1[20]="sensor1"; +char c2[20]="sensor2"; +char c3[20]="sensor3"; +char c4[20]="sensor4"; +char c5[20]="sensor5"; +char bat[20]="battery"; +char d[30]="Date"; +char t[30]="Time"; +char c6[20]="time"; +int main() +{ + int i; + set_time(1367038111); + time_t seconds = time(NULL)+19800; // time(null) gives the GMT time which mustbe added with IST ie..GMTtime + 5 hr:30 min +19800 + strftime(time1,16,"%H/%M/%S",localtime(&seconds)); //this converts the value in seconds obtained above to human readable format and assigns it to the time_stamp which stores it + strftime(date,16,"%d/%m/%y",localtime(&seconds)); + +//fprintf(fp,"%s,%s,%s,%s,%s,%s,%s,%s\r",t,d,c1,c2,c3,c4,c5,battery); + FILE *fp=fopen("/local/sensor1.csv","a"); + + fprintf(fp,"%s,%s,%s,%s,%s,%s,%s,%s\r",t,d,c1,c2,c3,c4,c5,bat); + while(1) + { + time_t seconds = time(NULL)+19800; + strftime(time1,16,"%H/%M/%S",localtime(&seconds)); //this converts the value in seconds obtained above to human readable format and assigns it to the time_stamp which stores it + strftime(date,16,"%d/%m/%y",localtime(&seconds)); + /* for(i=0;i<=20;i++) + { + pulse=1; + a[0]=a[0]+s_1.read(); + a[1]=a[1]+s_2.read(); + wait(0.005); + pulse=0; + wait(0.005); + } + a[0]=a[0]/21; + a[1]=a[1]/21;*/ + /*wait(1); + a[1]=s_2.read(); + wait(1); + a[2]=s_3.read(); + wait(1); + a[3]=s_4.read(); + wait(1); + a[4]=s_5.read(); + wait(1); + a[5]=b.read(); + wait(1); + lcd.cls();//clear the lcd screen + lcd.locate(0,0); + lcd.printf("%.3f",a[0]); + wait(2); + lcd.cls();//clear the lcd screen + lcd.locate(0,0); + lcd.printf("%s,%s",time1,date); + wait(3);*/ + sensor1=1; + sensor2=1; + wait(2); + a[0]=s_1.read(); + a[1]=s_2.read(); + wait(2); + sensor1=0; + sensor2=0; + pc.printf("a[0]=%f,a[1]=%f",a[0],a[1]); + fprintf(fp,"%s,%s,%0.6f,%.6f,%.6f,%.6f,%.6f,%.6f\r",time1,date,a[0],a[1],a[2],a[3],a[4],a[5]); + wait(2); + fclose(fp); + FILE *fp=fopen("/local/sensor1.csv","a"); + } + + +} +/* #include "mbed.h" +#include "TextLCD.h" +#include "string.h" +#include "SDFileSystem.h" +#include "PowerControl.h" +#include "EthernetPowerControl.h" + +void sendsms(float m); +char a=0x1A,e=0x22; + +char num[] = "9731892759"; +#define USR_POWERDOWN (0x104) +Serial uart(p9,p10); +Serial GSM(p13, p14); // tx, rx +Serial pc(USBTX,USBRX); + + +Ticker sense; // Ticker to Interrupt the sleeping mode + +TextLCD lcd(p24,p25,p26, p27, p28, p29, p30); // rs, rw, e, d4, d5, d6, d7 +AnalogIn Msensor_out(p20); +AnalogIn Tsensor_out(p19); +AnalogIn Lsensor_out(p18); +DigitalOut sensors_vcc(p17); +DigitalOut lcd2(p8); + int k; +char r[5]=""; + + unsigned char i = 0; + unsigned char j = 0; +char time_stamp[16];//as our lcd is of 16 character it is so + +float m,t,l; + + +int semihost_powerdown() +{ + uint32_t arg; + return __semihost(USR_POWERDOWN, &arg); +} + +//////////////////////////////////////////////////////////////////// +// fun() - it reads the sensor, writes to LCD and SD card and also senda the data on GSM +//////////////////////////////////////////////////////////////////// + +void fun() +{ + sensors_vcc=1; + m=Msensor_out.read(); //read the analog input from the pin15 and assign it to m + t=Tsensor_out.read(); + l=Lsensor_out.read(); + wait(2); + sensors_vcc=0; + lcd.cls();//clear the lcd screen + lcd.locate(0,0); + lcd.printf("Welcome to WMS"); + wait(3); + + FILE *fp = fopen("/sd/mydir/sdtest.csv", "a"); + if (fp == NULL) + { + error("Could not open file for write\n"); + } + fprintf(fp, "%d : %s \n",time_stamp,m); //Record Sensor data along with time stamp + fclose(fp); + wait(2); + + + + + lcd.cls();//clear the lcd screen + lcd.locate(0,0); + lcd.printf("sending sms to"); + wait(3); + lcd.locate(0,1); + lcd.printf("%s",num); + wait(3); + lcd.locate(0,0);//start displaying from zeroth column,zeroth row + lcd.printf("%s",time_stamp);//diplays the human readable time which was stored in time_stamp. + lcd.locate(0,1);//start displaying from zeroth column,first row + lcd.printf("M%0.3f,%0.3f,L%0.3f",m,t,l);//display the value of analog input obtained in variable m + wait(3); + GSM.printf("AT+CMGS=%c%s%c\r\n",e,num,e); + wait(3); + GSM.printf("%s,Moisture%f",time_stamp,m); + GSM.printf("%c",a); + return ; +} + + + +int main() + { + lcd2=0; + int result; + GSM.baud(9600); + pc.baud(9600); + set_time( 1358319500); + time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time which mustbe added with IST ie..GMTtime + 5 hr:30 min + strftime(time_stamp, 16, "%d/%m/%y/%H/%M/%S", localtime(&seconds)); //this converts the value in seconds obtained above to human readable format and assigns it to the time_stamp which stores it + + + PHY_PowerDown(); // PHY Powerdown + result = semihost_powerdown(); //Semihost Powerdown + sense.attach(&fun,30); // Excecute sd_write_read function every 5s + //t.start(); //Start of timer to record Time Stamp + while (1) + { + Sleep(); // Sleep mode to save power + } + + + } + + + */ + + + +
diff -r 000000000000 -r fb0aa840a7cd mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed May 01 05:36:38 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b \ No newline at end of file