Oled Display Driver, tested to work with EA W082-XLG SPI (HD44780) and WEH001602CRPP5N00001-WSR (WS0010). It can work with other SPI Oled Displays. It should work with 20x4 aswell but has not been tested. Should work for: EA W082-XLG EA W162-X3LW EA W162-X3LG EA W162-XLG EA W162-X9LG EA W162-XBLW EA W162-XBLG EA W202-XLG EA W202-XDLG EA W204-XLG
Display.h
00001 00002 //V1.1 Changes: 00003 //Added 2ms delay for clear display function 00004 //Added Return home in clear display function 00005 00006 00007 //INFO 00008 00009 //Made for MBED LPC1768 00010 //Made for EA W082-XLG In SPI mode (8x2 Oled display) 00011 //Also works with other Oled displays 00012 00013 //Default Ports: (For LPC1768) 00014 //p5 = mosi 00015 //p6 = miso 00016 //p7 = sck 00017 //p8 = cs 00018 00019 // 8x2 display cursor location 00020 // |---------------------------------------| 00021 // | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 00022 // |---------------------------------------| 00023 // | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 00024 // |---------------------------------------| 00025 00026 //IF Degree Symbol is desired, write DEG instead of the symbol, it will display the ° symbol. Example: DispCharacter(DEG); //Writes ° to display 00027 00028 00029 //FUNCTIONS: 00030 00031 //OpenDisplay(); //Configures the display, should be run at startup in main routine, Clears display and returns to (1,1) 00032 //DispLocate(X,Y); //For choosing where the cursor is located. X is the line position (1-8), Y is the line select (1 for first line, 2 is for second line) 00033 //DispCharacter('X'); //For writing a single Character to the display 00034 //DispLine("HELLO"); //For writing a string to the display, (max 8 bit) 00035 00036 //ClearDisp(); //For Clearing Display, also returns the cursor to home (1,1) 00037 //DispReturn(); //For Returning the cursor to home (1,1) 00038 //ShiftRight(); //Shifts the cursor one to the right 00039 //ShiftLeft(); //Shifts the cursor one to the left 00040 00041 00042 00043 00044 //Define Pins: 00045 #define mosi p5 00046 #define miso p6 00047 #define sck p7 00048 #define DEG 0xD2 //IF Degree Symbol is desired, write DEG instead of the symbol, it will display the ° symbol. Example: DispCharacter(DEG); //Writes ° to display 00049 00050 DigitalOut cs(p8); //Chip select 00051 00052 //Define SPI connections: 00053 SPI spi(mosi, miso, sck); // mosi, miso, sck 00054 00055 00056 //For Use in Main Routine: 00057 void DispLocate(char Char1, char Char2); //For deciding location of cursor, for use in main routine 00058 void ClearDisp(void); //Clears the display, also returns the cursor to home (1,1) 00059 void DispReturn(void); //returns cursor to home (1,1) 00060 void ShiftRight(void); //Shifts cursor right 00061 void ShiftLeft(void); //Shifts cursor left 00062 void DispCharacter(void); //For displaying a single character. Example: DispCharacter('A'); //Wrtites A on display 00063 void DispLine(void); //For Writing Line to display. Example: DispLine("Hello"); //Writes Hello on the display 00064 00065 00066 //Prototypes: 00067 void DispConfig(char Char); //For sending command to configure the display, used in the OpenDisplay routine 00068 void Delay2us(void); //2us delay, used as a small delay for setup purposes 00069 00070 //Init Oled Display: 00071 void OpenDisplay(){ 00072 00073 //DigitalOut cs(p8); //Chip select 00074 cs = 1; //high at idle 00075 00076 spi.format(10,3); //10bit, high steady state clock 00077 spi.frequency(1000000); //1MHz spi clock 00078 00079 //Display init routine 00080 DispConfig(0x39); //function set european chararacter set 00081 DispConfig(0x08); //display off 00082 DispConfig(0x06); //entry mode set increment cursor by 1 not shifting display 00083 DispConfig(0x17); //Character mode and internel power on 00084 DispConfig(0x01); //clear display 00085 DispConfig(0x02); //return home 00086 DispConfig(0x0C); //display on 00087 00088 wait_ms(10); //Time to stabilize (wont work without) 00089 } 00090 00091 00092 //Send single line to display 00093 void DispLine(char textstr[]){ 00094 00095 char len = strlen(textstr); 00096 for(char i = 0; i < len; i++){ 00097 00098 cs = 0; //chip select to start data transmission 00099 00100 spi.write(0x200 | textstr[i]); //add 0x02 for character transmission 00101 00102 cs = 1; //chip select to end data transmission 00103 00104 Delay2us(); //small delay for cs to stabilize 00105 } 00106 00107 } 00108 00109 00110 void DispCharacter(char instruction){ 00111 00112 cs = 0; //chip select to start data transmission 00113 00114 spi.write(0x200 | instruction); //add 0x02 for character transmission 00115 00116 cs = 1; //chip select to end data transmission 00117 00118 Delay2us(); //small delay for cs to stabilize 00119 00120 } 00121 00122 00123 //Send single character to display 00124 void DispConfig(char instruction){ 00125 00126 cs = 0; //chip select to start data transmission 00127 00128 spi.write(instruction); 00129 00130 cs = 1; //chip select to end data transmission 00131 00132 Delay2us(); //small delay for cs to stabilize 00133 } 00134 00135 00136 //Locate Cursor 00137 void DispLocate(char X, char Y){ 00138 00139 DispReturn(); //Return the cursor to home 00140 00141 char tempX; 00142 tempX = X; 00143 char tempY; 00144 tempY = Y; 00145 00146 //Shift to next line (64 times to the right) 00147 if(tempY > 1){ 00148 for(int i = 0; i < 64; i++){ 00149 ShiftRight(); 00150 } 00151 } 00152 00153 //Decides how many times the cursor is shifted 00154 while(tempX > 1){ 00155 tempX--; 00156 ShiftRight(); 00157 } 00158 } 00159 00160 00161 //Toggle Chipselect 00162 void Chipselect(){ 00163 00164 cs = !cs; 00165 } 00166 00167 00168 void Delay2us(){ 00169 00170 wait_us(2); //small delay for cs to stabilize 00171 } 00172 00173 00174 void ClearDisp(){ 00175 00176 DispConfig(0x01); //Clear Display, Sets DDRAM-address 0 into adresscounter 00177 wait_ms(2); //wait a little, wont work without 00178 DispReturn(); //Returns cursor home 00179 00180 } 00181 00182 00183 void DispReturn(){ 00184 00185 DispConfig(0x02); //Returns the cursor to home 00186 } 00187 00188 00189 void ShiftRight(){ 00190 00191 DispConfig(0x14); //Shift cursor right 00192 Delay2us(); 00193 } 00194 00195 00196 void ShiftLeft(){ 00197 00198 DispConfig(0x10); //Shift cursor left 00199 Delay2us(); 00200 }
Generated on Mon Jul 18 2022 17:28:31 by 1.7.2