找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3104|回复: 0
收起左侧

刚写的简单GUI画图程序

[复制链接]
ID:51090 发表于 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=坐标横轴,yp=坐标纵轴*/
{
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=坐标横轴,yl=坐标纵轴,genre=坐标*/
{
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);
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表