#include "stdarg.h"
#include "stdlib.h"
#include <stdint.h>
#include "unistd.h"
#include "TFT_API.h"

#define SCREEN_LENGTH 480	//Ļؿ
#define SCREEN_HIGHT 272	//Ļظ߶

#define WAVE_AREA_XL 0	//ʾΧ߽
#define WAVE_AREA_WIDTH (SCREEN_LENGTH - 50)	//ʾ
#define WAVE_AREA_XR (WAVE_AREA_XL + WAVE_AREA_WIDTH)	//ʾΧұ߽
#define WAVE_AREA_XM ((WAVE_AREA_XL + WAVE_AREA_XR)/2)	//ʾX

#define WAVE_AREA_YD 40		//ʾΧ±߽
#define WAVE_AREA_HIGHT (SCREEN_HIGHT - WAVE_AREA_YD - 16)	//ʾ߶
#define WAVE_AREA_YU (WAVE_AREA_YD + WAVE_AREA_HIGHT) 	//ʾΧϱ߽


#define WAVE_AREA_YM ((WAVE_AREA_YU+1 + WAVE_AREA_YD)/2)	//ʾY

#define Y_GIRD_NUM	8	//ֱդ
#define Y_GIRD_SIZE  ((WAVE_AREA_YU - WAVE_AREA_YD)/Y_GIRD_NUM)	//ÿդ߶ռ

#define X_GIRD_NUM	10	//ˮƽդ
#define X_GIRD_SIZE  ((WAVE_AREA_XR - WAVE_AREA_XL)/X_GIRD_NUM)	//ÿդռ

#define WAVE_SIZE 1024	//δ洢ռС

#define CH1_WAVE_COLOR YELLOW	//ͨ1ɫ
#define CH2_WAVE_COLOR GREEN		//ͨ2ɫ
#define WAVE_BACK_COLOR BLACK	//αɫ
#define GIRD_COLOR	GRAY		//դɫ
#define CURSOR_A_COLOR	WHITE	//Aɫ
#define CURSOR_B_COLOR	GREEN	//Bɫ


//LCDҪ
typedef struct
{
	char TIME_factor = 1; //X,ʱ
	unsigned char VOLT_factor = 1; //Y,ѹ
	short X_Offset_NOW = 0;	//ˮƽƫ
	short X_Offset_PRE = 0;//һˮƽƫ
	short Y_Offset_NOW = 0;	//δֱƫ
	short Y_Offset_PRE = 0;//һδֱƫ

	int8_t *pre_data = NULL;	//һ֡ݴڴָ
	int8_t *current_data;		//һ֡ݴڴָ

}wave_typef;


char CH1_TIME_factor = 1; //ͨ1X,ʱ
unsigned char CH1_VOLT_factor = 1; //ͨ1Y,ѹ

char CH2_TIME_factor = 1; //ͨ2X,ʱ
unsigned char CH2_VOLT_factor = 1; //ͨ2Y,ѹ

short CH1_Y_Offset = 0;	//ͨ1δֱƫ
short CH1_X_Offset = 0;	//ͨ1ˮƽƫ
short CH1_Y_Offset_PRE = 0;//ͨ1һδֱƫ
short CH1_X_Offset_PRE = 0;//ͨ1һˮƽƫ

short CH2_Y_Offset = 0;	//ͨ2δֱƫ
short CH2_X_Offset = 0;	//ͨ2ˮƽƫ
short CH2_Y_Offset_PRE = 0;//ͨ1һδֱƫ
short CH2_X_Offset_PRE = 0;//ͨ1һˮƽƫ

uint8_t sample_rate=100000000;	//β
int wave_point_num = 700;	//ÿʾʱҪʾĵʺʱ

//ͨ1
void draw_ch1_wave(uint8_t *p)
{
	int x_i=0;	//
	int d_i=0;

	int x1,y1,x2,y2;
	POINT_COLOR = CH1_WAVE_COLOR;
//	d_i = WAVE_SIZE/2 - WAVE_AREA_WIDTH/(2* CH1_TIME_factor)  + CH1_X_Offset;
	do{
		x1 = x_i + WAVE_AREA_XL;
		y1 = (p[d_i])*CH1_VOLT_factor + CH1_Y_Offset + WAVE_AREA_YM;
		x2 = x_i+CH1_TIME_factor + WAVE_AREA_XL;
		y2 = (p[d_i+1])*CH1_VOLT_factor + CH1_Y_Offset + WAVE_AREA_YM;
		LCD_DrawWaveLine(x1, y1,x2, y2);
		x_i = x_i + CH1_TIME_factor;
		d_i = d_i + 1;
	}while(((x_i+CH1_TIME_factor) <= WAVE_AREA_WIDTH) && (d_i < WAVE_SIZE - 1));

	BACK_COLOR = GRAY;
	POINT_COLOR = YELLOW;
//	LCD_ShowIco(WAVE_AREA_XL - 8, CH1_Y_Offset + WAVE_AREA_YM-8, 2, 0);
}

//ͨ2
void draw_ch2_wave(uint8_t *p)
{
	int x_i=0,d_i=0;
	int8_t a,b;
	int x1,y1,x2,y2;
	POINT_COLOR = CH2_WAVE_COLOR;
//	d_i = WAVE_SIZE/2 - WAVE_AREA_WIDTH/(2* CH2_TIME_factor)  + CH2_X_Offset;
	do{
		x1 = x_i + WAVE_AREA_XL;
		a = p[d_i];
		b = p[d_i+1];
		y1 = a*CH2_VOLT_factor + CH2_Y_Offset + WAVE_AREA_YM;
		x2 = x_i+CH2_TIME_factor + WAVE_AREA_XL;
		y2 = b*CH2_VOLT_factor + CH2_Y_Offset + WAVE_AREA_YM;
		LCD_DrawWaveLine(x1, y1,x2, y2);
		x_i = x_i + CH2_TIME_factor;
		d_i = d_i + 1;
	}while(((x_i+CH2_TIME_factor) <= WAVE_AREA_WIDTH) && (d_i < WAVE_SIZE - 1));

	BACK_COLOR = GRAY;
	POINT_COLOR = GREEN;
//	LCD_ShowIco(WAVE_AREA_XL - 8, CH2_Y_Offset + WAVE_AREA_YM-8, 2, 0);
}

//ͨ2һβ
void clear_ch2_wave(int8_t *p)
{
	int x_i=0,d_i=0;
	int x1,y1,x2,y2;
	POINT_COLOR = WAVE_BACK_COLOR;
//	d_i = WAVE_SIZE/2 - WAVE_AREA_WIDTH/(2* CH2_TIME_factor)  + CH2_X_Offset;
	do{
		x1 = x_i + WAVE_AREA_XL;
		y1 = (p[d_i])*CH2_VOLT_factor + CH2_Y_Offset_PRE + WAVE_AREA_YM;
		x2 = x_i+CH2_TIME_factor + WAVE_AREA_XL;
		y2 = (p[d_i+1])*CH2_VOLT_factor + CH2_Y_Offset_PRE + WAVE_AREA_YM;
		LCD_DrawWaveLine(x1, y1,x2, y2);
		x_i = x_i + CH2_TIME_factor;
		d_i = d_i + 1;
	}while(((x_i+CH2_TIME_factor) <= WAVE_AREA_WIDTH) && (d_i < WAVE_SIZE - 1));
	BACK_COLOR = BLUE;
	POINT_COLOR = BLUE;
//	LCD_ShowIco(WAVE_AREA_XL - 8, CH2_Y_Offset_PRE + WAVE_AREA_YM-8, 2, 0);
}

//ͨ1һβ
void clear_ch1_wave(int8_t *p)
{
	int x_i=0,d_i=0;
	int x1,y1,x2,y2;
	POINT_COLOR = WAVE_BACK_COLOR;
//	d_i = WAVE_SIZE/2 - WAVE_AREA_WIDTH/(2* CH1_TIME_factor)  + CH1_X_Offset;
	do{
		x1 = x_i + WAVE_AREA_XL;
		y1 = (p[d_i])*CH1_VOLT_factor + CH1_Y_Offset_PRE + WAVE_AREA_YM;
		x2 = x_i+CH1_TIME_factor + WAVE_AREA_XL;
		y2 = (p[d_i+1])*CH1_VOLT_factor + CH1_Y_Offset_PRE + WAVE_AREA_YM;
		LCD_DrawWaveLine(x1, y1,x2, y2);
		x_i = x_i + CH1_TIME_factor;
		d_i = d_i + 1;
	}while(((x_i+CH1_TIME_factor) <= WAVE_AREA_WIDTH) && (d_i < WAVE_SIZE - 1));
	BACK_COLOR = BLUE;
	POINT_COLOR = BLUE;
//	LCD_ShowIco(WAVE_AREA_XL - 8, CH1_Y_Offset_PRE + WAVE_AREA_YM-8, 2, 0);
}

uint16_t ch1_wave_point[8192][4];
uint16_t ch2_wave_point[8192][4];
void draw_wave2(int8_t *pp, int8_t *pn)
{
	int x_i=1,d_i=0;
	int x1,y1,x2,y2;
	uint16_t i;

	POINT_COLOR = WAVE_BACK_COLOR;
	do{
		x1 = x_i + WAVE_AREA_XL;
		x2 = x_i+CH2_TIME_factor + WAVE_AREA_XL;
		y1 = (pp[d_i])*CH2_VOLT_factor + CH2_Y_Offset_PRE + WAVE_AREA_YM;
		y2 = (pp[d_i+1])*CH2_VOLT_factor + CH2_Y_Offset_PRE + WAVE_AREA_YM;
		POINT_COLOR = WAVE_BACK_COLOR;
		ch2_wave_point[i][0] = x1;
		ch2_wave_point[i][0] = y1;
		ch2_wave_point[i][0] = x2;
		ch2_wave_point[i][0] = y1;

		LCD_DrawWaveLine(x1, y1,x2, y2);

		y1 = (pn[d_i])*CH2_VOLT_factor + CH2_Y_Offset + WAVE_AREA_YM;
		y2 = (pn[d_i+1])*CH2_VOLT_factor + CH2_Y_Offset + WAVE_AREA_YM;
		POINT_COLOR = CH2_WAVE_COLOR;
		LCD_DrawWaveLine(x1, y1,x2, y2);
		x_i = x_i + CH2_TIME_factor;
		d_i = d_i + 1;
	}while(((x_i+CH2_TIME_factor) <= WAVE_AREA_WIDTH) && (d_i < WAVE_SIZE - 1));
}


void draw_wave1(int8_t *pp, int8_t *pn)
{
	int x_i=1,d_i=0;
	int x1,y1,x2,y2;
	POINT_COLOR = WAVE_BACK_COLOR;
	do{
		x1 = x_i + WAVE_AREA_XL;
		x2 = x_i+CH1_TIME_factor + WAVE_AREA_XL;
		y1 = (pp[d_i])*CH1_VOLT_factor + CH1_Y_Offset_PRE + WAVE_AREA_YM;
		y2 = (pp[d_i+1])*CH1_VOLT_factor + CH1_Y_Offset_PRE + WAVE_AREA_YM;
		POINT_COLOR = WAVE_BACK_COLOR;
		LCD_DrawWaveLine(x1, y1,x2, y2);

		y1 = (pn[d_i])*CH1_VOLT_factor + CH1_Y_Offset + WAVE_AREA_YM;
		y2 = (pn[d_i+1])*CH1_VOLT_factor + CH1_Y_Offset + WAVE_AREA_YM;
		POINT_COLOR = CH1_WAVE_COLOR;
		LCD_DrawWaveLine(x1, y1,x2, y2);
		x_i = x_i + CH1_TIME_factor;
		d_i = d_i + 1;
	}while(((x_i+CH1_TIME_factor) <= WAVE_AREA_WIDTH) && (d_i < WAVE_SIZE - 1));
}

/*---------------------------------------------------------------------
 * Ʋ
 *
 * CH1_Buf ͨ1Ʋ
 * CH2_buf ͨ1Ʋ
 * CH_State ͨ״̬1ͨ1 2ͨ2 3ͬʱͨ1ͨ2
 -------------------------------------------------------------------*/
void draw_ch_wave(uint8_t *CH1_Buf, uint8_t *CH2_Buf, uint8_t CH_State)
{
	draw_ch1_wave(CH1_Buf);
	draw_ch2_wave(CH2_Buf);
}

/*---------------------------------------------------------------------
 * 
 *
 * CH1_Buf ͨ1Ʋ
 * CH2_buf ͨ1Ʋ
 * CH_State ͨ״̬1ͨ1 2ͨ2 3ͬʱͨ1ͨ2
 -------------------------------------------------------------------*/
void clear_ch_wave(int8_t *CH1_Buf, int8_t *CH2_Buf, uint8_t CH_State)
{
	clear_ch1_wave(CH1_Buf);
	clear_ch2_wave(CH2_Buf);
}

//Ʊ
void draw_back_gird()
{
	int i;
	POINT_COLOR = GIRD_COLOR;
	//
	for(i=WAVE_AREA_XL;i<=WAVE_AREA_XR;)
	{
		draw_y_line(i, WAVE_AREA_YD, WAVE_AREA_HIGHT, POINT_COLOR);
		i=i+X_GIRD_SIZE;
	}
	//
	draw_y_line(WAVE_AREA_XM+1, WAVE_AREA_YD, WAVE_AREA_HIGHT, POINT_COLOR);
	draw_y_line(WAVE_AREA_XM-1, WAVE_AREA_YD, WAVE_AREA_HIGHT, POINT_COLOR);
	//ƺ
	for(i=WAVE_AREA_YD;i <=WAVE_AREA_YU;)
	{
		draw_x_line(WAVE_AREA_XL, i, WAVE_AREA_WIDTH, POINT_COLOR);
		i=i+Y_GIRD_SIZE;
	}

	//
	draw_x_line(WAVE_AREA_XL, WAVE_AREA_YM-1, WAVE_AREA_WIDTH,POINT_COLOR);
	draw_x_line(WAVE_AREA_XL, WAVE_AREA_YM+1, WAVE_AREA_WIDTH,POINT_COLOR);
}


void draw_wave_area()
{
	LCD_Fill(WAVE_AREA_XL, WAVE_AREA_YD, WAVE_AREA_XR, WAVE_AREA_YU,WAVE_BACK_COLOR);//䲨ʾɫ
	draw_gui();
}

typedef struct{
	uint16_t pos_x;	//ʼλX
	uint16_t pos_y;	//ʼλY
	uint16_t hight;	//߶
	uint16_t width;	//
	uint32_t back_color;	//ɫ
	uint32_t text_color;	//ɫ
	char char_size;			//ַߴ
	char *str;		//ʾ
}buttontypedef;

typedef struct{
	uint16_t pos_x;	//ıʼλX
	uint16_t pos_y;	//ıʼλY
	uint16_t hight;	//ı߶
	uint16_t width;	//ı
	uint32_t back_color;	//ı򱳾ɫ
	uint32_t text_color;	//ıɫ
	char char_size;			//ַߴ
	char *str;		//ʾ
}textboxtypedef;


buttontypedef button0;	//
buttontypedef button1;	//
buttontypedef button2;	//
buttontypedef button3;	//
buttontypedef button4;	//
buttontypedef button5;	//

buttontypedef button6;	//
buttontypedef button7;	//



buttontypedef BUTTON_RUN;	//	ɫrunɫstop
buttontypedef BUTTON_VOLTAGE;	//ѹ֮󣬿޸դĵѹС
buttontypedef BUTTON_TIME;	//ʱ״̬ͨ޸Ĳʣ޸ÿդʱ
buttontypedef BUTTON_LEVEL;	//ֱƫƵεĴֱλ
buttontypedef BUTTON_OFFSET;	//ˮƽλѡ
buttontypedef BUTTON_TRIGGER;	//ѹ
buttontypedef BUTTON_CHANNEL;	//ͨѡ

buttontypedef BUTTON_INC;	//	Ӽ
buttontypedef BUTTON_DEC;	//  С


textboxtypedef textbox0;	//
textboxtypedef textbox1;	//
textboxtypedef textbox2;	//
textboxtypedef textbox3;	//
textboxtypedef textbox4;	//
textboxtypedef textbox5;	//
textboxtypedef textbox6;	//
textboxtypedef textbox7;	//
textboxtypedef textbox8;	//
textboxtypedef textbox9;	//


//ֱǰť
void draw_Rectangle_button(buttontypedef *button)
{
	POINT_COLOR = ~button->back_color;
	LCD_DrawRectangle(button->pos_x, button->pos_y, button->pos_x + button->width,button->pos_y + button->hight);
	LCD_Fill(button->pos_x + 1, button->pos_y + 1, button->pos_x + button->width - 1,button->pos_y + button->hight - 1,button->back_color);
	POINT_COLOR = button->text_color;
	BACK_COLOR = button->back_color;
	LCD_ShowString(button->pos_x + 5, button->pos_y + (button->hight - button->char_size)/2,12,  button->str);
}

//Բı
void draw_circle_textbox(textboxtypedef *textbox)
{
	int i;
	POINT_COLOR = textbox->back_color;
	for(i=textbox->hight/2 - 1;i>0;i--)
	{
		Draw_Circle(textbox->pos_x + textbox->hight/2, textbox->pos_y + textbox->hight/2,i);
	}
	for(i=textbox->hight/2 - 1;i>0;i--)
	{
		Draw_Circle(textbox->pos_x + textbox->width - textbox->hight/2, textbox->pos_y + textbox->hight/2,i);
	}
	LCD_Fill(textbox->pos_x + textbox->hight/2, textbox->pos_y, textbox->pos_x + textbox->width - textbox->hight/2, textbox->pos_y + textbox->hight,textbox->back_color);
	POINT_COLOR = textbox->text_color;
	BACK_COLOR = textbox->back_color;
	LCD_ShowString(textbox->pos_x + textbox->hight/2, textbox->pos_y + (textbox->hight - textbox->char_size)/2, 12, textbox->str);
}

//Բı
void draw_Rectangle_textbox(textboxtypedef *textbox)
{
	int i;
	POINT_COLOR = textbox->back_color;
	LCD_Fill(textbox->pos_x, textbox->pos_y, textbox->pos_x + textbox->width, textbox->pos_y + textbox->hight,textbox->back_color);
	POINT_COLOR = WHITE;
	LCD_DrawRectangle(textbox->pos_x, textbox->pos_y, textbox->pos_x + textbox->width, textbox->pos_y + textbox->hight);
	POINT_COLOR = textbox->text_color;
	BACK_COLOR = textbox->back_color;
	LCD_ShowString(textbox->pos_x + 4, textbox->pos_y + (textbox->hight - textbox->char_size)/2,12,  textbox->str);
}

textboxtypedef textbox[42];	//
buttontypedef BUTTON_RUN;

void creat_buttons(void)
{
	//RUN 
	BUTTON_RUN.pos_x = WAVE_AREA_XR + 2;
	BUTTON_RUN.pos_y = 230;
	BUTTON_RUN.hight = 25;
	BUTTON_RUN.width = SCREEN_LENGTH - WAVE_AREA_XR - 5;
	BUTTON_RUN.back_color = GRAY;
	BUTTON_RUN.text_color = RED;
	BUTTON_RUN.char_size = 16;
	BUTTON_RUN.str = "RUN";
	draw_Rectangle_button(&BUTTON_RUN);


	//Voltate 
	BUTTON_VOLTAGE.pos_x = WAVE_AREA_XR + 2;
	BUTTON_VOLTAGE.pos_y = 200;
	BUTTON_VOLTAGE.hight = 25;
	BUTTON_VOLTAGE.width = SCREEN_LENGTH - WAVE_AREA_XR - 5;
	BUTTON_VOLTAGE.back_color = GRAY;
	BUTTON_VOLTAGE.text_color = RED;
	BUTTON_VOLTAGE.char_size = 16;
	BUTTON_VOLTAGE.str = "  V";
	draw_Rectangle_button(&BUTTON_VOLTAGE);

	//Time 
	BUTTON_TIME.pos_x = WAVE_AREA_XR + 2;
	BUTTON_TIME.pos_y = 170;
	BUTTON_TIME.hight = 25;
	BUTTON_TIME.width = SCREEN_LENGTH - WAVE_AREA_XR - 5;
	BUTTON_TIME.back_color = GRAY;
	BUTTON_TIME.text_color = YELLOW;
	BUTTON_TIME.char_size = 16;
	BUTTON_TIME.str = "Time";
	draw_Rectangle_button(&BUTTON_TIME);
//
	//LEVEL 
	BUTTON_LEVEL.pos_x = WAVE_AREA_XR + 2;
	BUTTON_LEVEL.pos_y = 140;
	BUTTON_LEVEL.hight = 25;
	BUTTON_LEVEL.width = SCREEN_LENGTH - WAVE_AREA_XR - 5;
	BUTTON_LEVEL.back_color = GRAY;
	BUTTON_LEVEL.text_color = YELLOW;
	BUTTON_LEVEL.char_size = 16;
	BUTTON_LEVEL.str = "LEVEL";
	draw_Rectangle_button(&BUTTON_LEVEL);
//
	//OFFSET 
	BUTTON_OFFSET.pos_x = WAVE_AREA_XR + 2;
	BUTTON_OFFSET.pos_y = 110;
	BUTTON_OFFSET.hight = 25;
	BUTTON_OFFSET.width = SCREEN_LENGTH - WAVE_AREA_XR - 5;
	BUTTON_OFFSET.back_color = GRAY;
	BUTTON_OFFSET.text_color = YELLOW;
	BUTTON_OFFSET.char_size = 16;
	BUTTON_OFFSET.str = "OFFSET";
	draw_Rectangle_button(&BUTTON_OFFSET);
//
	//TRIGGER 
	BUTTON_TRIGGER.pos_x = WAVE_AREA_XR + 2;
	BUTTON_TRIGGER.pos_y = 80;
	BUTTON_TRIGGER.hight = 25;
	BUTTON_TRIGGER.width = SCREEN_LENGTH - WAVE_AREA_XR - 5;
	BUTTON_TRIGGER.back_color = GRAY;
	BUTTON_TRIGGER.text_color = YELLOW;
	BUTTON_TRIGGER.char_size = 16;
	BUTTON_TRIGGER.str = "TRIGER";
	draw_Rectangle_button(&BUTTON_TRIGGER);
//
	//Channel 
	BUTTON_CHANNEL.pos_x = WAVE_AREA_XR + 2;
	BUTTON_CHANNEL.pos_y = 50;
	BUTTON_CHANNEL.hight = 25;
	BUTTON_CHANNEL.width = SCREEN_LENGTH - WAVE_AREA_XR - 5;
	BUTTON_CHANNEL.back_color = GRAY;
	BUTTON_CHANNEL.text_color = YELLOW;
	BUTTON_CHANNEL.char_size = 16;
	BUTTON_CHANNEL.str = "CH0";
	draw_Rectangle_button(&BUTTON_CHANNEL);

	//INC 
	BUTTON_INC.pos_x = WAVE_AREA_XR + 2 - (SCREEN_LENGTH - WAVE_AREA_XR - 5) - 2;
	BUTTON_INC.pos_y = 0;
	BUTTON_INC.hight = 25;
	BUTTON_INC.width = SCREEN_LENGTH - WAVE_AREA_XR - 5;
	BUTTON_INC.back_color = GRAY;
	BUTTON_INC.text_color = YELLOW;
	BUTTON_INC.char_size = 16;
	BUTTON_INC.str = " INC";
	draw_Rectangle_button(&BUTTON_INC);

	//DEC 
	BUTTON_DEC.pos_x = WAVE_AREA_XR + 2;
	BUTTON_DEC.pos_y = 0;
	BUTTON_DEC.hight = 25;
	BUTTON_DEC.width = SCREEN_LENGTH - WAVE_AREA_XR - 5;
	BUTTON_DEC.back_color = GRAY;
	BUTTON_DEC.text_color = YELLOW;
	BUTTON_DEC.char_size = 16;
	BUTTON_DEC.str = " DEC";
	draw_Rectangle_button(&BUTTON_DEC);
}

void create_textbox(int num, uint16_t x,uint16_t y,uint16_t h,uint16_t w, uint32_t color, char *p)
{
	textbox[num].pos_x = x;
	textbox[num].pos_y = y;
	textbox[num].hight = h;
	textbox[num].width = w;
	textbox[num].back_color = BLACK;
	textbox[num].text_color = color;
	textbox[num].char_size = 12;
	textbox[num].str = p;
	draw_Rectangle_textbox(&textbox[num]);
}

void draw_gui()
{
	BACK_COLOR = BLACK;
	POINT_COLOR = GREEN;
	LCD_ShowString(0,256,16,"xiaomeige");
	LCD_ShowString(100,256,16,"STOP");
	LCD_ShowString(140,256,16,"AUTO");
//
	LCD_Fill(300, 256, 380, 271,BLACK);
	LCD_ShowString(300,256,16,"CH1");
	LCD_ShowString(338,256,16,"89.6mV");
//
	LCD_Fill(400, 256, 380, 271,BLACK);
	LCD_ShowString(420,256,16,"16:43");

	BACK_COLOR = RED;
	creat_buttons();

	//ͨ1ѹդ
	textbox0.pos_x = 0;
	textbox0.pos_y = 0;
	textbox0.hight = 16;
	textbox0.width = 80;
	textbox0.back_color = BLACK;
	textbox0.text_color = YELLOW;
	textbox0.char_size = 12;
	textbox0.str = "CH1:100mV";
	draw_Rectangle_textbox(&textbox0);

	//ͨ2ѹդ
	textbox1.pos_x = 0;
	textbox1.pos_y = 16;
	textbox1.hight = 16;
	textbox1.width = 80;
	textbox1.back_color = BLACK;
	textbox1.text_color = WHITE;
	textbox1.char_size = 12;
	textbox1.str = "CH2:100mV";
	draw_Rectangle_textbox(&textbox1);
//
	//V(1)
	textbox2.pos_x = 80;
	textbox2.pos_y = 0;
	textbox2.hight = 16;
	textbox2.width = 120;
	textbox2.back_color = BLACK;
	textbox2.text_color = YELLOW;
	textbox2.char_size = 12;
	textbox2.str = "V(1)=40.0mV";
	draw_Rectangle_textbox(&textbox2);
//
	//V(2)
	textbox3.pos_x = 80;
	textbox3.pos_y = 16;
	textbox3.hight = 16;
	textbox3.width = 120;
	textbox3.back_color = BLACK;
	textbox3.text_color = WHITE;
	textbox3.char_size = 12;
	textbox3.str = "V(2)=60.0mV";
	draw_Rectangle_textbox(&textbox3);
//
	//Freq(1)
	textbox4.pos_x = 200;
	textbox4.pos_y = 16;
	textbox4.hight = 16;
	textbox4.width = 100;
	textbox4.back_color = BLACK;
	textbox4.text_color = YELLOW;
	textbox4.char_size = 12;
	textbox4.str = "Freq(1)=32.768K";
	draw_Rectangle_textbox(&textbox4);

	//Freq(2)
	textbox5.pos_x = 200;
	textbox5.pos_y = 0;
	textbox5.hight = 16;
	textbox5.width = 100;
	textbox5.back_color = BLACK;
	textbox5.text_color = WHITE;
	textbox5.char_size = 12;
	textbox5.str = "Freq(1)=50.000M";
	draw_Rectangle_textbox(&textbox5);
//
	//ʱTime
	textbox6.pos_x = 300;
	textbox6.pos_y = 16;
	textbox6.hight = 16;
	textbox6.width = 80;
	textbox6.back_color = BLACK;
	textbox6.text_color = GREEN;
	textbox6.char_size = 12;
	textbox6.str = "Time:100ms";
	draw_Rectangle_textbox(&textbox6);

	//ʱƫT
	textbox7.pos_x = 300;
	textbox7.pos_y = 0;
	textbox7.hight = 16;
	textbox7.width = 80;
	textbox7.back_color = BLACK;
	textbox7.text_color = RED;
	textbox7.char_size = 12;
	textbox7.str = "T->:40ms";
	draw_Rectangle_textbox(&textbox7);



//	//Mѹ
//	textbox8.pos_x = 640;
//	textbox8.pos_y = 2;
//	textbox8.hight = 20;
//	textbox8.width = 100;
//	textbox8.back_color = BLACK;
//	textbox8.text_color = RED;
//	textbox8.char_size = 16;
//	textbox8.str = "M:100mV";
//	draw_Rectangle_textbox(&textbox8);
//	draw_timebar();
}



