#include "gd32e23x.h"
#include "systick.h"
#include <stdio.h>

#include <led.h>
#include <delay.h>
#include <usart.h>

#define u8 unsigned char
#define u16 unsigned int

uint32_t USART0_RECEIVE_Buf[100]; 
uint32_t USART1_RECEIVE_Buf[100]; 
char buf[256];


char row_max=2;
char col_max=3;
char row=1;
char col=1;
char cur=0;
char curpage=0;
char isbtn=0;
int shizhong=90;
int tx=0;


#define key_ok  gpio_input_bit_get(GPIOA,GPIO_PIN_0)		//ok键
#define key_up  gpio_input_bit_get(GPIOA,GPIO_PIN_1)		//方向上键
#define key_left  gpio_input_bit_get(GPIOA,GPIO_PIN_2)		//方向左键
#define key_down  gpio_input_bit_get(GPIOA,GPIO_PIN_3)		//方向下键
#define key_right  gpio_input_bit_get(GPIOA,GPIO_PIN_4)		//方向右键

#define KEY0_PRES 	1	//KEY0按下
#define KEY1_PRES		2	//KEY1按下
#define KEY2_PRES		3	//KEY2按下
#define KEY3_PRES		4	//KEY2按下
#define KEY4_PRES		5	//KEY2按下





int main(void)
{
		unsigned int i,k;
		int dly_page=400;
		int dly_key=50;
	
    systick_config(); 
		USART0_Init();
		//KEY_GPIOInit();
		Delay_ms(800);
	


	while(1){
				
					double i=0;
					
					for(i=0;i<=99;i+=0.1)
					
						{
						
							double k=i;
							double j=i;
							double l=i;
							
							if(i<=0.6)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(10,'%4.1F');SET_TXT(14,'%4.1F');SET_TXT(5,'优');SET_TXT(8,'优');SET_TXT(12,'空气清新');SET_TXT(12,'空气清新');\r\n",i,k,j,l);
						
							else if(i>0.6&&i<=1)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(10,'%4.1F');SET_TXT(14,'%4.1F');SET_TXT(5,'优');SET_TXT(8,'优');SET_TXT(12,'空气清新');SET_TXT(12,'空气清新');\r\n",i,k,j,l);
						
							else if(i>1&&i<=2)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(10,'%4.1F');SET_TXT(14,'%4.1F');SET_TXT(5,'优');SET_TXT(8,'优');SET_TXT(12,'空气清新');SET_TXT(12,'空气清新');\r\n",i,k,j,l);
						
							else if(i>2&&i<=4)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(10,'%4.1F');SET_TXT(14,'%4.1F');SET_TXT(5,'优');SET_TXT(8,'优');SET_TXT(12,'空气清新');SET_TXT(12,'空气清新');\r\n",i,k,j,l);
							
							else if(i<=15)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(5,'优');SET_TXT(8,'优');\r\n",i,k);
							
							else if(i>15&&i<=20)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(5,'良');SET_TXT(8,'良');\r\n",i,k);
							
							else if(i>20&&i<=30)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(5,'轻度污染');SET_TXT(8,'轻度污染');\r\n",i,k);
							
							else if(i>30&&i<=50)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(5,'中度污染');SET_TXT(8,'中度污染');\r\n",i,k);
							
							else if(i>50&&i<=60)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(5,'重度污染');SET_TXT(8,'重度污染');\r\n",i,k);
							
							else if(i>60&&i<=99)
								sprintf(buf,"SET_NUM(4,%0.1f,3);SET_TXT(7,'%4.1F');SET_TXT(5,'严重污染');SET_TXT(8,'严重污染');\r\n",i,k);
							
							UartSend(buf);
							CheckBusy();
							Delay_ms(5);
						}
				
				
				
				
				
				
				
				
				}

}
		
