能不能帮忙解析一下这个代码呀
#include "main.h"
u8 flag_FM;
u16 FLAS[6];
u16 light,temper;
u16 light_1,light_2,light_3,temp_h;
u8 flag_hw;
u8 flag_mode;
u8 LED_P;
unsigned char uart2_i;
unsigned char uart2_flag;
unsigned char uart2_dat;
unsigned char flag_REC2;
unsigned char buff2[3];
void write_flas() //写flash
{
FLAS[0]=6;
FLAS[1]=light_1;
FLAS[2]=light_2;
FLAS[3]=light_3;
FLAS[4]=temp_h;
STMFLASH_Write(FLASH_SAVE_ADDR,(u16*)FLAS,6);//flash写函数
}
void read_flas() //读flash
{
STMFLASH_Read(FLASH_SAVE_ADDR,(u16*)FLAS,6);//flash写函数
light_1=FLAS[1];
light_2=FLAS[2];
light_3=FLAS[3];
temp_h=FLAS[4];
}
void Init_flas()
{
read_flas(); //flash读函数
}
void Home_show(void)
{
u8 date1[]="Temp: 00.0 C P:0";
u8 date2[]="Ligh:00% 00 Auto";
u16 i;
if(flag_1_400ms==1 && flag_show==0)
{
date1[15]=LED_P+0x30;
i=read1_Temperture()*10;
light=ADC_ConvertedValue/40.96;
if(i<=1500)
temper = i; //读取温度值
if(temper>=1000)
{
date1[5]=temper/1000+0x30;
}else
{
date1[5]=' ';
}
date1[6]=temper/100%10+0x30;
date1[7]=temper/10%10+0x30;
date1[9]=temper%10+0x30;
date1[10]=0xdf;
date2[5]=light/10+0x30;
date2[6]=light%10+0x30;
if(flag_hw==1 && flag_mode==0 && LED_P!=0)
{
date2[9]=(15-miao)/10+0x30;
date2[10]=(15-miao)%10+0x30;
}else
{
date2[9]=' ';
date2[10]=' ';
}
if(flag_mode==0)
{
date2[12]='A';
date2[13]='u';
date2[14]='t';
date2[15]='o';
}else
{
date2[12]='M';
date2[13]='a';
date2[14]='n';
date2[15]='u';
}
LCD1602_ShowStr(0,0,date1);
LCD1602_ShowStr(0,1,date2);
flag_1_400ms=0;
}
}
void Set_show(void)
{
u8 date1[]=" 00 C ";
u8 date2[]=" 00 % ";
date1[8]=0xdf;
if(flag_1_400ms==1 && flag_show!=0)
{
if(flag_show==1)
{
LCD1602_ShowStr(0,0," Set_temp ");
date1[6]=temp_h/10+0x30;
date1[7]=temp_h%10+0x30;
LCD1602_ShowStr(0,1,date1);
}
if(flag_show==2)
{
LCD1602_ShowStr(0,0," Set_P1 ");
date2[6]=light_1/10+0x30;
date2[7]=light_1%10+0x30;
LCD1602_ShowStr(0,1,date2);
}
if(flag_show==3)
{
LCD1602_ShowStr(0,0," Set_P2 ");
date2[6]=light_2/10+0x30;
date2[7]=light_2%10+0x30;
LCD1602_ShowStr(0,1,date2);
}
if(flag_show==4)
{
LCD1602_ShowStr(0,0," Set_P3 ");
date2[6]=light_3/10+0x30;
date2[7]=light_3%10+0x30;
LCD1602_ShowStr(0,1,date2);
}
flag_1_400ms=0;
}
}
void Key(void)
{
if(KEY_Scan()==1)
{
flag_1_400ms=0;
if(flag_key==1)
{
flag_key=0;
flag_show++;
if(flag_show>4)
{
flag_show=0;
write_flas();
}
}
if(flag_key==4 && flag_show!=0)
{
flag_key=0;
flag_show=0;
write_flas();
}
if(flag_key==4 && flag_show==0)
{
flag_key=0;
flag_mode=~flag_mode;
}
if(flag_mode!=0)
{
if(flag_key==2)
{
flag_key=0;
FS=~FS;
}
if(flag_key==3)
{
flag_key=0;
LED_P++;
if(LED_P>3)
{
LED_P=0;
}
}
}
if(flag_show==1)
{
if(flag_key==2)
{
flag_key=0;
temp_h++;
if(temp_h>99)
temp_h=0;
}
if(flag_key==3)
{
flag_key=0;
temp_h--;
if(temp_h>99)
temp_h=99;
}
}
if(flag_show==2)
{
if(flag_key==2)
{
flag_key=0;
light_1++;
if(light_1>99)
light_1=0;
}
if(flag_key==3)
{
flag_key=0;
light_1--;
if(light_1>99)
light_1=99;
}
}
if(flag_show==3)
{
if(flag_key==2)
{
flag_key=0;
light_2++;
if(light_2>99)
light_2=0;
}
if(flag_key==3)
{
flag_key=0;
light_2--;
if(light_2>99)
light_2=99;
}
}
if(flag_show==4)
{
if(flag_key==2)
{
flag_key=0;
light_3++;
if(light_3>99)
light_3=0;
}
if(flag_key==3)
{
flag_key=0;
light_3--;
if(light_3>99)
light_3=99;
}
}
}
}
void Control(void)
{
if(flag_mode==0)
{
if(flag_hw==1)
{
if((temper/10)>temp_h)
{
FS=1;
}else
{
FS=0;
}
if(light<light_3)
{
TIM_SetCompare2(TIM3,0);
LED_P=3;
}else if(light<light_2)
{
TIM_SetCompare2(TIM3,50);
LED_P=2;
}else if(light<light_1)
{
TIM_SetCompare2(TIM3,80);
LED_P=1;
}else
{
TIM_SetCompare2(TIM3,100);
LED_P=0;
}
}else
{
TIM_SetCompare2(TIM3,100);
LED_P=0;
FS=0;
}
}else
{
if(LED_P==0)
{
TIM_SetCompare2(TIM3,100);
}else if(LED_P==1)
{
TIM_SetCompare2(TIM3,80);
}else if(LED_P==2)
{
TIM_SetCompare2(TIM3,50);
}else if(LED_P==3)
{
TIM_SetCompare2(TIM3,0);
}
}
if(HW==1)
{
LED=0;
flag_hw=1;
miao=0;
}else
{
LED=1;
}
}
void Siri(void)
{
if(flag_REC2==1)
{
flag_REC2=0;
if(buff2[1]=='B')
{
switch (buff2[2])
{
case '1': LED_P=2;flag_mode=0xff;break;
case '2': LED_P=0;flag_mode=0xff;break;
case '3':flag_mode=0xff; if(LED_P<3)LED_P++; break;
case '4':flag_mode=0xff; if(LED_P>0)LED_P--; break;
case '5': FS=1;flag_mode=0xff;break;
case '6': FS=0;flag_mode=0xff;break;
case '7': flag_mode=0;break;
}
write_flas();
flag_1s=1;
flag_1_400ms=1;
}
}
}
int main(void)
{
initGPIO_ds18b20();//初始化温度传感器
ADC1_Init();//ADC1初始化
Init_GPIO_LED();//LED初始化
KEY_Init();//按键初始化
LCD1602_Init();//液晶初始化
Init_flas();//FLAS初始化,数据保存
TIM2_Int_Init(499,7199);//每50ms中断一次
GPIO_Configuration_TIM3();//PWM初始化
TIM_SetCompare2(TIM3,100);//定时器3
NVIC_Configuration();//设置中断优先级
uart2_init(9600);//串口初始化,语音模块通过串口返回数据
while(1)
{
Home_show();//主界面显示
Set_show();//设置界面显示
Key(); //按键检测
Control();//控制函数
Siri();//语音控制
}
}
/*******************************************************************/
/* */
/* STM32在串口1接收1字节 */
/* 说明:串口1接收中断 */
/* */
/*******************************************************************/
void USART2_IRQHandler(void)
{
u8 dat2;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //若接收数据寄存器满
{
dat2 = USART_ReceiveData(USART2);
buff2[uart2_i]=dat2;
uart2_i++;
if(uart2_i>=3) // 停止接收
{
uart2_i=0;
uart2_flag=0;
flag_REC2=1;
}
if(dat2 == 0x63)
{
dat2 = 0;
Uart2_PutChar(0x77);
Uart2_PutChar(0x97);
}
}
}