?? main.c
字號(hào):
/*
**************************************************************************
* @file main.c
* @author dayong
* @version V1.0
*
* @brief This file provides program functions.
***************************************************************************
*/
/* Includes---------------------------------*/
#include <stdio.h>
#include "stm32f10x.h"
#include "fsmc_sram.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/pushbutton.h"
#include "lcdhal.h"
#include "touchstreen.h"
#include "usart.h"
#include "stdio.h"
typedef unsigned char tBoolean;
#define false 0
#define true 1
/**************全局變量聲明*************************/
static __IO uint32_t TimingDelay;
//USART1 ************************
uint8_t TxBuffer1[];
uint8_t RxBuffer1[],rec_f,tx_flag;
__IO uint8_t TxCounter1 = 0x00;
__IO uint8_t RxCounter1 = 0x00;
uint32_t Rec_Len;
TOUCH_CorrectionTypeDef g_strTouchCorrectionStruct; //觸摸屏矯正量 結(jié)構(gòu)體
MATRIX g_MATRIX; // 矯正矩陣聲明 結(jié)構(gòu)體
unsigned char g_ucPenUpDownState;
PointTypeDef g_strDpy_Point;
//**************引用函數(shù)聲明***********************
extern const tDisplay g_s240X400_SPFD5420;
/***************圖形控件結(jié)構(gòu)體聲明***************************/
extern tCanvasWidget g_sBackground;
extern tCanvasWidget g_sHeading;
//***************添加按鈕控件聲明
extern tPushButtonWidget g_sPushBtn_ESC; //Esc按鈕
extern tPushButtonWidget g_sPushBtn_UP;
extern tPushButtonWidget g_sPushBtn_DOWN;
extern tPushButtonWidget g_sPushBtn_LEFT;
extern tPushButtonWidget g_sPushBtn_RIGHT;
extern tPushButtonWidget g_sPushBtn_OK;
/****************聲明按鈕回調(diào)函數(shù)**************************/
void OnButtonPress(tWidget *pWidget);
/****************創(chuàng)建各個(gè)控件**************************/
Canvas(g_sBackground, WIDGET_ROOT, 0, &g_sHeading,
&g_s240X400_SPFD5420, 0, 23, 230, (400 - 23),
CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0);
Canvas(g_sHeading, &g_sBackground, &g_sPushBtn_ESC, 0,
&g_s240X400_SPFD5420, 0, 0, 400, 23,
(CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT),
ClrDarkBlue, ClrWhite, ClrWhite, &g_sFontCm20, "hello-widget", 0, 0);
//聲明各按鈕
RectangularButton(g_sPushBtn_ESC, &g_sBackground, &g_sPushBtn_UP, 0,
&g_s240X400_SPFD5420, 20, 200, 60, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite,
&g_sFontCmss22b, "Esc", 0, 0, 0, 0, 0);
RectangularButton(g_sPushBtn_UP, &g_sBackground, &g_sPushBtn_DOWN, 0,
&g_s240X400_SPFD5420, 80, 200, 60, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite,
&g_sFontCmss22b, "UP", 0, 0, 0, 0, 0);
RectangularButton(g_sPushBtn_DOWN, &g_sBackground, &g_sPushBtn_LEFT, 0,
&g_s240X400_SPFD5420, 140, 200, 60, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite,
&g_sFontCmss22b, "WN", 0, 0, 0, 0, 0);
RectangularButton(g_sPushBtn_LEFT, &g_sBackground, &g_sPushBtn_RIGHT, 0,
&g_s240X400_SPFD5420, 200, 200, 60, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite,
&g_sFontCmss22b, "L", 0, 0, 0, 0, 0);
RectangularButton(g_sPushBtn_RIGHT, &g_sBackground, &g_sPushBtn_OK, 0,
&g_s240X400_SPFD5420, 260, 200, 60, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite,
&g_sFontCmss22b, "R", 0, 0, 0, 0, 0);
RectangularButton(g_sPushBtn_OK, &g_sBackground, 0, 0,
&g_s240X400_SPFD5420, 320, 200, 60, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite,
&g_sFontCmss22b, "OK", 0, 0, 0, 0, 0);
/*LCD ------------------------------------------------*/
void RCC_Configuration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 |RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOD| RCC_APB2Periph_GPIOE , ENABLE);
}
/****************************************************************************
* 名 稱:void GPIO_Configuration(void)
* 功 能:通用IO口配置
* 入口參數(shù):無
* 出口參數(shù):無
* 說 明:
* 調(diào)用方法:
****************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //狀態(tài)LED1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //通用推挽輸出模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //輸出模式最大速度50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/****************************************************************************
* 名 稱:void Delay_us(__IO uint32_t nTime)
* 功 能:定時(shí)延時(shí)程序 10us為單位
* 入口參數(shù):無
* 出口參數(shù):無
* 說 明:
* 調(diào)用方法:無
****************************************************************************/
void Delay_us(__IO uint32_t nTime)
{
// TimingDelay = nTime;
//while(TimingDelay != 0);
while(nTime --);
}
/****************************************************************************
* 名 稱:void TimingDelay_Decrement(void)
* 功 能:獲取節(jié)拍程序
* 入口參數(shù):無
* 出口參數(shù):無
* 說 明:
* 調(diào)用方法:無
****************************************************************************/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
extern const tDisplay g_s240X400_SPFD5420;
tContext sContext;
int main(void)
{
tRectangle RectFillStructure;
RCC_Configuration(); //系統(tǒng)時(shí)鐘初始化及端口外設(shè)時(shí)鐘使能
GPIO_Configuration(); //狀態(tài)LED1的初始化
USART1_IO_Configuration(); //USART1初始化
USART_Config(USART1);
USART1_NVIC_Configuration();
XTP2046_Init(); //SPI1 觸摸電路初始化
TS_GPIO_Configuration();
FSMC_LCD_Init(); //FSMC TFT接口初始化
LCD_Init(); //LCD初始化代碼
GPIO_SetBits(GPIOD, GPIO_Pin_6);
//TFT_CLEAR(0,0,240,400); //清屏
if (SysTick_Config(720)) //時(shí)鐘節(jié)拍中斷時(shí)10us一次 用于定時(shí)
{
while (1);
}
Get_TouchCorrection(&g_strTouchCorrectionStruct); //設(shè)置參數(shù)結(jié)構(gòu)體
TS_NVIC_Configuration();
//GrCircleFill(&sContext, 119, 199,20);
GrContextInit(&sContext,&g_s240X400_SPFD5420);
TouchScreenCallbackSet(WidgetPointerMessage);//安裝回調(diào)函數(shù)
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground);//建立控件樹
WidgetPaint(WIDGET_ROOT); //打印控件樹
#if 0 //測試用
RectFillStructure.sXMin = 240;
RectFillStructure.sXMax = 379;
RectFillStructure.sYMin = 149;
RectFillStructure.sYMax = 229;
PixelDraw (0,10, 10, 0xffff);
LineDrawH (0,20,200,20,0xffff);
LineDrawV (0,60,20, 110, 0xffff);
RectFillStructure.sXMin = 15;
RectFillStructure.sXMax = 100;
RectFillStructure.sYMin = 12;
RectFillStructure.sYMax = 159;
RectFill (0, &RectFillStructure, 0xffff);
#endif
while (1)
{
WidgetMessageQueueProcess(); //處理隊(duì)列消息
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -