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.
main.cpp
00001 //#include "stdio.h" 00002 #include "mbed.h" 00003 //#include "string" 00004 #include "Arial12x12.h" 00005 #include "Arial24x23.h" 00006 //#include "Terminal6x8.h" 00007 #include "Arial43x48_numb.h" 00008 #include "pict.h" 00009 #include "pavement_48x34.h" 00010 00011 //#include "IST3020.h" 00012 //#include "UC1608.h" 00013 //#include "ST7565.h" 00014 #include "ST7920.h" 00015 //#include "ILI932x.h" 00016 //#include "ILI9341.h" 00017 //#include "ILI9486.h" 00018 //#include "TFT_MIPI.h" 00019 //#include "SSD1306.h" 00020 00021 Serial pc(USBTX, USBRX); 00022 DigitalOut led1(LED1); 00023 DigitalOut led2(LED2); 00024 00025 00026 //IST3020 myLCD(PAR_8, Port2, p23, p24, p25, p26, p27,"myLCD", 192, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD for F302 00027 //zeigt Schrott an 00028 //UC1608 myLCD(SPI_16, 10000000, p11, p12, p13, NC, NC, p16,"myLCD", 132, 64); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc 00029 00030 //ST7565 myLCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"myLCD", 128, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD 00031 //ILI932x myLCD(PAR_8, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 8bit, Port, CS, reset, RS, WR, RD for F401 00032 //ILI932x myLCD(SPI_16, 10000000, p11, p12, p13, p14, p15,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset 00033 //ILI9341 myLCD(SPI_16, 12000000, D11, D12, D13, D10, D9, D8,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc 00034 //ILI9341 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 00035 //ILI9486 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 00036 //TFT_MIPI myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 00037 //SSD1306 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc 00038 //zeigt Schrott an 00039 //ILI9486 myLCD(SPI_8, 12000000, p11, p12, p13, p14, p15, p16,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple 00040 //ILI9341 myLCD(SPI_8, 12000000, PA_7, PA_6, PA_5, PB_6, PA_8, PA_9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple 00041 00042 // cs, reset,dc must not be NC! 00043 // ST7920 can go up to 2,5MHz SPI-clock according to datasheet.Mine works with 10MHz fine too... 00044 ST7920 myLCD(SPI_8, 10000000, p11, p12, p13, p15, p14, p16, "128x64-ST7920", 128, 64); //Spi 8bit, 1MHz, mosi, miso, sclk, cs, reset, dc 00045 00046 Timer t; 00047 00048 unsigned short backgroundcolor=White; 00049 unsigned short foregroundcolor=Black; 00050 //unsigned short backgroundcolor=Black; 00051 //unsigned short foregroundcolor=White; 00052 00053 char orient=1; 00054 int main() 00055 { 00056 // myLCD.set_contrast(26);//for uc1608 00057 // myLCD.set_contrast(46);//for ist3020 00058 led1=1; 00059 pc.baud(115200); 00060 pc.printf("\n\r\n\r\n\r"); 00061 pc.printf("\n\rConnected to mbed\n\r"); 00062 pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000); 00063 00064 //myLCD.set_orientation(orient); 00065 int time, time2; 00066 t.start(); 00067 // myLCD.set_font((unsigned char*) Terminal6x8); 00068 // myLCD.claim(stdout); // send stdout to the LCD display 00069 //myLCD.claim(stderr); // send stderr to the LCD display 00070 myLCD.background(backgroundcolor); // set background to black 00071 myLCD.foreground(foregroundcolor); // set chars to white 00072 led1=1; 00073 while(1) 00074 { 00075 pc.printf("Orientation: %d\r\n",orient%4); 00076 myLCD.set_orientation((orient++)%4); 00077 00078 00079 pc.printf("cls() ...\r\n"); 00080 myLCD.cls(); 00081 wait(1); 00082 00083 pc.printf("fillrect(0, 0, 127 , 63, black) ...\r\n"); 00084 myLCD.fillrect(0, 0, 127 , 63, Black); 00085 wait(5); 00086 00087 pc.printf("Pixels at corners...\n\r"); 00088 myLCD.cls(); 00089 myLCD.pixel(1,1,Black); 00090 myLCD.pixel(126,62,Black); 00091 myLCD.pixel(1,62,Black); 00092 myLCD.pixel(126,1,Black); 00093 myLCD.copy_to_lcd(); 00094 wait(5); 00095 00096 myLCD.cls(); // clear the screen 00097 myLCD.locate(0,30); 00098 00099 myLCD.printf("Display ID: %.8X\r\n", myLCD.tftID); 00100 pc.printf("Display ID: %.8X\r\n", myLCD.tftID); 00101 // mem write/read test 00102 myLCD.printf("Dimension: %dX%d\r\n",myLCD.width(),myLCD.height()); 00103 00104 unsigned short readback; 00105 unsigned short colorstep = (0x10000/myLCD.width()); 00106 for(unsigned short i=0; i<myLCD.width(); i++) 00107 { 00108 myLCD.pixel(i,0,i*colorstep); // write line 00109 } 00110 myLCD.copy_to_lcd(); 00111 bool readerror=false; 00112 for(unsigned short i=0; i<myLCD.width(); i++) // verify line 00113 { 00114 readback = myLCD.pixelread(i,0); 00115 if(readback!=i*colorstep) 00116 { 00117 readerror=true; 00118 pc.printf("pix %.4X readback %.4X\r\n", i*colorstep, readback); 00119 } 00120 } 00121 myLCD.locate(0,10); 00122 myLCD.printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS"); 00123 wait(2); 00124 led2=1; 00125 myLCD.cls(); 00126 myLCD.set_auto_up(false); 00127 myLCD.set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled 00128 myLCD.locate(0,0); 00129 myLCD.printf("Display Test\r\nSome text just to see if auto carriage return works correctly"); 00130 myLCD.set_font((unsigned char*) Terminal6x8); 00131 // myLCD.locate(0,0); 00132 myLCD.printf("\r\nDisplay Test\r\nSome text just to see if auto carriage return works correctly"); 00133 pc.printf(" Display Test \r\n"); 00134 myLCD.set_auto_up(true); 00135 wait(3); 00136 led1=0; 00137 t.reset(); 00138 myLCD.cls(); 00139 time=t.read_us(); 00140 myLCD.locate(2,55); 00141 myLCD.printf("cls: %.3fms", (float)time/1000); 00142 pc.printf("cls: %.3fms\r\n", (float)time/1000); 00143 wait(3); 00144 00145 myLCD.cls(); 00146 myLCD.set_auto_up(false); 00147 t.reset(); 00148 // draw some graphics 00149 //myLCD.cls(); 00150 myLCD.set_font((unsigned char*) Arial24x23); 00151 myLCD.locate(10,10); 00152 myLCD.printf("Test"); 00153 00154 myLCD.line(0,0,myLCD.width()-1,0,foregroundcolor); 00155 myLCD.line(0,0,0,myLCD.height()-1,foregroundcolor); 00156 myLCD.line(0,0,myLCD.width()-1,myLCD.height()-1,foregroundcolor); 00157 00158 myLCD.rect(10,30,50,40,foregroundcolor); 00159 myLCD.fillrect(60,30,100,40,foregroundcolor); 00160 00161 myLCD.circle(150,32,30,foregroundcolor); 00162 myLCD.fillcircle(140,20,10,foregroundcolor); 00163 00164 double s; 00165 00166 for (unsigned short i=0; i<myLCD.width(); i++) 00167 { 00168 s =10 * sin((long double) i / 10 ); 00169 myLCD.pixel(i,40 + (int)s ,foregroundcolor); 00170 } 00171 00172 00173 time=t.read_us(); 00174 myLCD.locate(2,55); 00175 myLCD.set_font((unsigned char*) Terminal6x8); 00176 myLCD.printf("plot: %.3fms", (float)time/1000); 00177 pc.printf("plot: %.3fms\r\n", (float)time/1000); 00178 myLCD.set_auto_up(true); 00179 wait(3); 00180 myLCD.cls(); 00181 myLCD.set_auto_up(false); 00182 t.reset(); 00183 Bitmap_s pic = { 00184 64, // XSize 00185 64, // YSize 00186 8, // Bytes in Line 00187 burp, // Pointer to picture data 00188 }; 00189 myLCD.Bitmap_BW(pic,myLCD.width()-64,0); 00190 time=t.read_us(); 00191 myLCD.locate(2,55); 00192 myLCD.printf("bmp: %.3fms", (float)time/1000); 00193 pc.printf("bmp: %.3fms\r\n", (float)time/1000); 00194 myLCD.set_auto_up(true); 00195 wait(3); 00196 myLCD.cls(); 00197 myLCD.set_auto_up(false); 00198 myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled 00199 t.reset(); 00200 myLCD.locate(0,0); 00201 myLCD.printf("%d", 12345); 00202 time=t.read_us(); 00203 myLCD.locate(2,55); 00204 myLCD.set_font((unsigned char*) Terminal6x8); 00205 myLCD.printf("Big Font: %.3fms", (float)time/1000); 00206 pc.printf("Big Font: %.3fms\r\n", (float)time/1000); 00207 myLCD.set_auto_up(true); 00208 wait(3); 00209 // sparse pixels test 00210 myLCD.cls(); 00211 myLCD.FastWindow(true); 00212 t.reset(); 00213 for(unsigned int i=0; i<20000; i++) 00214 { 00215 myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); 00216 } 00217 myLCD.copy_to_lcd(); 00218 time=t.read_us(); 00219 myLCD.cls(); 00220 myLCD.FastWindow(false); 00221 t.reset(); 00222 for(unsigned int i=0; i<20000; i++) 00223 { 00224 myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); 00225 } 00226 myLCD.copy_to_lcd(); 00227 time2=t.read_us(); 00228 myLCD.locate(2,55); 00229 myLCD.printf("std:%.3fms fastw:%.3fms", (float)time2/1000, (float)time/1000); 00230 pc.printf("std: %.3fms fastw: %.3fms\r\n", (float)time2/1000, (float)time/1000); 00231 wait(3); 00232 // scroll test, only for TFT 00233 myLCD.cls(); 00234 myLCD.set_font((unsigned char*) Arial24x23); 00235 myLCD.locate(2,10); 00236 myLCD.printf("Scrolling"); 00237 myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); 00238 myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); 00239 myLCD.setscrollarea(0,myLCD.sizeY()); 00240 wait(1); 00241 myLCD.scroll(1); //up 1 00242 wait(1); 00243 myLCD.scroll(0); //center 00244 wait(1); 00245 myLCD.scroll(myLCD.sizeY()-1); //down 1 00246 wait(1); 00247 myLCD.scroll(myLCD.sizeY()); // same as 0, center 00248 wait(1); 00249 myLCD.scroll(myLCD.sizeY()>>1); // half screen 00250 wait(1); 00251 myLCD.scrollreset(); // center 00252 wait(1); 00253 for(unsigned short i=1; i<=myLCD.sizeY(); i++) 00254 { 00255 myLCD.scroll(i); 00256 wait_ms(2); 00257 } 00258 wait(2); 00259 // color inversion 00260 for(unsigned short i=0; i<=8; i++) 00261 { 00262 myLCD.invert(i&1); 00263 wait_ms(200); 00264 } 00265 wait(2); 00266 // bmp 16bit test 00267 myLCD.cls(); 00268 t.reset(); 00269 for(int y=0; y<myLCD.height(); y+=34) 00270 { 00271 for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); 00272 } 00273 time=t.read_us(); 00274 myLCD.locate(2,55); 00275 myLCD.set_font((unsigned char*) Terminal6x8); 00276 myLCD.printf("Bmp speed: %.3fms", (float)time/1000); 00277 pc.printf("Bmp speed: %.3fms\r\n", (float)time/1000); 00278 wait(2); 00279 } 00280 }
Generated on Fri Jul 22 2022 11:33:44 by
1.7.2