📄 main._c
字号:
#include <iom128v.h>
#include <stdio.h>
#include <macros.h>
#include "lcd.h"
#include "touch.h"
#include "display.h"
#include "rtc.h"
#define BLACK 0x00
#define BLUE 0x03
#define GREEN 0x1C
#define CYAN 0x1F
#define RED 0xE0
#define PURPLE 0xE3
#define YELLOW 0xFC
#define WHITE 0xFF
//extern unsigned char Batter_flag ;
extern unsigned char input_buffer[10];
extern void Input_Data(void);
//extern void Init_Adc(void);
unsigned char time_temp[15];
unsigned char Time_flag = 0;
unsigned char stop_flag = 0;
unsigned char Color_Count;
unsigned char count=0;
unsigned char const Color_Set[] = {
BLACK,BLUE,GREEN,CYAN,RED,PURPLE,YELLOW,WHITE,
};
//unsigned char ADC_ch = 0;//ADC 通道选择位
#define Color_size 2
struct Command const Color[] = {
{
5,5,100,100,100,100,RED,"","",RED,SMALL,WHITE,
},
{
220,140,100,100,100,100,RED,"","",RED,SMALL,WHITE,
},
};
#define Backlight_size 4
struct Command const Backlight[] = {
{ 80,
2,
45,
45,
24,
24,
0x97,
"增加",
"增加",
RED,
SMALL,
WHITE,
},
{//2
80,
50,
45,
45,
24,
24,
0x97,
"减少",
"减少",
RED,
SMALL,
WHITE,
},
{//3
80,
100,
45,
45,
24,
24,
0x97,
"关闭",
"关闭",
RED,
SMALL,
WHITE,
},
{//3
80,
150,
45,
45,
24,
24,
0x97,
"返回",
"返回",
RED,
SMALL,
WHITE,
},
};
#define Start_size 7
struct Command const Start[]={
{ 1,
71,
45,
45,
24,
24,
0x97,
"GoOn",
"GoOn",
RED,
SMALL,
WHITE,
},
{ //时间1
215,
215,
74,
74,
24,
24,
WHITE,
"",
"",
RED,
SMALL,
WHITE,
},
{//2
1,
1,
45,
45,
24,
24,
0x97,
"AUTO",
"AUTO",
RED,
SMALL,
WHITE,
},
{//3
1,
36,
45,
45,
24,
24,
0x97,
"STOP",
"STOP",
RED,
SMALL,
WHITE,
},
{//4
1,
200,
74,
74,
24,
24,
0x97,
"时间设定",
"时间设定",
RED,
SMALL,
WHITE,
},
{
1,
106,
74,
74,
24,
24,
0x97,
"颜色测试",
"颜色测试",
RED,
SMALL,
WHITE,
},
{//4
90,
200,
74,
74,
24,
24,
0x97,
"背光测试",
"背光测试",
RED,
SMALL,
WHITE,
},
};
#define TimeSet_size 8
struct Command const TimeSet[] = {
{
100,//显示起点X坐标
50,//显示起点Y坐标
42,//显示宽度
42,
26,//显示长度
26,
WHITE,//显示着色
" ",//显示内容
"",
BLACK,//字体颜色
SMALL,//字体大小
WHITE,//光标颜色
},
{
164,//显示起点X坐标
50,//显示起点Y坐标
42,//显示宽度
42,
26,//显示长度
26,
WHITE,//显示着色
" ",//显示内容
"",
BLACK,//字体颜色
SMALL,//字体大小
WHITE,//光标颜色
},
{
228,//显示起点X坐标
50,//显示起点Y坐标
40,//显示宽度
40,
26,//显示长度
26,
WHITE,//显示着色
" ",//显示内容
"",
BLACK,//字体颜色
SMALL,//字体大小
WHITE,//光标颜色
},
{
100,//显示起点X坐标
100,//显示起点Y坐标
42,//显示宽度
42,
26,//显示长度
26,
WHITE,//显示着色
" ",//显示内容
"",
BLACK,//字体颜色
SMALL,//字体大小
WHITE,//光标颜色
},
{
164,//显示起点X坐标
100,//显示起点Y坐标
42,//显示宽度
42,
26,//显示长度
26,
WHITE,//显示着色
" ",//显示内容
"",
BLACK,//字体颜色
SMALL,//字体大小
WHITE,//光标颜色
},
{
228,//显示起点X坐标
100,//显示起点Y坐标
42,//显示宽度
42,
26,//显示长度
26,
WHITE,//显示着色
" ",//显示内容
"",
BLACK,//字体颜色
SMALL,//字体大小
WHITE,//光标颜色
},
{
150,//显示起点X坐标
200,//显示起点Y坐标
42,//显示宽度
30,
26,//显示长度
26,
GREEN,//显示着色
"确认",//显示内容
"OK",
BLACK,//字体颜色
SMALL,//字体大小
WHITE,//光标颜色
},
{
1,//显示起点X坐标
200,//显示起点Y坐标
70,//显示宽度
70,
39,//显示长度
39,
BLUE,//显示着色
"BACK",//显示内容
"BACK",
RED,//字体颜色
BIG,//字体大小
BLUE,//光标颜色
},
};
void Init_interrupt(void)
{
CLI();
//MCUCR = 0x00;
EICRB = 0x02;
SEI();
}
void Screen_Color(unsigned char color)
{
unsigned char i = color;
for(i=color;i<=255;i++)
{
Dis_Rect(100,0,219,170,i);
Dis_Int(160,190,i,0,BLACK,WHITE);
Delayx10ms(40);
//if(i==255)i=0;
if(GetCursor(Start[3]))
{
Color_Count = i+1;
break;
}
}
}
void Start_Time(void)
{
Clear_Display(0x97);
Display(100,55," 年 月 日",SMALL,BLACK,0x97);
Display(100,105," 时 分 秒",SMALL,BLACK,0x97);
Dis_Menu(TimeSet,TimeSet_size);
}
void DisSetTime(unsigned char *ptr,unsigned char temp,unsigned char front,unsigned char back)
{
if(temp >0)
{
ReadTime();
//year
ptr[0] = (time.year_H>>4) +0x30;
ptr[1] = (time.year_H&0x0f)+0x30;
ptr[2] = (time.year_L>>4) +0x30;
ptr[3] = (time.year_L&0x0f)+0x30;
ptr[4] = (time.month>>4) + 0x30;
ptr[5] = (time.month & 0x0f) + 0x30;
ptr[6] = (time.day>>4) + 0x30;
ptr[7] = (time.day & 0x0f) + 0x30;
ptr[8] = (time.hour>>4) + 0x30;
ptr[9] = (time.hour & 0x0f) + 0x30;
ptr[10] = (time.minute>>4) + 0x30;
ptr[11] = (time.minute & 0x0f) + 0x30;
ptr[12] = (time.second>>4) + 0x30;
ptr[13] = (time.second & 0x0f) + 0x30;
}
Dis_Ascii(TimeSet[0].x+5,TimeSet[0].y+5,ptr[0],front,back);
Dis_Ascii(TimeSet[0].x+13,TimeSet[0].y+5,ptr[1],front,back);
Dis_Ascii(TimeSet[0].x+21,TimeSet[0].y+5,ptr[2],front,back);
Dis_Ascii(TimeSet[0].x+29,TimeSet[0].y+5,ptr[3],front,back);
//month
Dis_Ascii(TimeSet[1].x+17,TimeSet[1].y+5,ptr[4],front,back);
Dis_Ascii(TimeSet[1].x+25,TimeSet[1].y+5,ptr[5],front,back);
//day
Dis_Ascii(TimeSet[2].x+17,TimeSet[2].y+5,ptr[6],front,back);
Dis_Ascii(TimeSet[2].x+25,TimeSet[2].y+5,ptr[7],front,back);
//hour
Dis_Ascii(TimeSet[3].x+17,TimeSet[3].y+5,ptr[8],front,back);
Dis_Ascii(TimeSet[3].x+25,TimeSet[3].y+5,ptr[9],front,back);
//minute
Dis_Ascii(TimeSet[4].x+17,TimeSet[4].y+5,ptr[10],front,back);
Dis_Ascii(TimeSet[4].x+25,TimeSet[4].y+5,ptr[11],front,back);
//second
Dis_Ascii(TimeSet[5].x+17,TimeSet[5].y+5,ptr[12],front,back);
Dis_Ascii(TimeSet[5].x+25,TimeSet[5].y+5,ptr[13],front,back);
//return (ptr);
}
void Main_Display(void)
{
Clear_Display(WHITE);
Dis_Menu(Start,Start_size);
Display(1,130,"X=",BIG,BLACK,WHITE);
Display(1,160,"Y=",BIG,BLACK,WHITE);
//Dis_Batter(300,210,0,1,BLUE,WHITE);
//Dis_Image(Start[0].x,Start[0].y+8,gImage_menu,1,Start[0].color);
}
void ChangeLight(unsigned int val)
{
CMD = LCD_MODE_3;
DAT = val;
CMD = LCD_MODE_0;
}
void PowerOff(void)
{
CMD = LCD_POWER_OFF;
}
void PowerOn(void)
{
CMD = LCD_POWER_ON;
}
void main(void)
{
unsigned int i;
unsigned int list_time;
unsigned char BackLight=0;
unsigned int Back_Val=0;
DDRF |= 0x08;
PORTF |= 0x08;
Init_interrupt();
Main_Display();
ReadTime();//time是结构体,给time赋值
Init_Touch();
while(1)
{
//触摸屏处理程序
if(cursor.flag == 1)
{
Dis_Int(25,135,cursor.x,0,RED,WHITE);
Dis_Int(25,165,cursor.y,0,RED,WHITE);
if(GetCursor(Start[1]))//显示时间
{
if(Time_flag == 0)
{
Dis_Rect(100,165,160,50,BLUE);
Time_flag = 1;
DisTimeAll(100,165,BLACK,BLUE);
}
else if(Time_flag == 1)
{
Time_flag = 0;
Dis_Rect(100,165,160,50,WHITE);
}
}
else if(GetCursor(Start[2]))
{
Screen_Color(0);
}
else if(GetCursor(Start[0]))
{
Screen_Color(Color_Count);
}
else if(GetCursor(Start[4]))
{
Start_Time();
cursor.x = 0;
cursor.y = 0;
for(i=0;i<14;i++)
{
time_temp[i] = ' ';
}
//time_temp[14] = 0;
while(1)
{
if(cursor.flag)
{
if(GetCursor(TimeSet[0]))//年设定
{
Input_Data();
time_temp[0] = input_buffer[5];
time_temp[1] = input_buffer[6];
time_temp[2] = input_buffer[7];
time_temp[3] = input_buffer[8];
input_buffer[5] = ' ';
input_buffer[6] = ' ';
input_buffer[7] = ' ';
input_buffer[8] = ' ';
input_buffer[9] = 0;
Start_Time();
DisSetTime(time_temp,0,RED,WHITE);
}
else if(GetCursor(TimeSet[1]))//月设定
{
Input_Data();
time_temp[4] = input_buffer[7];
time_temp[5] = input_buffer[8];
input_buffer[7] = ' ';
input_buffer[8] = ' ';
input_buffer[9] = 0;
Start_Time();
DisSetTime(time_temp,0,RED,WHITE);
}
else if(GetCursor(TimeSet[2]))//日设定
{
Input_Data();
time_temp[6] = input_buffer[7];
time_temp[7] = input_buffer[8];
input_buffer[7] = ' ';
input_buffer[8] = ' ';
input_buffer[9] = 0;
Start_Time();
DisSetTime(time_temp,0,RED,WHITE);
}
else if(GetCursor(TimeSet[3]))//时设定
{
Input_Data();
time_temp[8] = input_buffer[7];
time_temp[9] = input_buffer[8];
input_buffer[7] = ' ';
input_buffer[8] = ' ';
input_buffer[9] = 0;
Start_Time();
DisSetTime(time_temp,0,RED,WHITE);
}
else if(GetCursor(TimeSet[4]))//分设定
{
Input_Data();
time_temp[10] = input_buffer[7];
time_temp[11] = input_buffer[8];
input_buffer[7] = ' ';
input_buffer[8] = ' ';
input_buffer[9] = 0;
Start_Time();
DisSetTime(time_temp,0,RED,WHITE);
}
else if(GetCursor(TimeSet[5]))//秒设定
{
Input_Data();
time_temp[12] = input_buffer[7];
time_temp[13] = input_buffer[8];
input_buffer[7] = ' ';
input_buffer[8] = ' ';
input_buffer[9] = 0;
Start_Time();
DisSetTime(time_temp,0,RED,WHITE);
}
else if(GetCursor(TimeSet[6]))//确认保存
{
for(i = 0;i<14;i++)
{
if(time_temp[i] == ' ')
{
time_temp[i] = '0';
}
}
REG_B=0xb2;
SECOND = (time_temp[12]-0x30)*16 + (time_temp[13] -0x30); //second
MINUTE = (time_temp[10]-0x30)*16 + (time_temp[11] -0x30); //minutes
HOUR = (time_temp[8]-0x30)*16 + (time_temp[9] -0x30); //hour
DAY = (time_temp[6]-0x30)*16 + (time_temp[7] -0x30); //day
MONTH = (time_temp[4]-0x30)*16 + (time_temp[5] -0x30); //month
YEAR = (time_temp[2]-0x30)*16 + (time_temp[3] -0x30); //year
REG_E = (time_temp[0]-0x30)*16 + (time_temp[1] -0x30);//year high byte
REG_A = 0x20;
REG_B = 0x12;
Display(150,150,"时间已保存!",SMALL,RED,0x97);
Delayx10ms(50);
Display(150,150," ",SMALL,RED,0x97);
}
else if(GetCursor(TimeSet[7]))
{
cursor.x = 0;
cursor.y = 0;
Main_Display();
break;
}
}
}
}
else if(GetCursor(Start[5]))//颜色测试
{
cursor.x = 0;
cursor.y = 0;
cursor.flag = 0;
count = 0;
Clear_Display(Color_Set[count]);
while(1)
{
if(cursor.flag)
{
if(GetCursor(Color[0]))//返回
{
cursor.x = 0;
cursor.y = 0;
Main_Display();
break;
}
else if(GetCursor(Color[1]))
{
count ++;
if(count > 7) count = 0;
Clear_Display(Color_Set[count]);
}
}
}
}
else if(GetCursor(Start[6]))
{
Dis_Menu(Backlight,Backlight_size);
Dis_Int(160,190,Back_Val,0,BLACK,WHITE);
ChangeLight(Back_Val);
while(1)
{
if(cursor.flag)
{
cursor.flag = 0;
if(BackLight == 1)
{
BackLight = 0;
PowerOn();
}
else if(GetCursor(Backlight[0]))//增加
{
Back_Val++;
if(Back_Val > 7) Back_Val = 7;
Dis_Int(160,190,Back_Val,0,BLACK,WHITE);
ChangeLight(Back_Val);
}
else if(GetCursor(Backlight[1]))//减少
{
Back_Val--;
if(Back_Val > 7) Back_Val = 0;
Dis_Int(160,190,Back_Val,0,BLACK,WHITE);
ChangeLight(Back_Val);
}
else if(GetCursor(Backlight[2]))//关闭
{
BackLight = 1;
PowerOff();
}
else if(GetCursor(Backlight[3]))//返回
{
break;
}
}
}
}
cursor.flag = 0;
}
if(Time_flag == 1)
{
DisTimeAll(100,165,BLACK,BLUE);
}
DisTime(220,220,RED,WHITE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -