Mohammed Youssuf / Mbed 2 deprecated STM32F103C8T6_Nokia1202

Dependencies:   mbed mbed-STM32F103C8T6

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nLCD.cpp Source File

nLCD.cpp

00001 /**
00002 @file N5110.cpp
00003 
00004 @brief Member functions implementations
00005 
00006 */
00007 #include "nLCD.h"
00008 #include "mbed.h"
00009 
00010 #define HIGH 1
00011 #define LOW 0
00012 
00013 graphicsLCD::graphicsLCD(PinName ResetPin,PinName CSPin,PinName SDAPin,PinName SCKPin):
00014 _CSPin(CSPin), _SCKPin( SCKPin), _SDAPin( SDAPin),_ResetPin( ResetPin)
00015 {
00016 //
00017   //disable graphicsLCD to start with 
00018   _CSPin = HIGH;
00019   _SDAPin = LOW;
00020   _SCKPin = LOW;
00021     // set reset pin to start graphicsLCD
00022   _ResetPin = HIGH;  
00023  }
00024  
00025 void graphicsLCD::contrast(byte con)
00026 {
00027   if(con<0) {con=0;}
00028   if(con>32) {con=32;}
00029   con = con | 0x80;
00030   graphicsLCD::command(con);  
00031 }
00032 
00033 
00034 void graphicsLCD::displayAllPointsOn()
00035 {
00036   graphicsLCD::command(0xA5);
00037 }
00038 
00039 
00040 void graphicsLCD::displayAllPointsOff()
00041 {
00042   graphicsLCD::command(0xA4);
00043 }
00044 
00045 
00046 void graphicsLCD::softwareReset()
00047 {
00048   graphicsLCD::command(0xE2);  //reset
00049 }
00050 
00051 
00052 void graphicsLCD::hardwareReset()
00053 {
00054   _ResetPin = LOW;
00055   wait_ms(5);
00056   _ResetPin = HIGH;
00057   wait_ms(5);
00058 }
00059 
00060  
00061 void graphicsLCD::line(byte line)
00062 {
00063   if (line<0){line = 0;}
00064   if (line>8){line = 8;}
00065   
00066   line = 176+line;
00067   
00068   graphicsLCD::command(line);  //set line
00069   graphicsLCD::column(0x00);
00070 }
00071 
00072  void graphicsLCD::column(byte payload)
00073 {
00074 if(payload<0){payload=0;}
00075 if(payload>95){payload=95;}
00076 
00077 byte lower = 0x0F;
00078 byte upper = 0x70;
00079 
00080 lower = payload & 0x0F;
00081 upper =payload &0x70;
00082 upper = upper>>4;
00083 upper = 0x10 | upper;
00084 graphicsLCD::command(upper);
00085 graphicsLCD::command(lower);
00086 }
00087 
00088 void graphicsLCD::scroll(byte payload)
00089 {
00090   payload =64+ payload;
00091   
00092   if (payload <0){payload = 64;}
00093   if (payload >127){payload = 127;}
00094   graphicsLCD::command(payload);
00095 }
00096 
00097 void graphicsLCD::displayOff()
00098 {
00099   graphicsLCD::command(0xAE);
00100 }
00101 
00102 void graphicsLCD::displayOn()
00103 {
00104   graphicsLCD::command(0xAF);
00105 }
00106 
00107 void graphicsLCD::displayNormal()
00108 {
00109   graphicsLCD::command(0xA6);
00110 }
00111 
00112 void graphicsLCD::displayInverse()
00113 {
00114   graphicsLCD::command(0xA7);
00115 }
00116 
00117  void graphicsLCD::println(char *characters)
00118 {
00119   graphicsLCD::command(0x10);  //set column=0 upper 3 bits
00120   graphicsLCD::command(0x00);  //set column=0 lower 4 bits
00121 
00122   while (*characters)
00123   {
00124     graphicsLCD::character(*characters++);
00125   }
00126 }
00127 
00128 
00129  
00130  void graphicsLCD::print(char *characters)
00131 {
00132   while (*characters)
00133   {
00134     graphicsLCD::character(*characters++);
00135   }
00136 }
00137 
00138  void graphicsLCD::print(const char *characters)
00139 {
00140   while (*characters)
00141   {
00142     graphicsLCD::character(*characters++);
00143   }
00144 }
00145 
00146  void graphicsLCD::print(long num)
00147 {
00148 char c[20];
00149 //ltoa(num,c,10);
00150 graphicsLCD::print(c);
00151 }
00152 
00153 void graphicsLCD::println(long num)
00154 {
00155 //char c[20];
00156 //ltoa(num,c,10);
00157 //graphicsLCD::println(c);
00158 char c[20];
00159 long dc=0;
00160 //long n= num*100;
00161 //n=n/100;
00162 dc=num % 100;
00163 graphicsLCD::print(num);graphicsLCD::print("  ");graphicsLCD::print(dc);
00164 }
00165 
00166 
00167 void graphicsLCD::character(char character)
00168 {
00169   for (int index = 0; index < 5; index++)
00170   {
00171     //graphicsLCD::data(ASCII[character - 0x20][index]); 
00172     graphicsLCD::data(chars[character - 0x20][index]);
00173   }
00174   graphicsLCD::data(0x00);  
00175 }
00176 
00177 
00178 void graphicsLCD::gotoRC (int r, int c)
00179 {
00180    graphicsLCD::command(0x41); 
00181 }
00182 
00183 void graphicsLCD::clear()
00184 {
00185   
00186   //display off
00187   graphicsLCD::command(0xAE);
00188   
00189   for (int i = 0; i < 864; i++)
00190   {
00191     graphicsLCD::data(0x00);  
00192   }
00193 
00194   graphicsLCD::command(0xB0);  //set page address
00195   graphicsLCD::command(0x10);  //set col=0 upper 3 bits
00196   graphicsLCD::command(0x00);  //set col=0 lower 4 bits
00197 
00198   graphicsLCD::command(0x40);  //set row 0
00199 
00200   //display on
00201   graphicsLCD::command(0xAF);
00202 
00203 }
00204 
00205 void graphicsLCD::command(byte payload)
00206 {  
00207   int dc =0 ;
00208   //select graphicsLCD
00209   _CSPin = LOW;
00210   
00211   //write dc bit
00212   if(dc==0){_SDAPin = LOW;}
00213   else {_SDAPin = HIGH;}
00214   _SCKPin = HIGH;
00215   _SCKPin = LOW;
00216   
00217   //write payload 8 bits
00218   for(int i=7;i>=0;i--)
00219   {
00220       _SDAPin = (payload>>i)&1;
00221       //toggle clock
00222       _SCKPin = HIGH;
00223       _SCKPin = LOW;
00224   }
00225   
00226   //turn off graphicsLCD cs
00227   _CSPin = HIGH;
00228 }
00229 
00230 void graphicsLCD::begin()
00231 {
00232   graphicsLCD::command(0xE2);  //reset
00233   wait_ms(10);
00234   graphicsLCD::command(0xA4);  //power save off
00235   graphicsLCD::command(0x2F);  //power control set
00236   graphicsLCD::command(0xB0);  //set page address
00237   graphicsLCD::command(0x10);  //set col=0 upper 3 bits
00238   graphicsLCD::command(0x00);  //set col=0 lower 4 bits
00239   
00240   graphicsLCD::command(0xAF);  //graphicsLCD display on
00241   wait_ms(500);
00242 }
00243 
00244 void graphicsLCD::init()
00245 {
00246   graphicsLCD::begin();
00247   graphicsLCD::clear();
00248   wait_ms(500);
00249   graphicsLCD::displayInverse();
00250   wait_ms(50);
00251   graphicsLCD::displayNormal();
00252   wait_ms(50);
00253 }
00254 
00255 
00256 void graphicsLCD::data(byte payload)
00257 {
00258   
00259   int dc =1 ;
00260   //select graphicsLCD
00261   _CSPin = LOW;
00262   
00263   //write dc bit
00264   if(dc==0){_SDAPin = LOW;}
00265   else {_SDAPin = HIGH;}
00266   _SCKPin = HIGH;
00267   _SCKPin = LOW;
00268   
00269   //write payload 8 bits
00270   for(int i=7;i>=0;i--)
00271   {
00272       _SDAPin = (payload>>i)&1;
00273       //toggle clock
00274       _SCKPin = HIGH;
00275       _SCKPin = LOW;
00276   }
00277   
00278   //turn off graphicsLCD cs
00279   _CSPin = HIGH;
00280 }