STM32开发板显示界面添加状态栏
扫描二维码
随时随地手机看文章
需要完成的主要工作有:
1)划分显示位置
2)绘制状态栏背景
3)绘制电池图标:一共7种图标baticos[7]
4)绘制时间:只显示时和分
5)循环检测时间变化,并更改显示时间数值,同步判断电池电量,绘制相应图标
源文件:satusbar.c
#include< includes.h >
#include
const u8* baticos[7] =
{
"0:/STATUSBAR/BAT/battery0.bmp",
"0:/STATUSBAR/BAT/battery1.bmp",
"0:/STATUSBAR/BAT/battery2.bmp",
"0:/STATUSBAR/BAT/battery3.bmp",
"0:/STATUSBAR/BAT/battery4.bmp",
"0:/STATUSBAR/BAT/battery5.bmp",
"0:/STATUSBAR/BAT/battery6.bmp"
};
u8 bat_status = 0;
u8 tmer_min = 0;
void statusbar_fun(void)
{
//绘制状态栏
//1)绘制状态栏背景320x12 x=0,y=0,w=320,h=22
LCD_Fill(0,0,320,22,BLACK);
//2)绘制电池电量 24X14右边显示,x=320-5-24,y=2,w=24,h=14
bat_status = 6;
minibmp_decode((u8*)baticos[bat_status],320-5-24,4,24,14,0,0);
//3)绘制时间30x16 x=320-5-24-10-40 y=3,w=40,h=16
{
POINT_COLOR = WHITE;
tmer_min = calendar.min;
LCD_ShowChar(320-5-24-10-40+16,3,':',16,1);
LCD_ShowNum(320-5-24-10-40,3,calendar.hour,2,16);
LCD_ShowNum(320-5-24-10-40+24,3,calendar.min,2,16); }
}
//由其他界面函数中的while(1)里面调用,例如主函数中
void statusbar_change(void)
{
if(tmer_min!=calendar.min)
{
tmer_min = calendar.min;
//1)绘制时间
POINT_COLOR = WHITE;
LCD_Fill(320-5-24-10-40,3,320-5-24-10,19,BLACK);
LCD_ShowChar(320-5-24-10-40+16,3,':',16,1);
LCD_ShowNum(320-5-24-10-40,3,calendar.hour,2,16);
LCD_ShowNum(320-5-24-10-40+24,3,calendar.min,2,16);
//2)绘制电池电量//目前没有添加电池,只是循环改变而已,如果之后添加电池,根据获得的电池量,修改bat_status的值
if(bat_status == 0||bat_status>6)
bat_status =6;
else
bat_status--;
minibmp_decode((u8*)baticos[bat_status],320-5-24,4,24,14,0,0);
}
}
在头文件
//add by joqian for statusbar
extern u8 bat_status;
extern u8 tmer_min;
extern void statusbar_change(void);
显示效果: