由于内存原因,仅显示部分代码,详情请下载文章置顶的完整工程。
一、菜单切换精华部分
menu.c
#include "menu.h"
#include "lcd.h"
#include "ttp223.h"
#include "usart.h"
#include "lcd_init.h"
int menu (void)
{
LCD_ShowChinese(90,10,"北京",RED,BLACK,32,1);
LCD_ShowChinese(90,50,"上海",RED,BLACK,32,1);
LCD_ShowChinese(90,90,"广州",RED,BLACK,32,1);
/********************************************************/
uint8_t menu_flag=1;
uint8_t key=0;
while(1)
{
key=Key_SIG_Scanf();
if(key==1)
{
/*控制角标移动*/
menu_flag++;
if(menu_flag==4) menu_flag=1;
}
if(key==2)
{
LCD_Fill(0,0,LCD_W,LCD_H,WHITE);//清全屏为白色
return menu_flag;
}
switch(menu_flag)
{
case 1:
{
LCD_ShowChar(50,10,'*' ,WHITE,BLACK,32,0);
LCD_ShowChar(50,50,' ' ,WHITE,WHITE,32,0);
LCD_ShowChar(50,90,' ' ,WHITE,WHITE,32,0);
}break;
case 2:
{
LCD_ShowChar(50,10,' ' ,WHITE,WHITE,32,0);
LCD_ShowChar(50,50,'*' ,WHITE,BLACK,32,0);
LCD_ShowChar(50,90,' ' ,WHITE,WHITE,32,0);
}break;
case 3:
{
LCD_ShowChar(50,10,' ' ,WHITE,WHITE,32,0);
LCD_ShowChar(50,50,' ' ,WHITE,WHITE,32,0);
LCD_ShowChar(50,90,'*' ,WHITE,BLACK,32,0);
}break;
}
}
}
void menu_beijing(void)
{
uint8_t menu_flag=1;
while(1)
{
uint8_t key=0;
key=Key_SIG_Scanf();
if(key==1)
{
LCD_Fill(0,0,LCD_W,LCD_H,WHITE);//清全屏为白色
return;
}
LCD_ShowChinese(80,10,"天安门",RED,BLACK,32,1);
LCD_ShowChinese(80,50,"故宫",RED,BLACK,32,1);
LCD_ShowChinese(80,90,"万里长城",RED,BLACK,32,1);
LCD_ShowChinese(80,130,"圆明园",RED,BLACK,32,1);
LCD_ShowChinese(80,170,"天坛",RED,BLACK,32,1);
}
}
void menu_shanghai(void)
{
while(1)
{
uint8_t key=0;
key=Key_SIG_Scanf();
if(KEY_SIG1==1)
{
LCD_Fill(0,0,LCD_W,LCD_H,WHITE);//清全屏为白色
return;
}
LCD_ShowChinese(60,10,"东方明珠",RED,BLACK,32,1);
LCD_ShowChinese(60,50,"和平饭店",RED,BLACK,32,1);
LCD_ShowChinese(60,90,"迪士尼",RED,BLACK,32,1);
}
}
void menu_guangzhou(void)
{
while(1)
{
uint8_t key=0;
key=Key_SIG_Scanf();
if(KEY_SIG1==1)
{
LCD_Fill(0,0,LCD_W,LCD_H,WHITE);//清全屏为白色
return;
}
LCD_ShowChinese(60,10,"广州塔",RED,BLACK,32,1);
LCD_ShowChinese(60,50,"南海影视城",RED,BLACK,32,1);
LCD_ShowChinese(60,90,"珠江夜游",RED,BLACK,32,1);
}
}
menu.h
#ifndef __MENU_H
#define __MENU_H
int menu (void);
void menu_beijing(void);
void menu_shanghai(void);
void menu_guangzhou(void);
#endif
二、主函数部分
main.c
#include "gd32e23x.h"
#include "systick.h"
#include <stdio.h>
#include "main.h"
#include "lcd_init.h"
#include "lcd.h"
#include "ttp223.h"
#include "usart.h"
#include "pic.h"
#include "menu.h"
#include "timer.h"
extern const unsigned char gImage_1[];
uint8_t menu_nuo;
int main(void)
{
systick_config(); // 初始化滴答定时器
LCD_Init();//屏幕初始化
LCD_Fill(0,0,LCD_W,LCD_H,WHITE);//清全屏为白色
TTP223_GPIO_Init();
USART1_Init ();
TIM5_Init ();
while(1)
{
menu_nuo=menu ();
if(menu_nuo==1) {menu_beijing();}
if(menu_nuo==2) {menu_shanghai();}
if(menu_nuo==3) {menu_guangzhou();}
printf("%d",Key_SIG_Scanf());
}
}