📄 main.c
字号:
#include <math.h>
#include <stddef.h>
#include "gui\core\GUI.h"
//#include "gui\core\LCD_ConfDefaults.h"
#include "Target\44b.h"
#include "Target\44blib.h"
/********************************************/
// ARMSYS实验二十三:绘制动画
// 描述:利用GUI提供的API函数绘制动态图像
/********************************************/
/*******************************************************************
*
* Structure containing information for drawing routine
*
*******************************************************************
*/
typedef struct {
I16 *aY;
} PARAM;
/*******************************************************************
*
* Defines
*
********************************************************************
*/
#define LCD_YSIZE 240
#define LCD_XSIZE 320
#define YSIZE (LCD_YSIZE - 100)
#define DEG2RAD (3.1415926f / 180)
#if LCD_BITSPERPIXEL == 1
#define COLOR_GRAPH0 GUI_WHITE
#define COLOR_GRAPH1 GUI_WHITE
#else
#define COLOR_GRAPH0 GUI_GREEN
#define COLOR_GRAPH1 GUI_YELLOW
#endif
/*******************************************************************
*
* Draws the graph area
*
********************************************************************
*/
static void Draw(void * p) {
int i;
PARAM * pParam = (PARAM *)p;
GUI_SetBkColor(GUI_BLACK);
GUI_SetColor(GUI_DARKGRAY);
GUI_ClearRect(19, (LCD_YSIZE - 20) - YSIZE, (LCD_XSIZE - 2), (LCD_YSIZE - 20));//画深灰色的网格线
for (i = 0; i < (YSIZE / 2); i += 20) {
GUI_DrawHLine((LCD_YSIZE - 20) - (YSIZE / 2) + i, 19, (LCD_XSIZE - 2));
if (i) {
GUI_DrawHLine((LCD_YSIZE - 20) - (YSIZE / 2) - i, 19, (LCD_XSIZE - 2));
}
}
for (i = 40; i < (LCD_XSIZE - 20); i += 40) {
GUI_DrawVLine(18 + i, (LCD_YSIZE - 20) - YSIZE, (LCD_YSIZE - 21));
}
GUI_SetColor(COLOR_GRAPH0);
GUI_DrawGraph(pParam->aY, (LCD_XSIZE - 20), 19, (LCD_YSIZE - 20) - YSIZE);//绘制绿色曲线
}
static void Draw2(void * p) {
PARAM * pParam = (PARAM *)p;
Draw(p);
GUI_SetColor(COLOR_GRAPH1);
GUI_DrawGraph(pParam->aY+15, (LCD_XSIZE - 20), 19, (LCD_YSIZE - 20) - YSIZE);//绘制黄色曲线
}
/*******************************************************************
*
* Draws a sine wave
*
********************************************************************
*/
static void GetSineData(I16 * paY, int n) {//取得一个周期的405个点的Y轴坐标
int i;
for (i = 0; i < n; i++) {
float s = sin(i * DEG2RAD * 4);
paY[i] = s * YSIZE / 2 + YSIZE / 2 + 1;
}
}
static void DemoSineWave(void) {
PARAM Param;
I16 * pStart;
int t0, Cnt = 0;
GUI_RECT Rect = {19, (LCD_YSIZE - 20) - YSIZE, (LCD_XSIZE - 2), (LCD_YSIZE - 19)};
GUI_HMEM hMem = GUI_ALLOC_Alloc(405 * sizeof(I16));
GUI_SetColor(GUI_WHITE);
GUI_SetBkColor(GUI_RED);
GUI_ClearRect(0, 0, LCD_XSIZE, 60);
GUI_SetFont(&GUI_FontComic18B_1);
GUI_DispStringAt("Sine wave", 10, 20);
pStart = GUI_ALLOC_h2p(hMem);
GetSineData(pStart, 405);
GUI_SetFont(&GUI_Font6x8);
t0 = GUI_GetTime();
while((GUI_GetTime() - t0) < 10000) {
int t1, tDiff2;
if (Cnt++ % 90) {
Param.aY++;//曲线位移
} else {
Param.aY = pStart;
}
t1 = GUI_GetTime();
GUI_MEMDEV_Draw(&Rect, Draw2, &Param, 0, 0);
tDiff2 = GUI_GetTime() - t1;
if (tDiff2 < 100) {
GUI_Delay(100 - tDiff2);
}
}
GUI_ALLOC_Free(hMem);
}
/*******************************************************************
*
* Labels the x & y-axis
*
********************************************************************
*/
static void Label(void) {//绘制外框
int x, y;
GUI_SetBkColor(GUI_RED);
GUI_Clear();
GUI_SetPenSize(1);
GUI_ClearRect(0, (LCD_YSIZE - 21) - YSIZE, (LCD_XSIZE - 1), (LCD_YSIZE - 1));
GUI_DrawRect(18, (LCD_YSIZE - 21) - YSIZE, (LCD_XSIZE - 1), (LCD_YSIZE - 18));
GUI_SetFont(&GUI_Font6x8);
for (x = 0; x < (LCD_XSIZE - 20); x += 40) {
int xPos = x + 18;
GUI_DrawVLine(xPos, (LCD_YSIZE - 20), (LCD_YSIZE - 14));
GUI_DispDecAt(x / 40, xPos - 2, (LCD_YSIZE - 9), 1);
}
for (y = 0; y < YSIZE / 2; y += 20) {
int yPos = (LCD_YSIZE - 20) - YSIZE / 2 + y;
GUI_DrawHLine(yPos, 13, 18);
if (y) {
GUI_GotoXY(1, yPos - 4);
GUI_DispSDec(-y / 20, 2);
yPos = (LCD_YSIZE - 20) - YSIZE / 2 - y;
GUI_DrawHLine(yPos, 13, 18);
GUI_GotoXY(1, yPos - 4);
GUI_DispSDec(y / 20, 2);
} else {
GUI_DispCharAt('0', 7, yPos - 4);
}
}
}
/*
*******************************************************************
*
* main()
*
*******************************************************************
*/
void Main(void) {
int i=0;
rSYSCFG=CACHECFG;// Using 8KB Cache//
Port_Init();
Uart_Init(0,115200);
Led_Display(0xf);
Delay(0);
Beep(0x01);
Uart_Select(0); //Select UART0//
Uart_Printf("\n*************************************************************************");
Beep(0x0);
Uart_Printf("\n* 立泰电子 *");
Uart_Printf("\n* -GUI应用:动画显示- *");
Uart_Printf("\n* Version 1.10 *");
Uart_Printf("\n* Email:rao_dali@263.net *");
Uart_Printf("\n* UART Config--COM:115.2kbps,8Bit,NP,UART0 *");
Uart_Printf("\n*------------------Begin to Start Drawing,OK? (Y/N)-------------------*");
Led_Display(0x0);
GUI_Init();//对GUI进行初始化(包括对LCD显示的初始化)
GUI_MEMDEV_Load();
Label();
while(1) {
DemoSineWave();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -