字體:小 中 大 | |
|
|
2019/11/23 18:19:05瀏覽249|回應0|推薦0 | |
本文為利用9325TP的彩色TFT LCD螢幕,進行撰寫擴充的不同圖形的繪圖程式,文中的原始碼只將有關的幾種繪圖程式寫出,其他的如UART, TIMER等程式,就不在此說明了,請參考過去已經發表的文章,請見諒。 使用的MCU是STC16F2K60S2—28I,設定的頻率是內部27。000Mhz,彩色螢幕是 ILI Technology Corp. a-Si TFT LCD Single Chip Driver 240RGBx320 Resolution and 262K color,
以下是程式的範例 簡單說明,由亂數決定將繪圖的圖形,0=矩形圖,1=線條,2=三角形,3=圓形,而繪製圖形時的位置與顏色,也是由亂數產生,
#include #include "9325tp.c /*------------------------------------------------ 主程式 ------------------------------------------------*/ void main(void) { unsigned long x0,x1,y0,y1,x2,y2,z0,z1; // unsigned short YCOLOR[9] = {0xffff,0x0000,0x001f,0x051f,0xf800,0xf81f,0x07e0,0x7fff,0xffe0}; ...................... while(1) { ................. switch(rand()%4) //亂數產生繪圖的形狀 { case 0: //**** 矩形框 x0 = rand()%200+20; y0 = rand()%150+150; x1 = rand()%200+20; y1 = rand()%150+150; z0 = rand()%8; //亂數產生色彩 if(x0>=220) x0=220;if(x0<=15) x0="15;" span="" style="font-family:新細明體" data-mce-style="font-family: 新細明體;">判斷是否超出邊框 if(y0>=305) y0=305;if(y0<=150) y0="150;</p"> if(x1>=220) x1=220;if(x1<=15) x1="15;</p"> if(y1>=305) y1=305;if(y1<=150) y1="150;" p=""> Rectangle(x0,y0,x1,y1,YCOLOR[z0]); //四角形圖框繪製 break; case 1: //***** 線條繪製 x0 = rand()%200+20; y0 = rand()%150+150; x1 = rand()%200+20; y1 = rand()%150+150; z0 = rand()%8; Line( x0,y0,x1,y1,YCOLOR[z0]); //線條繪圖 Line( x0+1,y0+1,x1+1,y1+1,YCOLOR[z0]); //強化線條圖案 Line( x0+2,y0+2,x1+2,y1+2,YCOLOR[z0]); break; case 2: //******** 三角形 x0 = rand()%200+20; y0 = rand()%150+150; x1 = rand()%200+20; y1 = rand()%150+150; x2 = rand()%200+20; y2 = rand()%150+150; z0 = rand()%8; Line( x0,y0,x1,y1,YCOLOR[z0]); //三角形第一條線形 Line( x0,y0,x2,y2,YCOLOR[z0]); //三角形第二條線形 Line( x1,y1,x2,y2,YCOLOR[z0]); //三角形第三條線形 break; case 3: //********* 圓形 x0 = rand()%200+20;if(x0>=220) x0=220;if(x0<=20) x0="20;</p"> y0 = rand()%150+150;if(y0>=305) y0=305;if(y0<=150) y0="150;</p"> z0 = rand()%8; z1 = rand()%50; for(i=0;i<=360;i+=1) p=""> { x1 =cos(i)*z1; y1 =sin(i)*z1; x2 = x0+x1;if(x2>=225) goto CYCLE;if(x2<=15) goto="" cycle="" span="" style="font-family:新細明體" data-mce-style="font-family: 新細明體;">判斷繪製位置是否超出邊框 y2 = y0+y1;if(y2>=305) goto CYCLE;if(y2<=150) goto="" cycle="" p=""> Put_pixel(x2,y2,YCOLOR[z0]); CYCLE: _nop_(); } break; default: break; } //********* if(AC_min%5==0 && AC_sec==0) //每5分鐘就清除圖案 { Show_RGB(15,225,150,305,0x0ff0); } ........... } } } .......................... //*******************
|
|
( 興趣嗜好|電腦3C ) |