新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 51單片機總線驅(qū)動

51單片機總線驅(qū)動

作者: 時間:2016-11-29 來源:網(wǎng)絡 收藏
/*****************************************用畫點的方式畫豎線*****************************************/void erect(uchar y0,uchar y1,uchar x){uchar temp,n;if(y0>y1){temp=y0;y0=y1;y1=temp;}n=y1-y0;for(;n>0;n--){sel_point(x,y0+n);}}/*******************************************************布蘭森漢姆(Bresenham)算法畫線 兩端點(x0,y0) (x1,y1)*******************************************************/void Draw_line(uchar x0,uchar y0,uchar x1,uchar y1){int dx,dy; //定義X.Y軸上增加的變量值int sub;int temp; //起點、終點大小比較,交換數(shù)據(jù)時的中間變量uchar flag;if(x0>x1) //X軸上,起點大于終點,交換數(shù)據(jù){temp=x1;x1=x0;x0=temp; temp=y1;y1=y0;y0=temp; } dx=x1-x0; //X軸方向上的增量dy=y1-y0; //Y軸方向上的增量if(dx==0) erect(y0,y1,x0);if(dy==0) rhorizontal(x0,x1,y0);if(dy>0)flag=1;elseflag=0;if((dx!=0)&&(dy!=0)){// 布蘭森漢姆(Bresenham)算法畫線 /if(flag==1){if(dx>=dy) //*近X軸{sub=2*dy-dx; //計算下個點的位置 while(x0!=x1){sel_point(x0,y0); //畫起點x0++; // X軸上加1if(sub>0) // 判斷下下個點的位置{y0++; // 為右上相鄰點,即(x0+1,y0+1)sub+=2*dy-2*dx;}else sub+=2*dy; // 判斷下下個點的位置 }sel_point(x0,y0);}else{sub=2*dy-dx; //*近Y軸 while(y0!=y1){sel_point(x0,y0); //畫起點y0++; if(sub>0) //判斷下下個點的位置{x0++; sub+=2*dx-2*dy;}elsesub+=2*dx;}sel_point(x0,y0);}}else{dy=y0-y1;if(dx>=dy) //*近X軸{sub=2*dy-dx; //計算下個點的位置 while(x0!=x1){sel_point(x0,y0); //畫起點x0++; // X軸上加1if(sub>0) // 判斷下下個點的位置{y0--; // 為右上相鄰點,即(x0+1,y0+1)sub+=2*dy-2*dx;}else sub+=2*dy; // 判斷下下個點的位置 }sel_point(x0,y0);}else{sub=2*dx-dy; //*近Y軸 while(y0!=y1){sel_point(x0,y0); //畫起點y0--; if(sub>0) //判斷下下個點的位置{x0++; sub+=2*dx-2*dy;}elsesub+=2*dx;}sel_point(x0,y0);}}} }/****************************************************畫圓 圓點(x,y) 半徑 r****************************************************/void draw_circle(int x, int y, int r){int a, b, num;a = 0;b = r;while(2 * b * b >= r * r) // 1/8圓即可{sel_point(x + a, y - b); // 0~1sel_point(x - a, y - b); // 0~7sel_point(x - a, y + b); // 4~5sel_point(x + a, y + b); // 4~3sel_point(x + b, y + a); // 2~3sel_point(x + b, y - a); // 2~1sel_point(x - b, y - a); // 6~7sel_point(x - b, y + a); // 6~5a++;num = (a * a + b * b) - r*r;if(num > 0){b--;a--;}}}void lcd_init(){lcd_writecom_two(0x00,0x00,0x24);lcd_writecom_two(0x00,0x00,0x21);lcd_writecom_two(0x00,0x00,0x42);lcd_writecom_two(0x28,0x00,0x43);//28lcd_writecom_two(0x00,0x00,0x40);lcd_writecom_two(0x01e,0x00,0x41);//1elcd_writecom(0xa0);lcd_writecom(0x98);lcd_writecom(0x80);}main(){unsigned char i;lcd_init();Draw_line(0,0,239,127);Draw_line(0,127,239,0);Draw_line(0,0,239,0);Draw_line(0,127,239,127);Draw_line(0,0,0,127);Draw_line(239,0,239,127);while(1){for(i=60;i<150;i++)draw_circle(i,64, 60);}}
上一頁 1 2 3 4 下一頁

評論


技術專區(qū)

關閉