Esta versión v6 pasa a ser el nuevo master. Funciona correctamente

Dependencies:   ADXL345 Display1602 MSCFileSystem SDFileSystem mbed FATFileSystem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Display1602.cpp Source File

Display1602.cpp

00001 
00002 #include "Display1602.h"
00003 
00004  Display1602::Display1602(PinName registerSelect,PinName readWriteSelect,PinName readWriteEnable,PinName d0,PinName d1,PinName d2,PinName d3,PinName d4,PinName d5,PinName d6,PinName d7) 
00005         : rs(registerSelect), rw(readWriteSelect), e(readWriteEnable), data(d0,d1,d2,d3,d4,d5,d6,d7)
00006 {
00007     //To ensure we have waited 15ms after power up and VDD > 4.5v (don't know how to test VDD)
00008     wait_ms(20);
00009     
00010     //The init commands always sent using the 4bit interface.
00011     e = true;
00012     
00013     //Set interface to 8 bit mode
00014     SendCommand(0x38);
00015     wait_ms(1); 
00016     
00017     //Display off
00018     SendCommand(0x08);
00019     wait_ms(1); 
00020     
00021     Clear();
00022     
00023     //Set the display to 2 line and 5x11 font.
00024     SendCommand(0x06);
00025     wait_ms(1); 
00026     
00027     //Init done, turn display on.
00028     SendCommand(0x0c); //No with no cursor.
00029     wait_ms(10);   
00030 }
00031 
00032 void Display1602::Clear()
00033 {
00034     SendCommand(0x01);
00035     wait_ms(2);//Docs say have to wait more than 1.53 milliseconds after clearing display.
00036 }
00037 
00038 void Display1602::Print(const char *text)
00039 {
00040     int n = 16;
00041     while (*text && n--)
00042     {
00043         SendChar(*text);
00044         text++;
00045     }
00046 }
00047 
00048 void Display1602::printf(const char *format,...)
00049 {
00050     va_list args;
00051     char buf[17];
00052 
00053     va_start(args, format);
00054     vsnprintf(buf,17,format, args);
00055     va_end(args);
00056     
00057     Print(buf);        
00058 }
00059 
00060 void Display1602::SetXY(int x,int y)
00061 {
00062     if (y == 0)
00063     {
00064         SendCommand (0x80 | x);
00065     }
00066     else
00067     {
00068         SendCommand (0xC0 | x);
00069     }
00070 }
00071     
00072 void Display1602::SendCommand(int cmd)
00073 {
00074     rs = false;//read register
00075     rw = false;//Write mode
00076     e = true;
00077     data = cmd;
00078     wait_us(40);//Have to wait this time before we then drop the e line. Data sent on rising edge so has to be dropped.
00079     e = false;
00080 }
00081 
00082 void Display1602::SendChar(char c)
00083 {
00084     rs = true;//Writing data.
00085     rw = false;//Write mode
00086     e = true;
00087     data = c;
00088     wait_us(40);//Have to wait this time before we then drop the e line. Data sent on rising edge so has to be dropped.
00089     e = false;
00090 }
00091