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 "mbed.h" 00002 00003 #define TFTWIDTH 240 00004 #define TFTHEIGHT 320 00005 00006 #define TFT_NORTH {SPFD5408_MADCTL_MY | SPFD5408_MADCTL_BGR} 00007 #define TFT_EAST {SPFD5408_MADCTL_MX | SPFD5408_MADCTL_MY | SPFD5408_MADCTL_MV | SPFD5408_MADCTL_BGR} 00008 #define TFT_SOUTH {SPFD5408_MADCTL_MX | SPFD5408_MADCTL_BGR} 00009 #define TFT_WEST {SPFD5408_MADCTL_MV | SPFD5408_MADCTL_BGR} 00010 00011 #define BLACK 0x0000 00012 #define BLUE 0x001F 00013 #define RED 0xF800 00014 #define GREEN 0x07E0 00015 #define CYAN 0x07FF 00016 #define MAGENTA 0xF81F 00017 #define YELLOW 0xFFE0 00018 #define WHITE 0xFFFF 00019 00020 #define SPFD5408_SOFTRESET 0x01 00021 #define SPFD5408_SLEEPIN 0x10 00022 #define SPFD5408_SLEEPOUT 0x11 00023 #define SPFD5408_NORMALDISP 0x13 00024 #define SPFD5408_INVERTOFF 0x20 00025 #define SPFD5408_INVERTON 0x21 00026 #define SPFD5408_GAMMASET 0x26 00027 #define SPFD5408_DISPLAYOFF 0x28 00028 #define SPFD5408_DISPLAYON 0x29 00029 #define SPFD5408_COLADDRSET 0x2A 00030 #define SPFD5408_PAGEADDRSET 0x2B 00031 #define SPFD5408_MEMORYWRITE 0x2C 00032 #define SPFD5408_PIXELFORMAT 0x3A 00033 #define SPFD5408_FRAMECONTROL 0xB1 00034 #define SPFD5408_DISPLAYFUNC 0xB6 00035 #define SPFD5408_ENTRYMODE 0xB7 00036 #define SPFD5408_POWERCONTROL1 0xC0 00037 #define SPFD5408_POWERCONTROL2 0xC1 00038 #define SPFD5408_VCOMCONTROL1 0xC5 00039 #define SPFD5408_VCOMCONTROL2 0xC7 00040 #define SPFD5408_MEMCONTROL 0x36 00041 #define SPFD5408_MADCTL 0x36 00042 #define SPFD5408_MADCTL_MY 0x80 00043 #define SPFD5408_MADCTL_MX 0x40 00044 #define SPFD5408_MADCTL_MV 0x20 00045 #define SPFD5408_MADCTL_ML 0x10 00046 #define SPFD5408_MADCTL_RGB 0x00 00047 #define SPFD5408_MADCTL_BGR 0x08 00048 #define SPFD5408_MADCTL_MH 0x04 00049 00050 #define IDLE 1 00051 #define ACTIVE 0 00052 #define COMMAND 0 00053 #define DATA 1 00054 00055 #define TEMPS 40 00056 00057 #define LCD_CS A3 00058 #define LCD_CD A2 00059 #define LCD_WR A1 00060 #define LCD_RD A0 00061 #define LCD_RESET A4 00062 00063 DigitalOut pinRD(LCD_RD); //PA_0; 00064 DigitalOut pinWR(LCD_WR); //PA_1; 00065 DigitalOut pinCD(LCD_CD); //PA_4; 00066 DigitalOut pinCS(LCD_CS); //PB_0; 00067 DigitalOut pinReset(LCD_RESET);//PC_1; 00068 00069 00070 BusInOut portTFT(D8, D9, D2, D3, D4, D5, D6, D7); 00071 00072 void WriteCommand(uint8_t c) 00073 { 00074 pinCD = COMMAND; 00075 pinWR = ACTIVE; 00076 portTFT = c; 00077 pinWR = IDLE; 00078 } 00079 00080 void WriteData(uint8_t d) 00081 { 00082 pinCD = DATA; 00083 wait_ms(1); 00084 wait_ms(1); 00085 pinWR = ACTIVE; 00086 wait_ms(1); 00087 portTFT = d; 00088 wait_ms(1); 00089 pinWR = IDLE; 00090 wait_ms(1); 00091 } 00092 00093 Serial pc(SERIAL_TX, SERIAL_RX); 00094 00095 DigitalOut myled(LED1); 00096 00097 00098 00099 void begin(void) { 00100 00101 pinCS = IDLE; 00102 pinCD = DATA; 00103 pinWR = IDLE; 00104 pinRD = IDLE; 00105 portTFT.output(); 00106 00107 pinReset = ACTIVE; 00108 wait_ms(100); 00109 pinReset = IDLE; 00110 wait_ms(100); 00111 pinCS = ACTIVE; 00112 00113 WriteCommand(SPFD5408_SOFTRESET); 00114 WriteData(0); 00115 wait_ms(50); 00116 00117 WriteCommand(SPFD5408_MEMCONTROL); 00118 WriteData(SPFD5408_MADCTL_MY | SPFD5408_MADCTL_BGR); 00119 00120 WriteCommand(SPFD5408_PIXELFORMAT); 00121 WriteData(0x55); 00122 00123 WriteCommand(SPFD5408_FRAMECONTROL); 00124 WriteData(0x00); 00125 WriteData(0x1B); 00126 00127 WriteCommand(SPFD5408_SLEEPOUT); 00128 WriteData(0); 00129 00130 WriteCommand(SPFD5408_DISPLAYON); 00131 WriteData(0); 00132 } 00133 00134 void setAddrWindow(int x1, int y1, int x2, int y2) { 00135 pinCS = ACTIVE; 00136 wait_us(TEMPS); 00137 WriteCommand(SPFD5408_COLADDRSET); 00138 WriteData(x1 >> 8); 00139 WriteData(x1); 00140 WriteData(x2 >> 8); 00141 WriteData(x2); 00142 wait_us(TEMPS); 00143 pinCS = IDLE; 00144 00145 pinCS = ACTIVE; 00146 wait_us(TEMPS); 00147 WriteCommand(SPFD5408_PAGEADDRSET); 00148 WriteData(y1 >> 8); 00149 WriteData(y1); 00150 WriteData(y2 >> 8); 00151 WriteData(y2); 00152 wait_us(TEMPS); 00153 pinCS = IDLE; 00154 } 00155 00156 00157 void fillRect(uint16_t x1, uint16_t y1, uint16_t w, uint16_t h, uint16_t fillcolor) { 00158 uint8_t hi, lo; 00159 uint16_t x2, y2; 00160 uint16_t i, j; 00161 00162 x2 = x1 + w - 1; 00163 y2 = y1 + h - 1; 00164 setAddrWindow(x1, y1, x2, y2); 00165 00166 hi = fillcolor >> 8; 00167 lo = fillcolor; 00168 00169 pinCS = ACTIVE; 00170 00171 WriteCommand(SPFD5408_MEMORYWRITE); 00172 pinCD = DATA; 00173 for (i = h; i > 0; i--) 00174 { 00175 for (j = w; j > 0; j--) 00176 00177 { 00178 pinWR = ACTIVE; 00179 portTFT = hi; 00180 pinWR = IDLE; 00181 pinWR = ACTIVE; 00182 portTFT = lo; 00183 pinWR = IDLE; 00184 } 00185 } 00186 pinCS = IDLE; 00187 } 00188 00189 00190 int main() 00191 { 00192 begin(); 00193 fillRect(0, 0, 240, 320, BLACK); 00194 fillRect(75, 100, 100, 150, RED); 00195 fillRect(80, 105, 90, 140, YELLOW); 00196 00197 while(1) 00198 { 00199 } 00200 } 00201 00202
Generated on Sat Jul 16 2022 00:32:31 by
1.7.2