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 //********************************************************************** 00002 #include "mbed.h" 00003 #include "TextLCD.h" 00004 00005 #include "star.h" 00006 #include "square.h" 00007 #include "jibanyan.h" 00008 00009 #include "crescent_moon_edge.h" 00010 #include "crescent_moon_mesh.h" 00011 00012 00013 #include "blktest.h" 00014 #include "blktest2.h" 00015 00016 #include "square_160x120_raster.h" 00017 #include "square_160x120_vector.h" 00018 #include "square_160x120_vector_half.h" 00019 #include "square_160x120_hybrid.h" 00020 00021 #include "square_full_vector.h" 00022 #include "square_L_vector.h" 00023 #include "square_M_vector.h" 00024 #include "square_S_vector.h" 00025 00026 00027 #include <stdlib.h> 00028 00029 00030 Serial pc(USBTX, USBRX); // tx, rx 00031 TextLCD lcd(p26, p25, p24, p23, p22, p21); // rs, e, d4-d7 00032 00033 SPI spi(p11, p12, p13); // mosi, miso, sclk 00034 DigitalOut CS(p10); 00035 DigitalOut LDAC(p9); 00036 00037 DigitalOut BLK(p8); // laser blanking 00038 00039 #define CHA 0x7000 // //0x0000 //0x7000 00040 #define CHB 0xF000 // //0x8000 //0xF000 00041 #define BLK_DELAY 80 // < 100 default 00042 //#define BLK_DELAY 160 // < 100 00043 00044 00045 //********************************************************************** 00046 00047 void mcp4922DataSet(char ch, uint16_t dt) 00048 { 00049 if (dt >= 4096) { 00050 //return; 00051 dt = dt &0x0FFF; 00052 } 00053 //return; 00054 // 00055 if (ch == 'A') { 00056 dt = CHA | dt ; //dt = 0b0111000000000000 | dt; 00057 } else { 00058 dt = CHB | dt ; //dt = 0b1111000000000000 | dt; 00059 } 00060 // 00061 CS = 0; 00062 00063 spi.write(dt); 00064 //LPC_SSP0->DR = dt; // | 0x10000; //hardware dependent 00065 //while(1) { 00066 // if( (LPC_SSP0->SR &0x13) == 3) break; 00067 //} 00068 00069 CS = 1; 00070 } 00071 00072 //********************************************************************** 00073 00074 void mcp4922Init() 00075 { 00076 CS = 1; 00077 // SCK = 0; 00078 // SDI = 0; 00079 CS = 0; 00080 LDAC = 1; 00081 // 00082 mcp4922DataSet('A', 0); 00083 mcp4922DataSet('B', 0); 00084 } 00085 00086 00087 00088 void high_flat(void) 00089 { 00090 while(1) { 00091 mcp4922DataSet('A', 4095);//wait_us(20); 00092 mcp4922DataSet('B', 4095);//wait_us(20); 00093 00094 LDAC = 0; 00095 LDAC = 1; 00096 wait_us(100); 00097 } 00098 } 00099 00100 00101 void triangle2(void) 00102 { 00103 int i=0; 00104 00105 while(1) { 00106 i++; 00107 if (i == 256) i = 0; 00108 else if (i < 128) { 00109 mcp4922DataSet('A', (i<<1)<<4);//wait_us(20); 00110 mcp4922DataSet('B', (i<<1)<<4);//wait_us(20); 00111 } else { 00112 mcp4922DataSet('A', ((255 - i)<<1)<<4);//wait_us(20); 00113 mcp4922DataSet('B', ((255 - i)<<1)<<4);//wait_us(20); 00114 } 00115 LDAC = 0; 00116 LDAC = 1; 00117 BLK = i % 2; 00118 wait_us(100); 00119 } 00120 } 00121 00122 00123 /* 00124 void star(void) 00125 { 00126 int i=0; 00127 uint16_t x,y; 00128 00129 while(1) { 00130 x = star001[i++]; 00131 y = star001[i++]; 00132 if (x == 0 && y == 0) { 00133 i = 0; 00134 } 00135 x += 32767; 00136 y += 32767; 00137 x = 65535 - x; // X-axis invert 00138 mcp4922DataSet('A', x>>4);//wait_us(20); 00139 mcp4922DataSet('B', y>>4);//wait_us(20); 00140 LDAC = 0; 00141 LDAC = 1; 00142 wait_us(100); 00143 00144 } 00145 } 00146 */ 00147 /* 00148 void jibanyan(void) 00149 { 00150 int i=0; 00151 uint16_t x,y; 00152 00153 while(1) { 00154 x = jibanyan001[i++]; 00155 y = jibanyan001[i++]; 00156 if (x == 0 && y == 0) { 00157 i = 0; 00158 } 00159 x += 32767; 00160 y += 32767; 00161 x = 65535 - x; // X-axis invert 00162 mcp4922DataSet('A', x>>4);//wait_us(20); 00163 mcp4922DataSet('B', y>>4);//wait_us(20); 00164 LDAC = 0; 00165 LDAC = 1; 00166 wait_us(100); 00167 00168 } 00169 } 00170 */ 00171 00172 /* 00173 void square(void) 00174 { 00175 int i=0; 00176 uint16_t x,y; 00177 bool b; 00178 00179 while(1) { 00180 b = square001[i++]; 00181 x = square001[i++]; 00182 y = square001[i++]; 00183 if (x == 0 && y == 0) { 00184 i = 0; 00185 } 00186 x += 32767; 00187 y += 32767; 00188 mcp4922DataSet('A', x>>4);//wait_us(20); 00189 mcp4922DataSet('B', y>>4);//wait_us(20); 00190 LDAC = 0; 00191 LDAC = 1; 00192 BLK = b; 00193 // wait_us(400); 00194 wait_us(2000); 00195 00196 } 00197 00198 } 00199 */ 00200 00201 00202 00203 /* 00204 void square(void) 00205 { 00206 int i=0; 00207 uint16_t x,y; 00208 00209 while(1) { 00210 x = square001[i++]; 00211 y = square001[i++]; 00212 if (x == 0 && y == 0) { 00213 i = 0; 00214 } 00215 x += 32767; 00216 y += 32767; 00217 x = 65535 - x; // X-axis invert 00218 mcp4922DataSet('A', x>>4);//wait_us(20); 00219 mcp4922DataSet('B', y>>4);//wait_us(20); 00220 LDAC = 0; 00221 LDAC = 1; 00222 wait_us(100); 00223 00224 } 00225 00226 } 00227 */ 00228 00229 00230 00231 00232 00233 Ticker timer; 00234 00235 uint8_t CNT=0; 00236 // timer.attach(&int_timer, 1); // 1 second 00237 void int_timer(void) 00238 { 00239 CNT++; 00240 } 00241 00242 00243 00244 void laserscan(const int *p, const int num) 00245 { 00246 int i = 0; 00247 uint16_t x,y = 0; 00248 00249 // while(1) { 00250 while(CNT < 5) { 00251 00252 x = *(p + i++); 00253 y = *(p + i++); 00254 00255 // if (x == 0 && y == 0) { 00256 // i = 0; 00257 // } 00258 00259 if (i == num) { 00260 i = 0; 00261 } 00262 00263 x += 32767; 00264 y += 32767; 00265 x = 65535 - x; // X-axis invert 00266 00267 mcp4922DataSet('A', x>>4);//wait_us(20); 00268 mcp4922DataSet('B', y>>4);//wait_us(20); 00269 00270 LDAC = 0; 00271 LDAC = 1; 00272 00273 wait_us(100); 00274 } 00275 CNT = 0; 00276 } 00277 00278 00279 // add laser blanking control 00280 void laserscan_blk(const int *p, const int num) 00281 { 00282 int i = 0; 00283 uint16_t x,y = 0; 00284 bool b = 0; 00285 00286 // while(1) { 00287 while(CNT < 5) { 00288 00289 b = *(p + i++); 00290 x = *(p + i++); 00291 y = *(p + i++); 00292 00293 // if (x == 0 && y == 0) { 00294 // i = 0; 00295 // } 00296 00297 if (i == num) { 00298 i = 0; 00299 } 00300 00301 x += 32767; 00302 y += 32767; 00303 x = 65535 - x; // X-axis invert 00304 00305 mcp4922DataSet('A', x>>4);//wait_us(20); 00306 mcp4922DataSet('B', y>>4);//wait_us(20); 00307 LDAC = 0; 00308 LDAC = 1; 00309 00310 wait_us(BLK_DELAY); 00311 // BLK = b; 00312 BLK = 1; 00313 00314 wait_us(200 - BLK_DELAY); // default 00315 // wait_us(400 - BLK_DELAY); 00316 00317 } 00318 CNT = 0; 00319 } 00320 00321 00322 // serial com test 00323 void laserscan_com(void) 00324 { 00325 int i = 0; 00326 int buff[4] = {0,0,0,0}; 00327 uint16_t x,y = 0; 00328 00329 while(1) { 00330 00331 for (i = 0; i < 4; i++) { 00332 char c = pc.getc(); 00333 buff[i] = c; 00334 // lcd.printf("%02X",buff[i]); 00335 00336 } 00337 00338 // lcd.printf("\n"); 00339 00340 x = (buff[1] << 8) + buff[0]; 00341 y = (buff[3] << 8) + buff[2]; 00342 // lcd.printf("x=%04X,y=%04X\n",x,y); 00343 00344 if (x == 0 && y == 0) { 00345 i = 0; 00346 } 00347 00348 x += 32767; 00349 y += 32767; 00350 x = 65535 - x; // X-axis invert 00351 00352 mcp4922DataSet('A', x>>4);//wait_us(20); 00353 mcp4922DataSet('B', y>>4);//wait_us(20); 00354 00355 LDAC = 0; 00356 LDAC = 1; 00357 00358 wait_us(100); 00359 } 00360 } 00361 00362 00363 00364 00365 00366 int main(void) 00367 { 00368 00369 spi.format(16,0); 00370 spi.frequency(20000000); 00371 00372 pc.baud(230400); 00373 00374 mcp4922Init(); 00375 00376 timer.attach(&int_timer, 1); 00377 00378 /* 00379 while(1) { 00380 char c = pc.getc(); 00381 lcd.printf("%02X",c); 00382 00383 // char str[] = "145"; 00384 // int buff = atoi(str); 00385 // lcd.printf("%02X",buff); 00386 00387 laserscan(c); 00388 00389 } 00390 */ 00391 00392 // triangle2(); 00393 // high_flat(); 00394 00395 while(1) { 00396 00397 // non blanking control 00398 // laserscan(jibanyan,jibanyan_dnum); 00399 // laserscan(star,star_dnum); 00400 // laserscan(crescent_moon_edge,crescent_moon_edge_dnum); 00401 // laserscan(crescent_moon_mesh,crescent_moon_mesh_dnum); 00402 00403 // add blanking control 00404 // laserscan_blk(blktest2,blktest2_dnum); 00405 // laserscan_blk(square_20x20_raster,square_20x20_raster_dnum); 00406 // laserscan_blk(square_160x120_raster,square_160x120_raster_dnum); 00407 // laserscan_blk(square_160x120_vector,square_160x120_vector_dnum); 00408 // laserscan_blk(square_160x120_vector_half,square_160x120_vector_half_dnum); 00409 // laserscan_blk(square_160x120_hybrid,square_160x120_hybrid_dnum); 00410 // laserscan_blk(square_full_vector,square_full_vector_dnum); 00411 laserscan_blk(square_L_vector,square_L_vector_dnum); 00412 laserscan_blk(square_M_vector,square_M_vector_dnum); 00413 laserscan_blk(square_S_vector,square_S_vector_dnum); 00414 00415 00416 00417 // add PC serial com 00418 // laserscan_com(); 00419 } 00420 00421 00422 } 00423 00424 00425
Generated on Tue Jul 19 2022 01:02:21 by
1.7.2