Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
spioled.h
00001 // ALO-095BWNN-J9 test program 00002 // See also "http://www.aitendo.co.jp/product/2099" 00003 00004 00005 #ifndef __SPIOLED_H__ 00006 #define __SPIOLED_H__ 00007 00008 #include "mbed.h" 00009 #include "small_font.h" 00010 00011 class SPIOLED { 00012 private: 00013 DigitalOut CS, RES, DC; 00014 SPI spi; // mosi, miso, sclk 00015 00016 #define Dis_X_MAX 96-1 // Max X axial direction in screen 00017 #define Dis_Y_MAX 64-1 // Max Y axial direction in screen 00018 #define X_Witch 8 // character's width 00019 #define Y_Witch 8 // character's height 00020 00021 unsigned int Char_Color; //character's color 00022 unsigned int BGround_Color; 00023 00024 00025 00026 void Init(void){ 00027 spi.format(8,0); // nazo 00028 spi.frequency(25000000); // modify later 00029 00030 // reset 00031 wait_ms(200); 00032 RES = 0; //Reset active 00033 wait_ms(200); 00034 RES = 1; 00035 00036 00037 // initialize sequence 00038 RegWrite(0xae); //OLED display OFF 00039 00040 //Row Address 00041 RegWrite(0x75); /* Set Row Address */ 00042 RegWrite(0x00); /* Start = 0 */ 00043 RegWrite(0x3f); /* End = 63 */ 00044 RegWrite(0x15); /* Set Column Address */ 00045 RegWrite(0x00); /* Start = 0 */ 00046 RegWrite(0x5F); /* End = 96 */ 00047 00048 //Contrast 00049 RegWrite(0xa0); //Set remap & data format 0111 0000 00050 RegWrite(0x74); 00051 RegWrite(0xa1); //set display star row RAM 00052 RegWrite(0x00); 00053 RegWrite(0xa2); //set dispaly offset 00054 RegWrite(0x00); 00055 RegWrite(0xa4); //Set Display Mode 00056 RegWrite(0xa8); //Set Multiplex Ratio 00057 RegWrite(0x3f); 00058 RegWrite(0xad); //Set Master Configuration 00059 RegWrite(0x8f); //(External VCC Supply Selected) 00060 RegWrite(0xB0); //Set Power Saving Mode 00061 RegWrite(0x1a); 00062 RegWrite(0xB1); //Set Phase 1 & 2 Period Adjustment 00063 RegWrite(0x74); 00064 RegWrite(0xb3); //Set Display Clock Divide Ratio / Oscillator Frequency 00065 RegWrite(0xd0); 00066 RegWrite(0x8A); //Set Second Pre-charge Speed of Color A 00067 RegWrite(0x81); 00068 RegWrite(0x8B); //Set Second Pre-charge Speed of Color B 00069 RegWrite(0x82); 00070 RegWrite(0x8C); //Set Second Pre-charge Speed of Color C 00071 RegWrite(0x83); 00072 RegWrite(0xBB); //Set Pre-charge Level 00073 RegWrite(0x3e); 00074 RegWrite(0xBE); //Set VCOMH 00075 RegWrite(0x3e); 00076 RegWrite(0x87); //Set Master Current Control 00077 RegWrite(0x0f); 00078 RegWrite(0x81); //Set Contrast Control for Color gAh 00079 RegWrite(0x80); 00080 RegWrite(0x82); //Set Contrast Control for Color gBh 00081 RegWrite(0x80); 00082 RegWrite(0x83); //Set Contrast Control for Color gCh 00083 RegWrite(0x80); 00084 RegWrite(0xaf); //display ON 00085 00086 } 00087 public: 00088 // constructor 00089 SPIOLED(PinName cs_pin, PinName rst_pin, PinName a0_pin, PinName mosi_pin, PinName miso_pin, PinName sclk_pin) 00090 : CS(cs_pin), RES(rst_pin), DC(a0_pin), spi(mosi_pin, miso_pin, sclk_pin) { 00091 00092 Init(); 00093 } 00094 00095 00096 00097 00098 void RegWrite(unsigned char Command) 00099 { 00100 DC = 0; // Command 00101 CS = 0; // CS active(toggle OLED) 00102 spi.write(Command); 00103 CS = 1; 00104 } 00105 00106 00107 00108 void DataWrite(unsigned char c){ 00109 DC = 1; // DATA 00110 CS = 0; // CS active(toggle OLED) 00111 spi.write(c); 00112 CS = 1; 00113 } 00114 00115 void DataWrite_to(unsigned int Dat) 00116 { 00117 DataWrite((unsigned char)((Dat >> 8)& 0x00ff)); 00118 DataWrite((unsigned char)(Dat & 0x00ff)); 00119 } 00120 00121 00122 00123 00124 void Draw_Dot(unsigned char x,unsigned char y,unsigned int Color) 00125 { 00126 RegWrite(0x15); 00127 RegWrite(x); 00128 RegWrite(x); 00129 RegWrite(0x75); 00130 RegWrite(y); 00131 RegWrite(y); 00132 DataWrite_to(Color); 00133 DataWrite_to(Color); 00134 } 00135 00136 void Full_Screen(unsigned int Dot) 00137 { 00138 unsigned char i,j; 00139 BGround_Color = Dot; 00140 for(i=0;i<=64;i++) 00141 { 00142 for(j=0;j<96;j++) 00143 { 00144 Draw_Dot(j,i,Dot); 00145 // DataWrite_to(Dot); 00146 } 00147 } 00148 } 00149 00150 void ChangeFontColor(unsigned int color) 00151 { 00152 Char_Color = color; 00153 } 00154 00155 void PutChar(unsigned char x,unsigned char y,unsigned int a) 00156 { 00157 int i,j; 00158 unsigned char Temp=0; 00159 j = 0; 00160 i = 0; 00161 //if(a < 32)a=32; 00162 for(i=0; i<X_Witch; i++) 00163 { 00164 Temp = FontLookup[a][i]; 00165 for(j=Y_Witch;j!=0;j--){ 00166 if((Temp & 0x80)==0x80){ 00167 Draw_Dot(x+i,y+j,Char_Color); 00168 }else{ 00169 Draw_Dot(x+i,y+j,BGround_Color); 00170 } 00171 Temp = Temp << 1; 00172 } 00173 } 00174 00175 00176 } 00177 00178 void PutChar_ABC(unsigned char x,unsigned char y,unsigned int a) 00179 { 00180 int i,j; 00181 unsigned char Temp=0; 00182 j = 0; 00183 i = 0; 00184 for(i=0; i<5; i++) 00185 { 00186 if(a < 32)a=32; 00187 Temp = FontLookup_ABC[a-32][i]; 00188 for(j=Y_Witch;j!=0;j--){ 00189 if((Temp & 0x80)==0x80){ 00190 Draw_Dot(x+i,y+j,Char_Color); 00191 }else{ 00192 Draw_Dot(x+i,y+j,BGround_Color); 00193 } 00194 Temp = Temp << 1; 00195 } 00196 } 00197 00198 00199 } 00200 00201 00202 00203 }; 00204 00205 00206 #endif
Generated on Mon Jul 18 2022 00:15:03 by
1.7.2