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 BLACK 0x0000 00004 #define NAVY 0x000F 00005 #define DARK_GREEN 0x03E0 00006 #define DARK_CYAN 0x03EF 00007 #define MAROON 0x7800 00008 #define PURPLE 0x780F 00009 #define OLIVE 0x7BE0 00010 #define LIGHT_GRAY 0xC618 00011 #define DARK_GRAY 0x7BEF 00012 #define BLUE 0x001F 00013 #define GREEN 0x07E0 00014 #define CYAN 0x07FF 00015 #define RED 0xF800 00016 #define MAGENTA 0xF81F 00017 #define YELLOW 0xFFE0 00018 #define WHITE 0xFFFF 00019 00020 00021 00022 SPI spi (5,6,7); 00023 DigitalOut cs (13); 00024 DigitalOut rst (17); 00025 DigitalOut tcs (23); 00026 00027 00028 00029 int _hwidth = 320; 00030 int _hheight = 240; 00031 00032 void command(int value); 00033 void data(int value); 00034 void config(int index, int value); 00035 void lcd_movePen(int x, int y); 00036 void lcd_fillScreen(int color); 00037 00038 void lcd_point(int x, int y, int color); 00039 void lcd_circle(int x0, int y0, int r, int color); 00040 00041 int main() { 00042 00043 spi.frequency(10000000); 00044 spi.format(9); 00045 00046 00047 cs = 0; 00048 00049 rst = 0; 00050 wait(0.001); 00051 rst = 1; 00052 wait(0.001); 00053 00054 00055 00056 config(0x07 00057 , 1 << 5 // GON 00058 | 0 << 4 // DTE 00059 | 0 << 3 // CM 00060 | 1 << 0 // D[1:0] = 01 - operate, but disp off 00061 ); 00062 00063 config(0x00, 0001); 00064 00065 config(0x07, 1 << 5 | 1 << 4 | 0 << 3 | 3 << 0 ); 00066 00067 config(0x10, 0000); 00068 00069 wait(0.030); 00070 00071 config(0x02, 0x0600); 00072 config(0x01, 0x2b3f); // 1011 00073 config(0x25, 0xa000); // 70Hz freq 00074 00075 00076 00077 00078 00079 while (1) { 00080 00081 lcd_fillScreen(WHITE); 00082 00083 lcd_fillScreen(BLUE); 00084 lcd_fillScreen(GREEN); 00085 00086 } 00087 } 00088 00089 00090 void command(int value) { 00091 spi.write(value & 0xFF); 00092 } 00093 00094 void data(int value) { 00095 spi.write(value | 0x100); 00096 } 00097 00098 void config(int index, int value) { 00099 command(0); 00100 command(index); 00101 data(value >> 8); 00102 data(value); 00103 } 00104 00105 00106 void lcd_movePen(int x, int y) { 00107 config(0x4e, x & 0x00ff); 00108 config(0x4f, y & 0x01ff); 00109 command(0); 00110 command(0x22); 00111 } 00112 00113 void lcd_fillScreen(int color) { 00114 int i = 0; 00115 int j = 0; 00116 00117 lcd_movePen(0, 0); 00118 00119 for (i=0; i < _hwidth; i++) { 00120 for (j=0; j< _hheight; j++) { 00121 data(color >> 8); 00122 data(color); 00123 } 00124 } 00125 } 00126 void lcd_point(int x, int y, int color) { 00127 data(color >> 8); 00128 data(color); 00129 00130 } 00131 00132 void lcd_circle(int x0, int y0, int r, int color) { 00133 int draw_x0, draw_y0; 00134 int draw_x1, draw_y1; 00135 int draw_x2, draw_y2; 00136 int draw_x3, draw_y3; 00137 int draw_x4, draw_y4; 00138 int draw_x5, draw_y5; 00139 int draw_x6, draw_y6; 00140 int draw_x7, draw_y7; 00141 int xx, yy; 00142 int di; 00143 00144 00145 draw_x0 = draw_x1 = x0; 00146 draw_y0 = draw_y1 = y0 + r; 00147 if (draw_y0 < _hheight) { 00148 lcd_point(draw_x0, draw_y0, color); /* 90 degree */ 00149 } 00150 00151 draw_x2 = draw_x3 = x0; 00152 draw_y2 = draw_y3 = y0 - r; 00153 if (draw_y2 >= 0) { 00154 lcd_point(draw_x2, draw_y2, color); /* 270 degree */ 00155 } 00156 00157 draw_x4 = draw_x6 = x0 + r; 00158 draw_y4 = draw_y6 = y0; 00159 if (draw_x4 < _hwidth) { 00160 lcd_point(draw_x4, draw_y4, color); /* 0 degree */ 00161 } 00162 00163 draw_x5 = draw_x7 = x0 - r; 00164 draw_y5 = draw_y7 = y0; 00165 if (draw_x5>=0) { 00166 lcd_point(draw_x5, draw_y5, color); /* 180 degree */ 00167 } 00168 00169 if (r == 1) { 00170 return; 00171 } 00172 00173 di = 3 - 2*r; 00174 xx = 0; 00175 yy = r; 00176 while (xx < yy) { 00177 if (di < 0) { 00178 di += 4*xx + 6; 00179 } else { 00180 di += 4*(xx - yy) + 10; 00181 yy--; 00182 draw_y0--; 00183 draw_y1--; 00184 draw_y2++; 00185 draw_y3++; 00186 draw_x4--; 00187 draw_x5++; 00188 draw_x6--; 00189 draw_x7++; 00190 } 00191 xx++; 00192 draw_x0++; 00193 draw_x1--; 00194 draw_x2++; 00195 draw_x3--; 00196 draw_y4++; 00197 draw_y5++; 00198 draw_y6--; 00199 draw_y7--; 00200 00201 if ( (draw_x0 <= _hwidth) && (draw_y0>=0) ) { 00202 lcd_point(draw_x0, draw_y0, color); 00203 } 00204 00205 if ( (draw_x1 >= 0) && (draw_y1 >= 0) ) { 00206 lcd_point(draw_x1, draw_y1, color); 00207 } 00208 00209 if ( (draw_x2 <= _hwidth) && (draw_y2 <= _hheight) ) { 00210 lcd_point(draw_x2, draw_y2, color); 00211 } 00212 00213 if ( (draw_x3 >=0 ) && (draw_y3 <= _hheight) ) { 00214 lcd_point(draw_x3, draw_y3, color); 00215 } 00216 00217 if ( (draw_x4 <= _hheight) && (draw_y4 >= 0) ) { 00218 lcd_point(draw_x4, draw_y4, color); 00219 } 00220 00221 if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) { 00222 lcd_point(draw_x5, draw_y5, color); 00223 } 00224 if ( (draw_x6 <= _hwidth) && (draw_y6 <= _hheight) ) { 00225 lcd_point(draw_x6, draw_y6, color); 00226 } 00227 if ( (draw_x7 >= 0) && (draw_y7 <= _hheight) ) { 00228 lcd_point(draw_x7, draw_y7, color); 00229 } 00230 } 00231 } 00232 00233 00234
Generated on Tue Jul 19 2022 08:57:52 by
1.7.2