?? gui12864.c
字號:
/***********************************************************************************************
* FILE NAME: gui12864.c
* PURPOSE: lcd1286418 GUI Firmware
* DESCRIPTION: ONLY FOR 128*64 PIXEL LCD
* DEVELOPMENT HISTORY:
* Date Author Release Description Of Change
* -------- ------------ --------- ------------------------------------------------
* 08-04-11 XuGuohong 1.0 Testing Edition
/**********************************************************************************************/
/* Include Global Parameters */
#include <iom128v.h>
#include "avr.h"
#include "gui12864.h"
/* Include Global Parameters */
/* Declare Prototypes */
void GuiDrawLine(unsigned char,unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDrawCircle(unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDrawSquare(unsigned char,unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDisCharF3(unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDisStringF3(unsigned char,unsigned char,unsigned char *,unsigned char);
//void GuiDisCharF2(unsigned char,unsigned char,unsigned char,unsigned char);
//void GuiDisCharF1(unsigned char,unsigned char,unsigned char,unsigned char);
void GuiDisLogo(unsigned char);
void GuiDisRoolStringF3(unsigned char,unsigned char,unsigned char,unsigned char *,unsigned char);
void GuiDisBattery(unsigned char,unsigned char,unsigned char);
void GuiDisUsb(unsigned char,unsigned char);
void GuiDisAcin(unsigned char,unsigned char);
void GuiDisTemp(unsigned char,unsigned char,signed char);
void GuiDisShortIcon(unsigned char,unsigned char,unsigned char);
void GuiDisMainMenu(void);
void GuiDisMenuIcon(unsigned char,unsigned char,unsigned char);
/*****************************************
* FUNCTION NAME: GuiDrawLine
* DESCRIPTION: Draw A Line From Between
* Any 2-Point
* (x1,y1) as start point
* (x2,y2) as end point
* Based On "Breshenham Line"
/*****************************************/
void GuiDrawLine(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, unsigned char color)
{
unsigned char temp;
int p; /* p-取值判斷因子 */
unsigned char x; /* x-坐標 */
unsigned char y; /* y-坐標 */
int dx; /* x方向差值 */
int dy; /* y方向差值 */
char signx; /* x方向標識 */
char signy; /* Y方向標識 */
if(x1>123 | y1>63 | x2>123 | y2>63)
return;
x = x1;
y = y1;
/* 1.計算X方向的參數 */
if(x2 > x1)
{
dx = x2 - x1;
signx = 1;
}
else if(x2 < x1)
{
dx = x1 - x2;
signx = -1;
}
else
{
dx = 0;
signx = 0;
}
/* 2.計算Y方向的參數 */
if(y2 > y1)
{
dy = y2 - y1;
signy = 1;
}
else if(y2 < y1)
{
dy = y1 - y2;
signy = -1;
}
else
{
dy = 0;
signy = 0;
}
/* 3.計算首個判斷因子 */
p = 2*dy -dx;
/* 4a.以X方向增長畫圖 */
if(dx >= dy)
{
for(temp=0; temp<dx; temp++)
{
LcdDisplayDot(x,y,color); /* 畫點 */
if(p >= 0) /* 根據P來判斷畫哪一點 */
{
x = x + signx;
y = y + signy;
p = p + 2*(dy - dx); /* dy,dx需要定義定義成有符號的,才能得到正確的值 */
}
else
{
x = x + signx;
y = y;
p = p + 2*dy;
}
}
}
else
{
for(temp=0; temp<dy; temp++)
{
LcdDisplayDot(x,y,color); /* 畫點 */
if(p >= 0) /* 根據P來判斷畫哪一點 */
{
y = y + signy;
x = x + signx;
p = p + 2*(dx - dy);
}
else
{
y = y + signy;
x = x;
p = p + 2*dx;
}
}
}
LcdDisplayDot(x2,y2,color); /* 畫最后一個點 */
}
/*****************************************
* FUNCTION NAME: GuiDrawCircle
* DESCRIPTION: Draw Circle
* Based On "Breshenham Circle"
/*****************************************/
void GuiDrawCircle(unsigned char x0, unsigned char y0, unsigned char r, unsigned char color)
{
int draw_x0, draw_y0; /* 繪制圖點坐標變量 */
int draw_x1, draw_y1;
int draw_x2, draw_y2;
int draw_x3, draw_y3;
int draw_x4, draw_y4;
int draw_x5, draw_y5;
int draw_x6, draw_y6;
int draw_x7, draw_y7;
int xx, yy; /* 畫圓控制變量 */
int di; /* 決策變量 */
/* 參數過濾 */
if(r==0)
return;
/* 計算出8個特殊點(0、45、90、135、180、225、270度),進行顯示 */
draw_x0 = draw_x1 = x0;
draw_y0 = draw_y1 = y0 + r;
LcdDisplayDot(draw_x0, draw_y0, color); // 90度
draw_x2 = draw_x3 = x0;
draw_y2 = draw_y3 = y0 - r;
LcdDisplayDot(draw_x2, draw_y2, color); // 270度
draw_x4 = draw_x6 = x0 + r;
draw_y4 = draw_y6 = y0;
LcdDisplayDot(draw_x4, draw_y4, color); // 0度
draw_x5 = draw_x7 = x0 - r;
draw_y5 = draw_y7 = y0;
LcdDisplayDot(draw_x5, draw_y5, color); // 180度
if(r==1)
return; // 若半徑為1,則已圓畫完
/* 使用Bresenham法進行畫圓 */
di = 3 - 2*r; // 初始化決策變量
xx = 0;
yy = 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--;
/* 要判斷當前點是否在有效范圍內 */
LcdDisplayDot(draw_x0, draw_y0, color);
LcdDisplayDot(draw_x1, draw_y1, color);
LcdDisplayDot(draw_x2, draw_y2, color);
LcdDisplayDot(draw_x3, draw_y3, color);
LcdDisplayDot(draw_x4, draw_y4, color);
LcdDisplayDot(draw_x5, draw_y5, color);
LcdDisplayDot(draw_x6, draw_y6, color);
LcdDisplayDot(draw_x7, draw_y7, color);
}
}
/*****************************************
* FUNCTION NAME: GuiDrawSquare
* DESCRIPTION: Draw Square
* (x0,y0)----------------------------
* | |
* | |
* | |
* | |
* | |
* -----------------------------(x1,y1)
/*****************************************/
void GuiDrawSquare(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char color)
{
GuiDrawLine(x0, y0, x0, y1, color);
GuiDrawLine(x0, y0, x1, y0, color);
GuiDrawLine(x0, y1, x1, y1, color);
GuiDrawLine(x1, y0, x1, y1, color);
}
/*****************************************
* FUNCTION NAME: GuiDisCharF3
* DESCRIPTION: Display ASCII Char
* ---------------------------->
* | x(0-20)
* |
* | y(0-7)
* |
* |
/*****************************************/
void GuiDisCharF3(unsigned char x,unsigned char y,unsigned char data,unsigned char color)
{
unsigned char temp,offset;
offset = x * 6; /* Display Place */
for(temp=0; temp<6; temp++)
{
if(color == 0)
LcdDisplaySeg(y,offset+temp,~font6x8[data-32][temp]);
else
LcdDisplaySeg(y,offset+temp,font6x8[data-32][temp]);
}
}
/*****************************************
* FUNCTION NAME: GuiDisStringF3
* DESCRIPTION: Display ASCII String
* (x0,y0) display start place
* Auto Change Line...
* ---------------------------->
* | x(0-20)
* |
* | y(0-7)
* |
* |
/*****************************************/
void GuiDisStringF3(unsigned char x0,unsigned char y0,unsigned char *p,unsigned char color)
{
while(*p != 0x00)
{
if(x0 == 21)
{
x0 = 0;
y0 = y0+1;
}
GuiDisCharF3(x0,y0,*(p++),color);
x0++;
}
}
/*****************************************
* FUNCTION NAME: GuiDisLogo
* DESCRIPTION: Display One Full Screen
* Picture 128X64...
/*****************************************/
void GuiDisLogo(unsigned char color)
{
unsigned char x=0,y=0;
unsigned int count=0;
for(count=0;count<128*8;count++)
{
if(x ==128)
{
x = 0;
y = y +1;
}
if(color == 0)
LcdDisplaySeg(y,x,~startlogo[count]);
else
LcdDisplaySeg(y,x,startlogo[count]);
x++;
}
}
/****************************************************
* FUNCTION NAME: GuiDisRoolStringF3
* DESCRIPTION: Display One Line With Left Rolling
* ---------------------------->
* | x(0-127)
* |
* | y(0-7)
* |
* |
/****************************************************/
void GuiDisRoolStringF3(unsigned char x0,unsigned char x1,unsigned char y,unsigned char *p,unsigned char color)
{
unsigned int dislength = x1 - x0 + 1; /* 顯示區域的寬度 */
unsigned int textlength=0; /* 要顯示內容的總段數 */
unsigned int totallength; /* 要移動的總長度 */
unsigned int step=0; /* 移動長度計數 */
unsigned char n; /* 字庫字偏移地址 */
unsigned char a; /* 字庫段偏移地址 */
unsigned int temp1,temp2,temp3;
unsigned int i;
while(*(p+textlength) != 0x00) /* 計算顯示內容的總段數 */
{
textlength++;
}
textlength = textlength*6;
totallength = dislength + textlength; /* 計算總移顯示內容的長度 */
for(i=0; i<totallength; i++)
{
step++;
if(step <= dislength)
{
for(temp1=0; temp1<step; temp1++)
{
if((temp1 +1) > textlength)
{
LcdDisplaySeg(y,x1+1-step+temp1,0x00);
}
else
{
LcdDisplaySeg(y,x1+1-step+temp1,font6x8[*(p + temp1 / 6) - 32][temp1 % 6]);
Delay10ms(10);
}
}
}
else if(step > textlength)
{
temp2 = 0;
for(temp1= step - dislength; temp1<step; temp1++)
{
if((temp1 +1) > textlength)
{
LcdDisplaySeg(y,x0 + temp2,0x00);
}
else
{
LcdDisplaySeg(y,x0 + temp2,font6x8[*(p + temp1 / 6) - 32][temp1 % 6]);
Delay10ms(10);
}
temp2++;
}
}
else
{
temp2 = 0;
for(temp1= step - dislength; temp1<step; temp1++)
{
LcdDisplaySeg(y,x0 + temp2,font6x8[*(p + temp1 / 6) - 32][temp1 % 6]);
Delay10ms(10);
temp2++;
}
}
}
}
/************************************************************
* FUNCTION NAME: GuiDisBattery
* DESCRIPTION: Display Battery Icon
* level- 0 warn,1 low,2 20%,3 40%,4 60%,5 80%,6 full
* x - 0-112
* y - 0-7
/************************************************************/
void GuiDisBattery(unsigned char x,unsigned char y,unsigned char level)
{
unsigned char temp;
for(temp=0; temp<16; temp++)
{
LcdDisplaySeg(y,x+temp,battery[level][temp]);
}
}
/************************************************************
* FUNCTION NAME: GuiDisUsb
* DESCRIPTION: Display USB Icon
/************************************************************/
void GuiDisUsb(unsigned char x,unsigned char y)
{
unsigned char temp;
for(temp=0; temp<13; temp++)
{
LcdDisplaySeg(y,x+temp,~usb[temp]);
}
}
/************************************************************
* FUNCTION NAME: GuiDisAcin
* DESCRIPTION: Display AC Input Icon
/************************************************************/
void GuiDisAcin(unsigned char x,unsigned char y)
{
unsigned char temp;
for(temp=0; temp<6; temp++)
{
LcdDisplaySeg(y,x+temp,acin[temp]);
}
}
/************************************************************
* FUNCTION NAME: GuiDisMainMenu
* DESCRIPTION: Display MainMenu Square
/************************************************************/
void GuiDisMainMenu(void)
{
unsigned char temp1;
for(temp1=0; temp1<128; temp1++)
{
LcdDisplaySeg(0,temp1,0XFF);
LcdDisplaySeg(1,temp1,0X07);
}
GuiDrawSquare(0,0,127,54,1);
}
/************************************************************
* FUNCTION NAME: GuiDisShortIcon
* DESCRIPTION: Display Short-Cut Icon
* 0:
* 1:
* 2:
* 3:
* 4:
/************************************************************/
void GuiDisShortIcon(unsigned char x,unsigned char y,unsigned char type)
{
unsigned char temp1,temp2;
for(temp1=0; temp1<2; temp1++)
{
for(temp2=0; temp2<16; temp2++)
{
LcdDisplaySeg(y+temp1,x+temp2,~shorticon1[temp1][temp2]);
}
}
}
/************************************************************
* FUNCTION NAME: GuiDisMenuIcon
* DESCRIPTION: Display MainMenu Name
/************************************************************/
void GuiDisMenuIcon(unsigned char x,unsigned char y,unsigned char type)
{
unsigned char temp1,temp2;
for(temp1=0; temp1<2; temp1++)
{
for(temp2=0; temp2<34; temp2++)
{
LcdDisplaySeg(y+temp1,x+temp2,~menuicon1[temp1][temp2]);
}
}
}
/************************************************************
* FUNCTION NAME: GuiDisTemp
* DESCRIPTION: Display temperature icon and value
* temperature display range from -99 to +99
/************************************************************/
void GuiDisTemp(unsigned char x,unsigned char y,signed char value)
{
unsigned char temp;
signed char sign; /* 寫SIGNED才表明書有符號數 */
for(temp=0; temp<11; temp++)
{
LcdDisplaySeg(y,x+temp,~temperature[temp]);
}
if(value > 0)
{
GuiDisCharF3(x/6 + 2,y,'+',1);
sign = 1;
}
else if(value < 0)
{
GuiDisCharF3(x/6 + 2,y,'-',1);
sign = -1;
}
else
{
GuiDisCharF3(x/6 + 2,y,' ',1);
sign = 0;
}
value = sign * value;
GuiDisCharF3(x/6 + 3,y,(value/10 + 0X30),1);
GuiDisCharF3(x/6 + 4,y,(value%10 + 0X30),1);
for(temp=12; temp<17; temp++)
{
LcdDisplaySeg(y,x+21+temp,temperature[temp]);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -