找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

帖子
查看: 3724|回復(fù): 0
收起左側(cè)

剛寫的簡(jiǎn)單GUI畫圖程序

[復(fù)制鏈接]
ID:51090 發(fā)表于 2014-9-17 23:07 | 顯示全部樓層 |閱讀模式
#include<iom16v.h>
#include<macros.h>
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
#define P2 PORTA
#define background 0x2202
#define E_clear PORTB&=~BIT(2)
#define E_set PORTB|=BIT(2)
#define RW_clear PORTB&=~BIT(1)
#define RW_set PORTB|=BIT(1)
#define RS_clear PORTB&=~BIT(0)
#define RS_set PORTB|=BIT(0)
void delay(uint z_temp)
{
while(z_temp--);
}
void delay_ms(uint z_temp)
{
uint x_temp,y_temp;
for(x_temp=z_temp;x_temp>0;x_temp--)
for(y_temp=120;y_temp>0;y_temp--);
}
void delay_us(uint z_temp)
{
uint x_temp,y_temp;
for(x_temp=z_temp;x_temp>0;x_temp--)
for(y_temp=1;y_temp>0;y_temp--);
}
void write_com(uchar com)
{
E_clear;
RS_clear;
RW_clear;
PORTA=com;
E_set;
E_clear;
}
void write_dat(uchar dat)
{
E_clear;
RS_set;
RW_clear;
PORTA=dat;
E_set;
E_clear;
}
void init()
{
uint i,j;
uchar background_h,background_l;
background_h=background/0xff;
background_l=background%0xff;
DDRA=0XFF;
DDRB=0XFF;
/*for(j=0;j<240;j++)
{
write_com(0);
write_com(0);
write_com(j);
write_com(0);
for(i=0;i<320;i++)
{
write_dat(background_h);
write_dat(background_l);
}
}        */
}
void draw_pin(uint xp,uint yp,uint colorp)
/*xp=坐標(biāo)橫軸,yp=坐標(biāo)縱軸*/
{
write_com(xp%256);
write_com(xp/256);
write_com(yp);
write_com(0);
write_dat(colorp%256);
write_dat(colorp/256);
}

void draw_line(uint xl,uint yl,uint lonl,uint colorl,uchar genre)
/*xl=坐標(biāo)橫軸,yl=坐標(biāo)縱軸,genre=坐標(biāo)*/
{
uint col;uchar i,o,m;
uchar color_h=colorl/256;
uchar color_l=colorl%256;
if(genre==0)
{
while(lonl--)
{
draw_pin(xl++,yl,colorl);
}
}
if(genre==90)
{
while(lonl--)
{
draw_pin(xl,yl++,colorl);
}
}
if(genre==45)
{
while(lonl--)
{
draw_pin(xl++,yl--,colorl);
}
}
if(genre==175)
{
while(lonl--)
{
draw_pin(xl--,yl--,colorl);
}
}
}
void draw_box(uint xb,uint yb,uint with,uint high,uint colorb)
{
while(high--)
{
draw_line(xb,yb++,with,colorb,0);
}
}
void draw_round(uint xr,uint yr,uint rr,uint colorr)
{
int bx,by;
double an=3.1415926,pang;
pang=3.00/rr;
while(an>-3.1415926)
{
an=an-pang;
bx=(uint)(sin(an)*rr+xr);
by=(uint)(cos(an)*rr+yr);
draw_pin(bx,by,colorr);
}
}
void draw_rbox(uint xrb,uint yrb,uint rrb,uint colorrb)
{
while(rrb--)
{
draw_round(xrb,yrb,rrb,colorrb);
}
}
void draw_roundbox(uint xrb,uint yrb,uint rrb,uint clororrb)
{

}
void main()
{
init();
draw_pin(55,33,0xf452);
draw_line(99,88,123,0xf0ff,0);
draw_line(77,66,55,0xaabb,90);
draw_line(77,66,55,0x00f3,45);
draw_line(77,66,55,0x00bb,175);
draw_box(224,446,55,33,0x7777);
draw_round(99,93,66,0x9999);
draw_round(55,88,44,0x4444);
draw_rbox(100,100,33,0xf8b2);
}
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表