/*
================================================================================
File Name : GUI_Basic.c
Author : LiYOng
Date : 2008-12-12 15:51
Version : 1.0
Decription: This file contains some basic functions for GUI, It need the LCD
Drive functions
================================================================================
*/
#include "GUI_Basic.H"
#include "GUI_Type.H"
#include "fontlib.h"
/*
================================================================================
Function : GUI_DrawRectangle( )
Description : Draw a rectangle
Input : -pRect, point to a rectangle structure
output : None
================================================================================
*/
void GUI_DrawRectangle( RECT* pRect )
{
LINE line;
line.xs = pRect->xs;
line.xe = pRect->xe;
line.ys = pRect->ys;
line.ye = pRect->ys;
line.Color = pRect->Color;
LCDDrawHRLine( &line );
line.xe = pRect->xs;
line.ye = pRect->ye;
LCDDrawHRLine( &line );
line.xs = pRect->xe;
line.ys = pRect->ye;
LCDDrawHRLine( &line );
line.xe = pRect->xe;
line.ye = pRect->ys;
LCDDrawHRLine( &line );
}
/*
================================================================================
Function : GUI_DrawLine( )
Description : Draw a line
Input : -pLine, point to a line structure
output : None
================================================================================
*/
void GUI_DrawLine( LINE* pLine )
{
INT32S dx; // 直线x轴差值变量
INT32S dy; // 直线y轴差值变量
INT32S dx_sym; // x轴增长方向,为-1时减值方向,为1时增值方向
INT32S dy_sym; // y轴增长方向,为-1时减值方向,为1时增值方向
INT32S dx_x2; // dx*2值变量,用于加快运算速度
INT32S dy_x2; // dy*2值变量,用于加快运算速度
INT32S di; // 决策变量
POINT point;
LINE line;
line.xs = pLine->xs;
line.ys = pLine->ys;
line.xe = pLine->xe;
line.ye = pLine->ye;
line.Color = pLine->Color;
point.Color = pLine->Color;
dx = line.xe - line.xs;
dy = line.ye - line.ys;
/* 判断增长方向,或是否为水平线、垂直线、点 */
if( dx > 0 ) // 判断x轴方向
{
dx_sym = 1; // dx>0,设置dx_sym=1
}
else
{
if( dx < 0 )
{
dx_sym = -1; // dx<0,设置dx_sym=-1
}
else
{
LCDDrawHRLine( &line );
return;
}
}
if( dy > 0 ) // 判断y轴方向
{
dy_sym = 1; // dy>0,设置dy_sym=1
}
else
{
if( dy < 0 )
{
dy_sym = -1; // dy<0,设置dy_sym=-1
}
else
{ // dy==0,画水平线,或一点
LCDDrawHRLine( &line );
return;
}
}
/* 将dx、dy取绝对值 */
dx = dx_sym * dx;
dy = dy_sym * dy;
/* 计算2倍的dx及dy值 */
dx_x2 = dx*2;
dy_x2 = dy*2;
/* 使用Bresenham法进行画直线 */
if( dx >= dy ) // 对于dx>=dy,则使用x轴为基准
{
di = dy_x2 - dx;
while( line.xs != line.xe )
{
point.x = line.xs;
point.y = line.ys;
LCDDrawPoint( &point );
line.xs += dx_sym;
if( di < 0 )
{
di += dy_x2; // 计算出下一步的决策值
}
else
{
di += dy_x2 - dx_x2;
line.ys += dy_sym;
}
}
LCDDrawPoint( &point ); // 显示最后一点
}
else // 对于dx<dy,则使用y轴为基准
{
di = dx_x2 - dy;
while( line.ys != line.ye )
{
point.x = line.xs;
point.y = line.ys;
LCDDrawPoint( &point );
line.ys += dy_sym;
if(di<0)
{
di += dx_x2;
}
else
{
di += dx_x2 - dy_x2;
line.xs += dx_sym;
}
}
LCDDrawPoint( &point ); // 显示最后一点
}
}
/*
================================================================================
Name: PrintFont
Function: Display a character at a special area
Input: 1.Xs : Start position X
2.Ys : Start position Y
3.pFont : A pointer of a font structure
4.Character : The ASCII code of the character.
Output: None
Note: The start position is inputted as a parameter, And the end position is calculated by the FONT
structure.
Author: LiYong
Date : 2008.08.09
================================================================================
*/
void GUI_DisplayFont( INT8U Xs, INT8U Ys, FONT* pFont, char Character )
{
BitBlock Block;
INT32U Bytes;
INT8U DataBuffer[64];
INT8U i;
const unsigned char *offset;
Block.Height = pFont->Height;
Block.Width = pFont->Width;
Block.Color = pFont->Color;
Block.BackColor = pFont->BackColor;
Block.xs = Xs;
Block.ys = Ys;
Bytes = pFont->Width >> 3;
if( pFont->Width & 0x07 )
{
Bytes ++;
}
Bytes *= pFont->Height;
Bytes *= Character - ' ';
if( pFont->Height == 18 )
{
offset = (const unsigned char*)&FontLib_18;
}
else if( pFont->Height == 14 )
{
offset = (const unsigned char*)&FontLib_14;
}
else
{
return;
}
offset += Bytes;
for( i = 0; i < 36; i ++ )
{
//DataBuffer[i] = pgm_read_byte( offset + i );
}
Block.pData = DataBuffer;
PrintBitBlock( &Block );
}
/*
========================================================================================================
Name: DisplayStr
Function: Display a character at a special area
Input:
1.Xs : Start position X
2.Ys : Start position Y
3.pFont : A pointer of a font structure
4.Str : The start address of a string
Output: None
Note: The start position is inputted as a parameter, And the end position is calculated by the FONT
structure.
Author: LiYong
Date : 2008.08.09
========================================================================================================
*/
void GUI_DisplayStr( INT8U xs, INT8U ys, FONT* pFont, char* Str )
{
while( *Str )
{
GUI_DisplayFont( xs, ys, pFont, *Str );
Str ++;
xs += pFont->Width;
}
}
/*
================================================================================
Name: GUI_DrawCircle( )
Function: Display a cycle at a special area
Input: -pCycle, A pinter point to a cycle structure
Output: None
Author: LiYong
Date : 2008.08.09
================================================================================
*/
void GUI_DrawCircle( CIRCLE* pCircle )
{
INT8S draw_x0, draw_y0; // 刽图点坐标变量
INT8S draw_x1, draw_y1;
INT8S draw_x2, draw_y2;
INT8S draw_x3, draw_y3;
INT8S draw_x4, draw_y4;
INT8S draw_x5, draw_y5;
INT8S draw_x6, draw_y6;
INT8S draw_x7, draw_y7;
INT8S xx, yy; // 画圆控制变量
INT8S di; // 决策变量
POINT point;
point.Color = pCircle->Color;
/* 参数过滤 */
if(0 == pCircle->r ) return;
/* 计算出8个特殊点(0、45、90、135、180、225、270度),进行显示 */
point.x = draw_x0 = draw_x1 = pCircle->x;
point.y = draw_y0 = draw_y1 = pCircle->y + pCircle->r;
if( draw_y0 < GUI_LCM_YMAX ) LCDDrawPoint( &point ); // 90度
point.x = draw_x2 = draw_x3 = pCircle->x;
point.y = draw_y2 = draw_y3 = pCircle->y - pCircle->r;
if( draw_y2 >= 0 ) LCDDrawPoint( &point ); // 270度
point.x = draw_x4 = draw_x6 = pCircle->x + pCircle->r;
point.y = draw_y4 = draw_y6 = pCircle->y;
if(draw_x4<GUI_LCM_XMAX) LCDDrawPoint( &point ); // 0度
point.x = draw_x5 = draw_x7 = pCircle->x - pCircle->r;
point.y = draw_y5 = draw_y7 = pCircle->y;
if(draw_x5>=0) LCDDrawPoint( &point ); // 180度
if(1==pCircle->r) return; // 若半径为1,则已圆画完
/* 使用Bresenham法进行画圆 */
di = 3 - 2*pCircle->r; // 初始化决策变量
xx = 0;
yy = pCircle->r;
while(xx<yy)
{ if(di<0)
{ di += 4*xx + 6;
}
else
{ di += 4*(xx - yy) + 10;
yy--;
draw_y0--;
draw_y1--;
draw_y2++;
draw_y3++;
draw_x4--;
draw_x5++;
draw_x6--;
draw_x7++;
}
xx++;
draw_x0++;
draw_x1--;
draw_x2++;
draw_x3--;
draw_y4++;
draw_y5++;
draw_y6--;
draw_y7--;
/* 要判断当前点是否在有效范围内 */
if( (draw_x0<=GUI_LCM_XMAX)&&(draw_y0>
没有合适的资源?快使用搜索试试~ 我知道了~
MCU.zip_LCD12864 ad proteus_hot51_site:www.pudn.com
共778个文件
bak:126个
lst:99个
obj:98个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 79 浏览量
2022-09-24
05:05:10
上传
评论
收藏 1.36MB ZIP 举报
温馨提示
HOT51开发板的示例程序,包括流水灯、AD采集、LCD12864等。
资源推荐
资源详情
资源评论
收起资源包目录
MCU.zip_LCD12864 ad proteus_hot51_site:www.pudn.com (778个子文件)
12864 7KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
STARTUP.A51 5KB
AD转换 14KB
AD转换 13KB
AD转换_uvopt.bak 58KB
AD转换_uvopt.bak 57KB
流水灯_uvopt.bak 56KB
闪烁灯二_uvopt.bak 56KB
闪烁灯一_uvopt.bak 55KB
12864_uvopt.bak 55KB
蜂鸣器发声_uvopt.bak 55KB
矩阵键盘LCD_uvopt.bak 55KB
数码管静态显示_uvopt.bak 55KB
KEILLCD_Opt.Bak 5KB
KEILLCD_Opt.Bak 5KB
KEILLCD_Opt.Bak 5KB
KEILLCD_Uv2.Bak 2KB
KEILLCD_Uv2.Bak 2KB
KEILLCD_Uv2.Bak 2KB
AD转换.Uv2.bak 2KB
AD转换_Uv2.Bak 2KB
AD转换.Uv2.bak 2KB
12864.Uv2.bak 2KB
定时器和外部中断_Uv2.Bak 2KB
闪烁灯二.Uv2.bak 2KB
闪烁灯二_Uv2.Bak 2KB
定时器的使用_Uv2.Bak 2KB
定时器的使用.Uv2.bak 2KB
液晶1602显示_Uv2.Bak 2KB
流水灯.Uv2.bak 2KB
流水灯_Uv2.Bak 2KB
串口发送试验_Uv2.Bak 2KB
蜂鸣器间断发声.Uv2.bak 2KB
蜂鸣器间断发声_Uv2.Bak 2KB
矩阵键盘LCD.Uv2.bak 2KB
蜂鸣器发声.Uv2.bak 2KB
蜂鸣器发声_Uv2.Bak 2KB
数码管静态显示.Uv2.bak 2KB
数码管静态显示_Uv2.Bak 2KB
数码管静态显示_Uv2.Bak 2KB
矩阵键盘.Uv2.bak 2KB
矩阵键盘_Uv2.Bak 2KB
独立按键.Uv2.bak 2KB
12864_Uv2.Bak 2KB
液晶_Uv2.Bak 2KB
电机调速_Uv2.Bak 2KB
步进电机_Uv2.Bak 2KB
点阵显示_Uv2.Bak 2KB
点阵显示.Uv2.bak 2KB
继电器_Uv2.Bak 2KB
AD转换_Uv2.Bak 2KB
AD转换.Uv2.bak 2KB
AD转换_Uv2.Bak 2KB
外部中断的使用_Uv2.Bak 2KB
闪烁灯一.Uv2.bak 2KB
EEPROM_24C02_Uv2.Bak 2KB
定时器的使用_Uv2.Bak 2KB
时钟DS1302LCD_Uv2.Bak 2KB
数码管动态显示_Uv2.Bak 2KB
矩阵键盘LCD_Uv2.Bak 2KB
宏晶看门狗_Uv2.Bak 2KB
闪烁灯一_Uv2.Bak 2KB
sd_Uv2.Bak 2KB
温度采集DS18B20LCD_Uv2.Bak 2KB
共 778 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
APei
- 粉丝: 64
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功