前面介绍了桌面化管理的界面制作,这次是实现以按键和触摸相组合来实现功能选择与只需,其界面变化如图1和图2所示。
其中,以触摸键来选取功能,以ISP键来进行确认。
图1 PWM选项
图2 控制选项
实现功能选择的功能函数为:
void gnxz()
{
uint8_t i;
if(f==1)
{
i=n;
if(i<7)
{
i++;
if(i==1)
{
BACK_COLOR=RED;
POINT_COLOR=WHITE;
LCD_ShowCharh(80,220,'P',0);
LCD_ShowCharh(80,212,'W',0);
LCD_ShowCharh(80,204,'M',0);
showhanzi16h(80,280,3,1);
showhanzi16h(80,264,4,1);
}
if(i==2)
{
BACK_COLOR=RED;
POINT_COLOR=WHITE;
LCD_ShowCharh(80,160,'R',0);
LCD_ShowCharh(80,152,'T',0);
LCD_ShowCharh(80,144,'C',0);
BACK_COLOR=WHITE;
POINT_COLOR=RED;
LCD_ShowCharh(80,220,'P',0);
LCD_ShowCharh(80,212,'W',0);
LCD_ShowCharh(80,204,'M',0);
}
if(i==3)
{
showhanzi16h(80,100,5,0);
showhanzi16h(80,84,6,0);
BACK_COLOR=WHITE;
POINT_COLOR=RED;
LCD_ShowCharh(80,160,'R',0);
LCD_ShowCharh(80,152,'T',0);
LCD_ShowCharh(80,144,'C',0);
}
if(i==4)
{
showhanzi16h(80,100,5,1);
showhanzi16h(80,84,6,1);
showhanzi16h(180,280,13,0);
showhanzi16h(180,264,14,0);
}
if(i==5)
{
showhanzi16h(180,280,13,1);
showhanzi16h(180,264,14,1);
showhanzi16h(180,220,11,0);
showhanzi16h(180,204,12,0);
}
if(i==6)
{
showhanzi16h(180,220,11,1);
showhanzi16h(180,204,12,1);
showhanzi16h(180,160,9,0);
showhanzi16h(180,144,10,0);
}
if(i==7)
{
showhanzi16h(180,160,9,1);
showhanzi16h(180,144,10,1);
showhanzi16h(180,100,7,0);
showhanzi16h(180,84,8,0);
}
}
else
{
showhanzi16h(180,100,7,1);
showhanzi16h(180,84,8,1);
showhanzi16h(80,280,3,0);
showhanzi16h(80,264,4,0);
i=0;
}
f=0;
n=i;
}
}
相应的触摸键中断处理函数为:
void TSI0_IRQHandler(void)
{
if (TSI_GetSelfCapMeasuredChannel(APP_TSI) == BOARD_TSI_ELECTRODE_1)
{
if (TSI_GetCounter(APP_TSI) > (uint16_t)(buffer.calibratedData[BOARD_TSI_ELECTRODE_1] + TOUCH_DELTA_VALUE))
{
f=1;
s_tsiInProgress = false;
}
}
TSI_ClearStatusFlags(APP_TSI, kTSI_EndOfScanFlag);
SDK_ISR_EXIT_BARRIER;
}
进行功能测试的主程序为:
int main(void)
{
uint8_t i,n;
gpio_pin_config_t led_config = {
kGPIO_DigitalOutput,
0,
};
gpio_pin_config_t key_config = {
kGPIO_DigitalInput,
0,
};
CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
CLOCK_EnableClock(kCLOCK_Gpio0);
CLOCK_EnableClock(kCLOCK_Gpio1);
CLOCK_EnableClock(kCLOCK_Gpio4);
BOARD_InitPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
GPIO_PinInit(GPIO0, 25U, &led_config);
GPIO_PinInit(GPIO0, 26U, &led_config);
GPIO_PinInit(GPIO0, 24U, &led_config);
GPIO_PinInit(GPIO0, 27U, &led_config);
GPIO_PinInit(GPIO0, 10U, &led_config);
GPIO_PinInit(GPIO0, 28U, &led_config);
GPIO_PinInit(GPIO0, 6U, &key_config);
delay();
LCD_LED_High();
tft_Init();
LCD_Clear(WHITE);
jm();
BACK_COLOR=WHITE;
POINT_COLOR=RED;
showhanzi16h(80,280,3,0);
showhanzi16h(80,264,4,0);
// 触摸初始化处理
f=0;
n=0;
while (1)
{
gnxz();
delay();
if((GPIO_PinRead(GPIO0, 6U))==0)
{
LCD_Clear(WHITE);
if(n==7)
{
show_tbh(80,180,4);
BACK_COLOR=WHITE;
POINT_COLOR=RED;
LCD_ShowStringh(80,140,"Cannot find");
LCD_ShowStringh(100,140," OV7670 ");
LCD_ShowStringh(120,140,"Cannot AI !");
delay();
}
while((GPIO_PinRead(GPIO0, 6U))==1);
LCD_Clear(WHITE);
jm();
n=0;
BACK_COLOR=WHITE;
POINT_COLOR=RED;
showhanzi16h(80,280,3,0);
showhanzi16h(80,264,4,0);
}
}
经程序的编译与下载,当选取图像功能时会显示图3所示界面。
图3 图像处理界面