找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5875|回复: 0
收起左侧

stm32单片机自制pda之app.c源代码

[复制链接]
ID:1 发表于 2013-9-5 14:43 | 显示全部楼层 |阅读模式
完整代码下载地址:http://www.51hei.com/f/29782212PDA.rar
#include <stm32f10x_lib.h>
#include "app.h"
#include "sd.h"
#include "ff.h"
#include "touch.h"
#include "ui.h"
#include "delay.h"
#include "ILI9320.h"
#include "rtc.h"//时间设置,屏保用
#include "picdecoder.h"//显示图标用
#include "theme.h"//显示图标用
#include "string.h"//SD卡信息用到
#include "w25x16.h"//关于用到
#include "adc.h"//引用ADC,CPU温度用

/////////////////////////////////////////////
//此文件实现小功能
//时间日期设置
//SD卡
//关于
//////////////////////////////////////////////

//检查SD卡是否存在
u8 SD_Sta;//SD卡存在状态,存在为1,不存在为0
void Check_SD(void)
{
	u8 sta=3;//初始数值,默认SD卡存在
RECHECK:
	if(SD_Init()!=0)
	{
		Windows(10,110,230,210,"注意——SD卡错误",12);//显示窗体,标题栏高18
		show_string(62,136,158,"未检测到SD卡,这将导致无法使用与SD卡相关的功能!",12,color(0,0,0));//文本框高度28,文本框长180
		show_string(62,160,158,"确认不使用SD卡吗?",12,color(0,0,0));//文本框高度28,文本框长180
		Button(20,180,68,204,UNPRESS,"不使用",36,12);//显示是按钮
		Button(172,180,220,204,UNPRESS,"使用",24,12);//显示否按钮
		show_ico(15,133,59,177,sigh.addr,sigh.size);//显示图标
		sta=0;
	}
	else
	{
		SD_Sta=1;//SD卡存在标志
		f_mount(0,&fatfs);
	}
	while(sta==0)
	{
		if(Pen_Point.Key_Sta==Key_Down)
		{
			Pen_Int_Set(0);//关闭中断
			Pen_Point.Key_Sta=Key_Up;
			do//连续读取数据
			{
				Convert_Pos();
				if(Is_In_Area(20,180,68,204))//((Pen_Point.x0>20)&&(Pen_Point.x0<68))&&((Pen_Point.y0>180)&&(Pen_Point.y0<204)))
				sta=1;
				else if(((Pen_Point.x0>172)&&(Pen_Point.x0<220))&&((Pen_Point.y0>180)&&(Pen_Point.y0<204)))
				sta=2;
				else sta=0;
				if(sta==1)Button(20,180,68,204,PRESS,"不使用",36,12);//显示是按钮
				else if(sta==2)Button(172,180,220,204,PRESS,"使用",24,12);//显示否按钮
				else if(sta==0)
				{
					Button(20,180,68,204,UNPRESS,"不使用",36,12);//显示是按钮
					Button(172,180,220,204,UNPRESS,"使用",24,12);//显示否按钮
				}
				Delay_us(50);
			}while(T_PEN==0);
			Pen_Int_Set(1);//开启中断
		}
		if(sta==2)goto RECHECK;//选择否
		else if(sta==1)SD_Sta=0;//选择是,SD标志为SD卡没检测到
	}
	Creat_Readme();//生成Readme文件
}

//刷新SD卡
//成功返回1,失败返回0
u8 Reflash_SD(void)
{
	u8 sta=0;
	if(SD_Sta==0)
	{
		Windows(10,122,230,198,"请插入SD卡",12);//显示窗体,标题栏高18
		show_string(42,148,158,"是否插入SD卡以使用此功能?",12,color(0,0,0));//文本框高度28,文本框长180
		Button(20,168,68,192,UNPRESS,"是(Y)",30,12);//显示是按钮
		Button(172,168,220,192,UNPRESS,"否(N)",30,12);//显示否按钮
		while(sta==0)
		{
			if(Pen_Point.Key_Sta==Key_Down)
			{
				Pen_Int_Set(0);//关闭中断
				Pen_Point.Key_Sta=Key_Up;
				do//连续读取数据
				{
					Convert_Pos();
					if(Is_In_Area(20,168,68,192))//((Pen_Point.x0>20)&&(Pen_Point.x0<68))&&((Pen_Point.y0>168)&&(Pen_Point.y0<192)))
					sta=1;
					else if(Is_In_Area(172,168,220,192))//((Pen_Point.x0>172)&&(Pen_Point.x0<220))&&((Pen_Point.y0>168)&&(Pen_Point.y0<192)))
					sta=2;
					else sta=0;
					if(sta==1)Button(20,168,68,192,PRESS,"是(Y)",30,12);//显示是按钮
					else if(sta==2)Button(172,168,220,192,PRESS,"否(N)",30,12);//显示否按钮
					else if(sta==0)
					{
						Button(20,168,68,192,UNPRESS,"是(Y)",30,12);//显示是按钮
						Button(172,168,220,192,UNPRESS,"否(N)",30,12);//显示否按钮
					}
					Delay_us(50);
				}while(T_PEN==0);
				Pen_Int_Set(1);//开启中断
			}
			if(sta==1)Check_SD();
			else if(sta==2)return 0;//选择是,SD标志为SD卡没检测到
		}
	}
	return SD_Sta;
}

//时间设置UI
#include "rtc.h"
extern const u8 mon_date[12];//引用月份号数数据表
void Adjust_Time(void)
{
	u16 year;
	u8 month,day,hour,minutes,secon;
	u8 key_sta=0;
	u32 count=0;
	Get_Time();
	year=time.year;
	month=time.month;
	day=time.day;
	hour=time.hour;
	minutes=time.minutes;
	secon=time.secon;
	Windows(10,88,230,232,"请设定系统时间",12);
	Hole(110,125,138,139);//年孔
	show_nums(112,127,year,4,12,color(0,0,0),0);
	show_string(139,127,12,"年",12,color(0,0,0));
	Hole(150,125,166,139);//月孔
	show_nums(152,127,month,2,12,color(0,0,0),0);
	show_string(167,127,12,"月",12,color(0,0,0));
	Hole(178,125,194,139);//日孔
	show_nums(180,127,day,2,12,color(0,0,0),0);
	show_string(195,127,12,"日",12,color(0,0,0));
	Hole(110,169,126,183);//时孔
	show_nums(112,171,hour,2,12,color(0,0,0),0);
	show_string(127,171,12,":",12,color(0,0,0));
	Hole(138,169,154,183);//分孔
	show_nums(140,171,minutes,2,12,color(0,0,0),0);
	show_string(155,171,12,":",12,color(0,0,0));
	Hole(166,169,182,183);//秒孔
	show_nums(168,171,secon,2,12,color(0,0,0),0);
	//显示按钮(日期)
	Button_Up(117,113,131,123,UNPRESS);
	Button_Up(150,113,166,123,UNPRESS);
	Button_Up(178,113,194,123,UNPRESS);
	Button_Down(117,140,131,151,UNPRESS);
	Button_Down(150,140,166,151,UNPRESS);
	Button_Down(178,140,194,151,UNPRESS);
	//显示按钮(时间)
	Button_Up(110,157,126,167,UNPRESS);
	Button_Up(138,157,154,167,UNPRESS);
	Button_Up(166,157,182,167,UNPRESS);
	Button_Down(110,184,126,195,UNPRESS);
	Button_Down(138,184,154,195,UNPRESS);
	Button_Down(166,184,182,195,UNPRESS);
	//显示按钮确定,取消
	Button(20,202,68,226,UNPRESS,"确定",24,12);//显示是按钮
	Button(172,202,220,226,UNPRESS,"取消",24,12);//显示否按钮
	//显示带阴影时钟一个
	show_clock_app(61,155,40,hour,minutes,secon,color(255,255,255));	
	show_clock_app(60,154,40,hour,minutes,secon,color(0x40,0x40,0x40));	
	while((key_sta!=13)&&(key_sta!=14))
	{
		Pen_Point.x0=0;
		Pen_Point.y0=0;
		if(Pen_Point.Key_Sta==Key_Down)
		{
			Pen_Int_Set(0);//关闭中断
			Pen_Point.Key_Sta=Key_Up;
			do//连续读取数据
			{
				Convert_Pos();
				if(Is_In_Area(117,113,131,123))key_sta=1;//((Pen_Point.x0>117)&&(Pen_Point.x0<131))&&(Pen_Point.y0>113)&&(Pen_Point.y0<123))key_sta=1;//年上
				else if(Is_In_Area(117,140,131,151))key_sta=2;//((Pen_Point.x0>117)&&(Pen_Point.x0<131))&&(Pen_Point.y0>140)&&(Pen_Point.y0<151))key_sta=2;//年下
				else if(Is_In_Area(150,113,166,123))key_sta=3;//((Pen_Point.x0>150)&&(Pen_Point.x0<166))&&(Pen_Point.y0>113)&&(Pen_Point.y0<123))key_sta=3;//月上
				else if(Is_In_Area(150,140,166,151))key_sta=4;//((Pen_Point.x0>150)&&(Pen_Point.x0<166))&&(Pen_Point.y0>140)&&(Pen_Point.y0<151))key_sta=4;//月下
				else if(Is_In_Area(178,113,194,123))key_sta=5;//((Pen_Point.x0>178)&&(Pen_Point.x0<194))&&(Pen_Point.y0>113)&&(Pen_Point.y0<123))key_sta=5;//日上
				else if(Is_In_Area(178,140,194,151))key_sta=6;//((Pen_Point.x0>178)&&(Pen_Point.x0<194))&&(Pen_Point.y0>140)&&(Pen_Point.y0<151))key_sta=6;//日下
				else if(Is_In_Area(110,157,126,167))key_sta=7;//((Pen_Point.x0>110)&&(Pen_Point.x0<126))&&(Pen_Point.y0>157)&&(Pen_Point.y0<167))key_sta=7;//时上
				else if(Is_In_Area(110,184,126,195))key_sta=8;//((Pen_Point.x0>110)&&(Pen_Point.x0<126))&&(Pen_Point.y0>184)&&(Pen_Point.y0<195))key_sta=8;//时下
				else if(Is_In_Area(138,157,154,167))key_sta=9;//((Pen_Point.x0>138)&&(Pen_Point.x0<154))&&(Pen_Point.y0>157)&&(Pen_Point.y0<167))key_sta=9;//分上
				else if(Is_In_Area(138,184,154,195))key_sta=10;//((Pen_Point.x0>138)&&(Pen_Point.x0<154))&&(Pen_Point.y0>184)&&(Pen_Point.y0<195))key_sta=10;//分下
				else if(Is_In_Area(166,157,182,167))key_sta=11;//((Pen_Point.x0>166)&&(Pen_Point.x0<182))&&(Pen_Point.y0>157)&&(Pen_Point.y0<167))key_sta=11;//秒上
				else if(Is_In_Area(166,184,182,195))key_sta=12;//((Pen_Point.x0>166)&&(Pen_Point.x0<182))&&(Pen_Point.y0>184)&&(Pen_Point.y0<195))key_sta=12;//秒下
				else if(Is_In_Area(20,202,68,226))key_sta=13;//((Pen_Point.x0>20)&&(Pen_Point.x0<68))&&(Pen_Point.y0>202)&&(Pen_Point.y0<226))key_sta=13;//确定
				else if(Is_In_Area(172,202,220,226))key_sta=14;//((Pen_Point.x0>172)&&(Pen_Point.x0<220))&&(Pen_Point.y0>202)&&(Pen_Point.y0<226))key_sta=14;//取消
				else key_sta=0;
				//显示按键状态
				if(key_sta==1)
				{
					Button_Up(117,113,131,123,PRESS);
					year++;
					if(year>2100)year=2000;
				}else Button_Up(117,113,131,123,UNPRESS); 
				if(key_sta==2)
				{
					Button_Down(117,140,131,151,PRESS);
					year--;
					if(year<2000)year=2100;
				}else Button_Down(117,140,131,151,UNPRESS);
				if(key_sta==3)
				{
					Button_Up(150,113,166,123,PRESS);
					month++;
					if(month>12)month=1;
				}else Button_Up(150,113,166,123,UNPRESS);
				if(key_sta==4)
				{
					Button_Down(150,140,166,151,PRESS);
					month--;
					if(month<1)month=12;
				}else Button_Down(150,140,166,151,UNPRESS);
				if(key_sta==5)
				{
					Button_Up(178,113,194,123,PRESS);
					day++;
					if(day>28)
					{
						if(runnian(year))
						{
							if(month==2)
							{
								if(day>(mon_date[month-1]+1))day=1;
							}
							else if(day>mon_date[month-1])day=1;
						}
						else if(day>mon_date[month-1])day=1;
					}
				}else Button_Up(178,113,194,123,UNPRESS);
				if(key_sta==6)
				{
					Button_Down(178,140,194,151,PRESS);
					day--;
					if(day<1)
					{
						if(runnian(year))
						{
							if(month==2)day=29;
							else day=mon_date[month-1];
						}
						else day=mon_date[month-1];
					}
				}else Button_Down(178,140,194,151,UNPRESS);
				if(key_sta==7)
				{
					Button_Up(110,157,126,167,PRESS);
					hour++;
					if(hour>23)hour=0;
				}else Button_Up(110,157,126,167,UNPRESS);
				if(key_sta==8)
				{
					Button_Down(110,184,126,195,PRESS);
					hour--;
					if(hour>23)hour=23;
				}else Button_Down(110,184,126,195,UNPRESS);
				if(key_sta==9)
				{
					Button_Up(138,157,154,167,PRESS);
					minutes++;
					if(minutes>59)minutes=0;
				}else Button_Up(138,157,154,167,UNPRESS);
				if(key_sta==10)
				{
					Button_Down(138,184,154,195,PRESS);
					minutes--;
					if(minutes>59)minutes=59;
				}else Button_Down(138,184,154,195,UNPRESS);
				if(key_sta==11)
				{
					Button_Up(166,157,182,167,PRESS);
					secon++;
					if(secon>59)secon=0;
				}else Button_Up(166,157,182,167,UNPRESS);
				if(key_sta==12)
				{
					Button_Down(166,184,182,195,PRESS);
					secon--;
					if(secon>59)secon=59;
				}else Button_Down(166,184,182,195,UNPRESS);
				if(key_sta==13)Button(20,202,68,226,PRESS,"确定",24,12);//显示是按钮
				else Button(20,202,68,226,UNPRESS,"确定",24,12);//显示是按钮
				if(key_sta==14)Button(172,202,220,226,PRESS,"取消",24,12);//显示否按钮
				else Button(172,202,220,226,UNPRESS,"取消",24,12);//显示否按钮
				//进入延时循环之前先刷新一次显示,避免还没进入延时循环就松开笔
				//刷新显示
				clear(112,127,136,137,color(255,255,255));//年孔
				show_nums(112,127,year,4,12,color(0,0,0),0);
				clear(152,127,164,137,color(255,255,255));//月孔
				show_nums(152,127,month,2,12,color(0,0,0),0);
				clear(180,127,192,137,color(255,255,255));//日孔
				show_nums(180,127,day,2,12,color(0,0,0),0);
				clear(112,171,124,181,color(255,255,255));//时孔
				show_nums(112,171,hour,2,12,color(0,0,0),0);
				clear(140,171,152,181,color(255,255,255));//分孔
				show_nums(140,171,minutes,2,12,color(0,0,0),0);
				clear(168,171,180,181,color(255,255,255));//秒孔
				show_nums(168,171,secon,2,12,color(0,0,0),0);
				while(T_PEN==0)//还在按下
				{
					if(count<300000)
					{
						Delay_us(1);//递加延时设置
						count++;
					}
					else
					{
						Delay_ms(100);
						switch(key_sta)
						{
							case 1:
							{
								year++;
								if(year>2100)year=2000;
							}break;
							case 2:
							{
								year--;
								if(year<2000)year=2100;
							}break;
							case 3:
							{
								month++;
								if(month>12)month=1;
							}break;
							case 4:
							{
								month--;
								if(month<1)month=12;
							}break;
							case 5:
							{
								day++;
								if(day>28)
								{
									if(runnian(year))
									{
										if(month==2)
										{
											if(day>(mon_date[month-1]+1))day=1;
										}
										else if(day>mon_date[month-1])day=1;
									}
									else if(day>mon_date[month-1])day=1;
								}
							}break;
							case 6:
							{
								day--;
								if(day<1)
								{
									if(runnian(year))
									{
										if(month==2)day=29;
										else day=mon_date[month-1];
									}
									else day=mon_date[month-1];
								}
							}break;
							case 7:
							{
								hour++;
								if(hour>23)hour=0;
							}break;
							case 8:
							{
								hour--;
								if(hour>23)hour=23;
							}break;
							case 9:
							{
								minutes++;
								if(minutes>59)minutes=0;
							}break;
							case 10:
							{
								minutes--;
								if(minutes>59)minutes=59;
							}break;
							case 11:
							{
								secon++;
								if(secon>59)secon=0;
							}break;
							case 12:
							{
								secon--;
								if(secon>59)secon=59;
							}break;
						}
						//刷新显示
						clear(112,127,136,137,color(255,255,255));//年孔
						show_nums(112,127,year,4,12,color(0,0,0),0);
						clear(152,127,164,137,color(255,255,255));//月孔
						show_nums(152,127,month,2,12,color(0,0,0),0);
						clear(180,127,192,137,color(255,255,255));//日孔
						show_nums(180,127,day,2,12,color(0,0,0),0);
						clear(112,171,124,181,color(255,255,255));//时孔
						show_nums(112,171,hour,2,12,color(0,0,0),0);
						clear(140,171,152,181,color(255,255,255));//分孔
						show_nums(140,171,minutes,2,12,color(0,0,0),0);
						clear(168,171,180,181,color(255,255,255));//秒孔
						show_nums(168,171,secon,2,12,color(0,0,0),0);
					}
				} 
				//刷新显示时钟
				clear(20,114,101,195,color(0xd4,0xd0,0xc8));//清除时钟位置
				show_clock_app(61,155,40,hour,minutes,secon,color(255,255,255));	
				show_clock_app(60,154,40,hour,minutes,secon,color(0x40,0x40,0x40));	   
			}while(T_PEN==0);
			Pen_Int_Set(1);//开启中断
			count=0;
			//还原按键
			//显示按钮(日期)
			Button_Up(117,113,131,123,UNPRESS);
			Button_Up(150,113,166,123,UNPRESS);
			Button_Up(178,113,194,123,UNPRESS);
			Button_Down(117,140,131,151,UNPRESS);
			Button_Down(150,140,166,151,UNPRESS);
			Button_Down(178,140,194,151,UNPRESS);
			//显示按钮(时间)
			Button_Up(110,157,126,167,UNPRESS);
			Button_Up(138,157,154,167,UNPRESS);
			Button_Up(166,157,182,167,UNPRESS);
			Button_Down(110,184,126,195,UNPRESS);
			Button_Down(138,184,154,195,UNPRESS);
			Button_Down(166,184,182,195,UNPRESS);
			//显示按钮确定,取消
			Button(20,202,68,226,UNPRESS,"确定",24,12);//显示是按钮
			Button(172,202,220,226,UNPRESS,"取消",24,12);//显示否按钮
		}
	}
	if(key_sta==13)Time_Set(year,month,day,hour,minutes,secon);//按下确定则设置时间
}

//格式化SD卡
void Format_SD(void)
{
	u8 key=0;
	Pen_Point.x0=0;
	Pen_Point.y0=0;
	Windows(9,110,229,208,"格式化SD卡……",12);//显示窗体
	show_ico(19,136,51,168,question.addr,question.size);
	show_string(59,140,160,"警告:格式化操作将删除SD卡中的所有数据,是否继续?",12,color(0,0,0));
	Button(19,176,67,200,UNPRESS,"是(Y)",30,12);//显示是按钮
	Button(171,176,219,200,UNPRESS,"否(N)",30,12);//显示否按钮
	while(key==0)
	{
		if(Pen_Point.Key_Sta==Key_Down)
		{
			Pen_Int_Set(0);//关闭中断
			Pen_Point.Key_Sta=Key_Up;
			do//连续读取数据
			{
				Convert_Pos();
				if(Is_In_Area(19,176,67,200))key=1;//((Pen_Point.x0>19)&&(Pen_Point.x0<67))&&((Pen_Point.y0>176)&&(Pen_Point.y0<200)))key=1;
				else if(Is_In_Area(171,176,219,200))key=2;//((Pen_Point.x0>171)&&(Pen_Point.x0<219))&&((Pen_Point.y0>176)&&(Pen_Point.y0<200)))key=2;
				else key=0;
				
				if(key==1)Button(19,176,67,200,PRESS,"是(Y)",30,12);//显示是按钮
				else Button(19,176,67,200,UNPRESS,"是(Y)",30,12);//显示是按钮
				if(key==2)Button(171,176,219,200,PRESS,"否(N)",30,12);//显示否按钮
				else Button(171,176,219,200,UNPRESS,"否(N)",30,12);//显示否按钮
				Delay_us(50);
			}while(T_PEN==0);
			Pen_Int_Set(1);//开启中断
		}
	}
	if(key==1)
	{
		key=0;
		Windows(9,110,229,208,"格式化SD卡……",12);//显示窗体
		show_ico(19,136,51,168,sigh.addr,sigh.size);
		show_string(59,136,160,"警告:正在格式化SD卡,请勿移除SD卡或者切断电源,此过程大约持续1分钟……",12,color(0,0,0));
		Button(101,176,137,200,INVALID,"取消",24,12);//显示取消按钮,居中
		if(f_mkfs(0,0,0)==FR_OK)
		{
			Windows(9,110,229,208,"格式化SD卡……",12);//显示窗体
			show_ico(19,136,51,168,right.addr,right.size);
			show_string(59,146,160,"格式化成功!",12,color(0,0,0));
			Button(101,176,137,200,UNPRESS,"确定",24,12);//显示取消按钮,居中
			f_mount(0,NULL);
			f_mount(0,&fatfs);
		}
		else
		{
			Windows(9,110,229,208,"格式化SD卡……",12);//显示窗体
			show_ico(19,136,51,168,wrong.addr,wrong.size);
			show_string(59,146,160,"格式化失败!",12,color(0,0,0));
			Button(101,176,137,200,UNPRESS,"确定",24,12);//显示取消按钮,居中
		}
		while(key==0)
		{
			if(Pen_Point.Key_Sta==Key_Down)
			{
				Pen_Int_Set(0);//关闭中断
				Pen_Point.Key_Sta=Key_Up;
				do//连续读取数据
				{
					Convert_Pos();
					if(Is_In_Area(101,176,137,200))key=1;//((Pen_Point.x0>101)&&(Pen_Point.x0<137))&&((Pen_Point.y0>176)&&(Pen_Point.y0<200)))key=1;
					else key=0;
					
					if(key==1)Button(101,176,137,200,PRESS,"确定",24,12);//显示取消按钮,居中
					else Button(101,176,137,200,UNPRESS,"确定",24,12);//显示取消按钮,居中
					Delay_us(50);
				}while(T_PEN==0);
				Pen_Int_Set(1);//开启中断
			}
		}
	}
}

//SD卡信息
const u8 sd_note[]={"SD卡没检测到,暂时无法显示相关信息,请插入SD卡后再试!"};
void SD_Card(void)
{
	FATFS *fs;
	u8 key=0;
	char temp[40];
	u32 total_size=0;
	u32 free_size=0;
	u32 used_size=0;
	u32 i;
BEGIN:
	key=0;
	Pen_Point.x0=0;
	Pen_Point.y0=0;
	if(Reflash_SD())
	{
		//获取容量信息
		f_getfree("0:",&free_size,&fs);//获取可用容量
		free_size=free_size*(fs->csize)*512;//得到可用容量
		total_size=((fs->n_fatent-2)*fs->csize)*512;//得到总容量
		used_size=total_size-free_size;//得到已用容量

		Windows(0,0,239,319,"SD卡属性",12);//显示窗体
		Button(221,3,235,16,UNPRESS,"×",12,12);//关闭按钮
		Button(20,269,104,293,UNPRESS,"格式化SD卡",60,12);//显示是按钮
		Button(135,269,219,293,UNPRESS,"安全卸载SD卡",72,12);//显示否按钮
		Hole(8,26,60,78);
		show_ico(10,28,58,76,drive.addr,drive.size);//显示驱动器图标
		show_string(68,36,200,"SD卡状态:",12,color(0,0,0));
		show_string(68,52,200,"已装载!",12,color(0,0,0));
		
		_line_(9,82,229,82,color(0x80,0x80,0x80));
		strcpy(temp,"SD卡类型:");//复制SD卡类型
		switch(SD_Type)
		{
			case SD_TYPE_ERR:strcat(temp,"未知类型");break;
			case SD_TYPE_MMC:strcat(temp,"MMC卡");break;
			case SD_TYPE_V1:strcat(temp,"SD 1.0卡");break;
			case SD_TYPE_V2:strcat(temp,"SD 2.0卡");break;
			case SD_TYPE_V2HC:strcat(temp,"SD 2.0高速卡");break;
		}
		show_string(10,86,220,(u8*)temp,12,color(0,0,0));//显示SD卡类型
		//显示卡的文件系统类型
		strcpy(temp,"文件系统类型:");
		switch(fs->fs_type)
		{
			case 0:strcat(temp,"未知类型");break;
			case FS_FAT12:strcat(temp,"FAT12");break;
			case FS_FAT16:strcat(temp,"FAT16");break;
			case FS_FAT32:strcat(temp,"FAT32");break;
		}
		show_string(10,102,220,(u8*)temp,12,color(0,0,0));
	
		//显示容量
		_line_(9,118,229,118,color(0x80,0x80,0x80));
		//显示卡的已用容量信息
		show_string(10,122,60,"已用容量:",12,color(0,0,0));
		i=show_nums(70,122,used_size,10,12,color(0,0,0),1);
		show_string((10+60+i*6),122,24,"字节",12,color(0,0,0));
		//显示卡的未用容量信息
		show_string(10,138,60,"可用容量:",12,color(0,0,0));
		i=show_nums(70,138,free_size,10,12,color(0,0,0),1);
		show_string((10+60+i*6),138,24,"字节",12,color(0,0,0));
		
		//显示总容量
		_line_(9,154,229,154,color(0x80,0x80,0x80));
		show_string(10,158,48,"总容量:",12,color(0,0,0));
		i=show_nums(58,158,total_size,10,12,color(0,0,0),1);
		show_string((10+48+i*6),158,24,"字节",12,color(0,0,0));
		//显示进度条百分比UI
		show_string(10,174,48,"已使用:",12,color(0,0,0));
		Progress_Bar(9,190,220,used_size,total_size,1);
		show_string(10,208,48,"剩余:",12,color(0,0,0));
		Progress_Bar(9,224,220,free_size,total_size,1);
		while(key==0)
		{
			if(Pen_Point.Key_Sta==Key_Down)
			{
				Pen_Int_Set(0);//关闭中断
				Pen_Point.Key_Sta=Key_Up;
				do//连续读取数据
				{
					Convert_Pos();
					if(Is_In_Area(20,269,104,293))key=1;//((Pen_Point.x0>20)&&(Pen_Point.x0<104))&&((Pen_Point.y0>269)&&(Pen_Point.y0<293)))key=1;
					else if(Is_In_Area(135,269,219,293))key=2;//((Pen_Point.x0>135)&&(Pen_Point.x0<219))&&((Pen_Point.y0>269)&&(Pen_Point.y0<293)))key=2;
					else if(Is_In_Area(221,3,235,16))key=3;//((Pen_Point.x0>221)&&(Pen_Point.x0<235))&&((Pen_Point.y0>3)&&(Pen_Point.y0<16)))key=3;
					else key=0;
					
					if(key==3)Button(221,3,235,16,PRESS,"×",12,12);//关闭按钮
					else Button(221,3,235,16,UNPRESS,"×",12,12);//关闭按钮
					if(key==1)Button(20,269,104,293,PRESS,"格式化SD卡",60,12);//显示是按钮
					else Button(20,269,104,293,UNPRESS,"格式化SD卡",60,12);//显示是按钮
					if(key==2)Button(135,269,219,293,PRESS,"安全卸载SD卡",72,12);//显示否按钮
					else Button(135,269,219,293,UNPRESS,"安全卸载SD卡",72,12);//显示否按钮
					Delay_us(50);
				}while(T_PEN==0);
				Pen_Int_Set(1);//开启中断
			}
		}
		if(key==1)
		{
			key=0;
			goto FORMAT;
		}
		if(key==2)
		{
			key=0;
			Pen_Point.x0=0;
			Pen_Point.y0=0;
			goto UNMOUNT;
		}
		if(key==3)goto OUT;
FORMAT: Format_SD();
		goto BEGIN;
UNMOUNT:
		if(f_mount(0,NULL)==FR_OK)
		{
			Windows(9,110,229,208,"安全卸载SD卡",12);//显示窗体
			show_ico(19,136,51,168,right.addr,right.size);
			show_string(59,146,160,"请拔出SD卡!",12,color(0,0,0));
			Button(101,176,137,200,UNPRESS,"确定",24,12);//显示取消按钮,居中
			while(key==0)
			{
				if(Pen_Point.Key_Sta==Key_Down)
				{
					Pen_Int_Set(0);//关闭中断
					Pen_Point.Key_Sta=Key_Up;
					do//连续读取数据
					{
						Convert_Pos();
						if(Is_In_Area(101,176,137,200))key=1;//((Pen_Point.x0>101)&&(Pen_Point.x0<137))&&((Pen_Point.y0>176)&&(Pen_Point.y0<200)))key=1;
						else key=0;
						
						if(key==1)Button(101,176,137,200,PRESS,"确定",24,12);//显示取消按钮,居中
						else Button(101,176,137,200,UNPRESS,"确定",24,12);//显示取消按钮,居中
						Delay_us(50);
					}while(T_PEN==0);
					Pen_Int_Set(1);//开启中断
				}
			}
			if(key)
			{
				key=0;
				Pen_Point.x0=0;
				Pen_Point.y0=0;
				SD_Sta=0;//标记SD卡移除标志
				goto BEGIN1;
			}
		}
	}
	else
	{
BEGIN1:
		Windows(0,0,239,319,"SD卡属性",12);//显示窗体
		Button(221,3,235,16,UNPRESS,"×",12,12);//关闭按钮
		Hole(8,26,60,78);
		show_ico(10,28,58,76,drive.addr,drive.size);//显示驱动器图标
		show_string(68,36,200,"SD卡状态:",12,color(0,0,0));
		show_string(68,52,200,"未装载!",12,color(0,0,0));
		
		_line_(9,82,229,82,color(0x80,0x80,0x80));
		show_string(9,86,216,"请插入SD卡以获取相关信息!",16,color(0,0,0));
		Button(89,269,149,293,UNPRESS,"加载SD卡",48,12);
		while(key==0)
		{
			if(Pen_Point.Key_Sta==Key_Down)
			{
				Pen_Int_Set(0);//关闭中断
				Pen_Point.Key_Sta=Key_Up;
				do//连续读取数据
				{
					Convert_Pos();
					if(Is_In_Area(89,269,149,293))key=1;//((Pen_Point.x0>89)&&(Pen_Point.x0<149))&&((Pen_Point.y0>269)&&(Pen_Point.y0<293)))key=1;
					else if(Is_In_Area(221,3,235,16))key=2;//((Pen_Point.x0>221)&&(Pen_Point.x0<235))&&((Pen_Point.y0>3)&&(Pen_Point.y0<16)))key=2;
					else key=0;
					
					if(key==1)Button(89,269,149,293,PRESS,"加载SD卡",48,12);
					else Button(89,269,149,293,UNPRESS,"加载SD卡",48,12);
					if(key==2)Button(221,3,235,16,PRESS,"×",12,12);//关闭按钮
					else Button(221,3,235,16,UNPRESS,"×",12,12);//关闭按钮
					Delay_us(50);
				}while(T_PEN==0);
				Pen_Int_Set(1);//开启中断
			}
		}
		if(key==1)goto BEGIN;			                      
		if(key==2)goto OUT;
	}
OUT:
	Pen_Point.x0=0;
	Pen_Point.y0=0;
}

//关于
extern u16 DeviceCode;
extern u8 opera_s,opera_m,opera_h;//引用开机时间统计
extern u8 reflash;//引用rtc更新标志
void About(void)
{
	u8 key=0;
	float temp;
	u8 lon;
	Windows(0,0,239,319,"系统属性",12);
	Button(221,3,235,16,UNPRESS,"×",12,12);//关闭按钮
	//显示控制器信息
	_line_(9,26,229,26,color(0x80,0x80,0x80));
	_line_(9,26,9,134,color(0x80,0x80,0x80));
	_line_(9,134,229,134,color(0x80,0x80,0x80));
	_line_(229,26,229,134,color(0x80,0x80,0x80));
	clear(19,20,55,32,color(0xd4,0xd0,0xc8));
	show_string(19,20,200,"控制器",12,color(0,0,0));
	show_string(19,36,200,"控制器型号:STM32F103RBT6",12,color(0,0,0));
	show_string(19,52,200,"内核:Cortex-M3",12,color(0,0,0));
	show_string(19,68,200,"主频:72MHz",12,color(0,0,0));
	show_string(19,84,200,"RAM:20KB",12,color(0,0,0));
	show_string(19,100,200,"ROM:128KB",12,color(0,0,0));
	show_string(19,116,200,"控制器温度:",12,color(0,0,0));
	//显示显示器信息
	_line_(9,146,229,146,color(0x80,0x80,0x80));
	_line_(9,146,9,206,color(0x80,0x80,0x80));
	_line_(9,206,229,206,color(0x80,0x80,0x80));
	_line_(229,146,229,206,color(0x80,0x80,0x80));
	clear(19,140,55,152,color(0xd4,0xd0,0xc8));
	show_string(19,140,200,"显示器",12,color(0,0,0));
	show_string(19,156,200,"TFT LCD ID:",12,color(0,0,0));
	show_nums(91,156,DeviceCode,10,12,color(0,0,0),1);
	show_string(19,172,200,"有效色素:64K",12,color(0,0,0));
	show_string(19,188,200,"像素:240×320",12,color(0,0,0));
	//显示显示器信息
	_line_(9,218,229,218,color(0x80,0x80,0x80));
	_line_(9,218,9,278,color(0x80,0x80,0x80));
	_line_(9,278,229,278,color(0x80,0x80,0x80));
	_line_(229,218,229,278,color(0x80,0x80,0x80));
	clear(19,212,115,224,color(0xd4,0xd0,0xc8));
	show_string(19,212,200,"字库、图标储存器",12,color(0,0,0));
	show_string(19,228,200,"型号:Winbond 25Q64BVS1G-1022",12,color(0,0,0));
	show_string(19,244,200,"容量:8MB",12,color(0,0,0));
	show_string(19,260,200,"设备ID:",12,color(0,0,0));
	show_nums(67,260,SPI_Flash_ReadID(),10,12,color(0,0,0),1);
	//显示开机时间
	_line_(9,290,229,290,color(0x80,0x80,0x80));
	_line_(9,290,9,314,color(0x80,0x80,0x80));
	_line_(9,314,229,314,color(0x80,0x80,0x80));
	_line_(229,290,229,314,color(0x80,0x80,0x80));
	clear(19,280,67,294,color(0xd4,0xd0,0xc8));
	show_string(19,284,200,"开机时间",12,color(0,0,0));
	while(key==0)
	{
		if(reflash)
		{
			reflash=0;
			temp=Get_Temp();
			//显示CPU温度
			clear(91,116,200,128,color(0xd4,0xd0,0xc8));
			lon=show_nums(91,116,(u8)temp,10,12,color(0,0,0),1);
			show_string((91+lon*6),116,6,".",12,color(0,0,0));
			show_nums((97+lon*6),116,(u8)((temp-(u8)temp)*100),2,12,color(0,0,0),0);
			show_string((97+lon*6+12),116,12,"℃",12,color(0,0,0));
			//显示开机时间
			clear(19,297,73,309,color(0xd4,0xd0,0xc8));
			show_string(19,297,200,"   :  :  ",12,color(0,0,0));
			show_nums(19,297,opera_h,3,12,color(0,0,0),0);
			show_nums(43,297,opera_m,2,12,color(0,0,0),0);
			show_nums(61,297,opera_s,2,12,color(0,0,0),0);
		}
		if(Pen_Point.Key_Sta==Key_Down)
		{
			Pen_Int_Set(0);//关闭中断
			Pen_Point.Key_Sta=Key_Up;
			do//连续读取数据
			{
				Convert_Pos();
				if(Is_In_Area(221,3,235,16))key=1;//((Pen_Point.x0>221)&&(Pen_Point.x0<235))&&((Pen_Point.y0>3)&&(Pen_Point.y0<16)))key=1;
				else key=0;
				if(key)Button(221,3,235,16,PRESS,"×",12,12);//关闭按钮
				else Button(221,3,235,16,UNPRESS,"×",12,12);//关闭按钮
				Delay_us(50);
			}while(T_PEN==0);
			Pen_Int_Set(1);//开启中断
		}
	}
}

//屏保延时
u8 Scr_Delay=0;//屏保延时
u8 Scr_Count;//屏保计数
u8 Scr_Flag=0;//屏保启动标志
void Screen_Saver_Delay(void)
{
	u8 key=0;
	u32 i=0;
	u8 temp=Scr_Delay;
	//记录用
	FIL fil;
	UINT byteleft;
	Windows(9,89,229,229,"屏保延时",12);
	show_string(19,117,220,"请设定屏保启动延时,0为不启动屏保。",12,color(0,0,0));
	show_string(19,155,220,"设定延时为:",12,color(0,0,0));
	show_string(115,155,220,"秒",12,color(0,0,0));
	Hole(91,153,113,169);
	Button_Up(94,140,110,151,UNPRESS);
	Button_Down(94,170,110,181,UNPRESS);
	Button(19,195,67,219,UNPRESS,"确定",24,12);//显示是按钮
	Button(171,195,219,219,UNPRESS,"取消",24,12);//显示否按钮
	show_nums(93,155,temp,3,12,color(0,0,0),0);
BEGIN:
	while(key==0)
	{
		if(Pen_Point.Key_Sta==Key_Down)
		{
			Pen_Int_Set(0);//关闭中断
			Pen_Point.Key_Sta=Key_Up;
			do//连续读取数据
			{
				Convert_Pos();
				if(Is_In_Area(94,140,110,169))key=1;
				else if(Is_In_Area(94,170,110,181))key=2;
				else if(Is_In_Area(19,195,67,219))key=3;
				else if(Is_In_Area(171,195,219,219))key=4;
				else key=0;
				if(key==1)Button_Up(94,140,110,151,PRESS);
				else Button_Up(94,140,110,151,UNPRESS);
				if(key==2)Button_Down(94,170,110,181,PRESS);
				else Button_Down(94,170,110,181,UNPRESS);
				if(key==3)Button(19,195,67,219,PRESS,"确定",24,12);//显示是按钮
				else Button(19,195,67,219,UNPRESS,"确定",24,12);//显示是按钮
				if(key==4)Button(171,195,219,219,PRESS,"取消",24,12);//显示否按钮
				else Button(171,195,219,219,UNPRESS,"取消",24,12);//显示否按钮
				i=0;
				while(T_PEN==0)
				{
					if(i<300000)
					{
						Delay_us(1);
						i++;
					}
					else
					{
						if(key==1)temp++;
						if(key==2)temp--;
						clear(93,157,111,169,color(255,255,255));
						show_nums(93,155,temp,3,12,color(0,0,0),0);
						Delay_ms(100);
					}				
				}
			}while(T_PEN==0);
			Pen_Int_Set(1);//开启中断
			Button_Up(94,140,110,151,UNPRESS);
			Button_Down(94,170,110,181,UNPRESS);
			Button(19,195,67,219,UNPRESS,"确定",24,12);//显示是按钮
			Button(171,195,219,219,UNPRESS,"取消",24,12);//显示否按钮
		}
	}
	if((key==1)||(key==2))
	{
		if(key==1)temp++;
		if(key==2)temp--;
		key=0;
		clear(93,157,111,169,color(255,255,255));
		show_nums(93,155,temp,3,12,color(0,0,0),0);
		goto BEGIN;
	}
	if(key==3)
	{
		Scr_Delay=temp;
		Scr_Count=temp;
		if(Reflash_SD())
		{
			if(f_open(&fil,"0:/setup.set",FA_OPEN_ALWAYS|FA_WRITE)==FR_OK)
			{
				f_lseek(&fil,19);
				f_write(&fil,&Scr_Delay,1,&byteleft);
				f_close(&fil);
			}
		}
   	}
}

//黑屏延时
u8 Blk_Delay=0;//黑屏延时
u8 Blk_Count;//黑屏计数
u8 Blk_Flag=1;//屏幕亮起标志
void Screen_Blockout_Delay(void)
{
	u8 key=0;
	u32 i=0;
	u8 temp=Blk_Delay;
	//记录用
	FIL fil;
	UINT byteleft;
	Windows(9,89,229,229,"黑屏延时",12);
	show_string(19,117,220,"请设定进入黑屏延时,0为屏幕常亮。",12,color(0,0,0));
	show_string(19,155,220,"设定延时为:",12,color(0,0,0));
	show_string(115,155,220,"秒",12,color(0,0,0));
	Hole(91,153,113,169);
	Button_Up(94,140,110,151,UNPRESS);
	Button_Down(94,170,110,181,UNPRESS);
	Button(19,195,67,219,UNPRESS,"确定",24,12);//显示是按钮
	Button(171,195,219,219,UNPRESS,"取消",24,12);//显示否按钮
	show_nums(93,155,temp,3,12,color(0,0,0),0);
BEGIN:
	while(key==0)
	{
		if(Pen_Point.Key_Sta==Key_Down)
		{
			Pen_Int_Set(0);//关闭中断
			Pen_Point.Key_Sta=Key_Up;
			do//连续读取数据
			{
				Convert_Pos();
				if(Is_In_Area(94,140,110,169))key=1;
				else if(Is_In_Area(94,170,110,181))key=2;
				else if(Is_In_Area(19,195,67,219))key=3;
				else if(Is_In_Area(171,195,219,219))key=4;
				else key=0;
				if(key==1)Button_Up(94,140,110,151,PRESS);
				else Button_Up(94,140,110,151,UNPRESS);
				if(key==2)Button_Down(94,170,110,181,PRESS);
				else Button_Down(94,170,110,181,UNPRESS);
				if(key==3)Button(19,195,67,219,PRESS,"确定",24,12);//显示是按钮
				else Button(19,195,67,219,UNPRESS,"确定",24,12);//显示是按钮
				if(key==4)Button(171,195,219,219,PRESS,"取消",24,12);//显示否按钮
				else Button(171,195,219,219,UNPRESS,"取消",24,12);//显示否按钮
				i=0;
				while(T_PEN==0)
				{
					if(i<300000)
					{
						Delay_us(1);
						i++;
					}
					else
					{
						if(key==1)temp++;
						if(key==2)temp--;
						clear(93,157,111,169,color(255,255,255));
						show_nums(93,155,temp,3,12,color(0,0,0),0);
						Delay_ms(100);
					}				
				}
			}while(T_PEN==0);
			Pen_Int_Set(1);//开启中断
			Button_Up(94,140,110,151,UNPRESS);
			Button_Down(94,170,110,181,UNPRESS);
			Button(19,195,67,219,UNPRESS,"确定",24,12);//显示是按钮
			Button(171,195,219,219,UNPRESS,"取消",24,12);//显示否按钮
		}
	}
	if((key==1)||(key==2))
	{
		if(key==1)temp++;
		if(key==2)temp--;
		key=0;
		clear(93,157,111,169,color(255,255,255));
		show_nums(93,155,temp,3,12,color(0,0,0),0);
		goto BEGIN;
	}
	if(key==3)
	{
		Blk_Delay=temp;
		Blk_Count=temp;
		if(Reflash_SD())
		{
			if(f_open(&fil,"0:/setup.set",FA_OPEN_ALWAYS|FA_WRITE)==FR_OK)
			{
				f_lseek(&fil,21);
				f_write(&fil,&Blk_Delay,1,&byteleft);
				f_close(&fil);
			}
		}
   	}
}

//屏保程序
void Screen_Saver(void)
{
	if(reflash)
	{
		show_clock(119,110,90,color(255,255,0),color(0,0,0));//这个里面已经把reflash还原了
		Show_Digital_Clock(87,210,16,color(0,255,255),color(0,0,0));
		if((time.week==0)||(time.week==6))Show_Digital_Week(95,230,16,color(255,0,0),color(0,0,0));
		else Show_Digital_Week(95,230,16,color(0,255,0),color(0,0,0));
		Show_Digital_Date(63,250,16,color(0,255,255),color(0,0,0));
	}
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表