Exemple #1
0
  int main(void)
 {
	 u8 t=0;	
	 u16 Time=0,dis_pre=0;
	 float V_ave;	//平均速度
	 char code_ave[5],code_v[5],code_vr[5], mileage[5];//信息储存数组
	 
	delay_init(72);	    	 			//延时函数初始化	  
	Stm32_Clock_Init(9);		  //系统时钟设置
	uart_init(72,9600);	 	 		  //串口初始化为9600
	usmart_dev.init(72);			//初始化USMART	
	EXTIX_Init();							//外部中断初始化
	TIM3_Int_Init(5000,7199); //10Khz的计数频率,计数到5000为500ms 
	LCD_Init();				 				//  PE.ALL,PD1~5  
	LCD_Display_Dir(1);				//设置显示方向为横屏显示
	LED_Init();		  					//初始化与LED连接的硬件接口
	KEY_Init();								//初始化按键

		while(RTC_Init())
		{	//等待RTC初始化
			delay_ms(200);
			printf("rtc waiting```\r\n");
		} 
		printf("finish\n");
		display_jing();
		//初始化完成
   while(1)
	{	
		POINT_COLOR=RED;
		if(t!=calendar.sec)		//时间更新后显示新时间
		{
				t=calendar.sec;	
				LCD_ShowNum(200,135,calendar.min,2,32);		
				LCD_ShowString(230,135,200,32,32,":");			
				LCD_ShowNum(248,135,calendar.sec,2,32);
			
				Time = 60*calendar.min+calendar.sec;//比赛用时
				if(dis_pre != quanshu_tenfold)			//有位移变化
				{
					V_ave=(0.154*quanshu_tenfold)/Time;
					dis_pre = quanshu_tenfold;
					sprintf(code_ave,"%.2f",V_ave);	
					LCD_ShowString(100,200,200,32,32,code_ave);//修改一下位置
					
				}
		}
			
		sprintf(code_v,"%.2f",V);					//float 转 字符串  
		LCD_ShowString(365,275,200,32,32,code_v);		//速度
		
		sprintf(code_vr,"%d",V_RPM);					//float 转 字符串  
		LCD_ShowString(365,275,200,32,32,code_vr);		//转速
 
		sprintf(mileage,"%.2f",0.154*quanshu_tenfold);
		LCD_ShowString(250,225,200,24,32,mileage);	//里程
		
	  display_dong(V_RPM,V,50);
		delay_ms(300);
	}
 }
Exemple #2
0
//等待多个内核对象的任务函数
void multi_task(void *p_arg)
{	
	u8 num;
	OS_ERR err;
	OS_OBJ_QTY index;
	OS_PEND_DATA pend_multi_tbl[CORE_OBJ_NUM];	
	
	pend_multi_tbl[0].PendObjPtr=(OS_PEND_OBJ*)&Test_Sem1;
	pend_multi_tbl[1].PendObjPtr=(OS_PEND_OBJ*)&Test_Sem2;
	pend_multi_tbl[2].PendObjPtr=(OS_PEND_OBJ*)&Test_Q;
	
	while(1)
	{
		index=OSPendMulti((OS_PEND_DATA*	)pend_multi_tbl,	
						  (OS_OBJ_QTY		)CORE_OBJ_NUM,	//内核数量
						  (OS_TICK		   	)0,		
						  (OS_OPT         	)OS_OPT_PEND_BLOCKING,
						  (OS_ERR*			)&err);
		LCD_ShowNum(147,111,index,1,16);  					//显示当前有几个内核对象准备好了
		num++;
		LCD_Fill(6,131,233,313,lcd_discolor[num%14]);		//刷屏
		LED1 = ~LED1;
		OSTimeDlyHMSM(0,0,1,0,OS_OPT_TIME_PERIODIC,&err);   //延时1s
	}
}
//显示鼠标的坐标值
//x,y:在LCD上显示的坐标位置
//pos:坐标值
void Mouse_Show_Pos(u16 x,u16 y,short pos)
{
	if(pos<0)
	{			  
		LCD_ShowChar(x,y,'-',16,0);		//显示负号
		pos=-pos;						//转为正数
	}else LCD_ShowChar(x,y,' ',16,0);	//去掉负号
	LCD_ShowNum(x+8,y,pos,5,16);		//显示值				  
}
Exemple #4
0
void TIM3_IRQHandler(void)   //TIM5中断
{
	if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检查指定的TIM中断发生与否:TIM 中断源
	{
		LCD_Color_Fill(150,10,175,20, White);
		LCD_ShowNum(150,10,adcValue ,Black);
		drawMap();
	}
	TIM_ClearITPendingBit(TIM3, TIM_IT_Update  );  //清除TIMx的中断待处理位:TIM 中断源
}
Exemple #5
0
 int main(void)
 {
	u16 adcx;
	float temp;
	SystemInit();
	delay_init(72);	     //延时初始化
	NVIC_Configuration();
 	uart_init(9600);
 	LED_Init();
 	KEY_Init();
	LCD_Init();
	Adc_Init();
	POINT_COLOR=RED;//设置字体为红色 
	LCD_ShowString(60,50,"Mini STM32");	
	LCD_ShowString(60,70,"ADC TEST");	
	LCD_ShowString(60,90,"ATOM@ALIENTEK");
	LCD_ShowString(60,110,"2010/12/30");	
	//显示提示信息
	POINT_COLOR=BLUE;//设置字体为蓝色
	LCD_ShowString(60,130,"ADC_CH0_VAL:");	      
	LCD_ShowString(60,150,"ADC_CH0_VOL:0.000V");	      
	while(1)
	{
		adcx=Get_Adc(ADC_Channel_0);
		LCD_ShowNum(156,130,adcx,4,16);//显示ADC的值
		temp=(float)adcx*(3.3/4096);
		adcx=temp;
		LCD_ShowNum(156,150,adcx,1,16);//显示电压值
		temp-=adcx;
		temp*=1000;
		LCD_ShowNum(172,150,temp,3,16);
		LED0=!LED0;
		delay_ms(250);
	}

 }
//显示当前字体更新进度
u32 fupd_prog(u32 fsize,u32 pos)
{
    float prog;
    u8 t=0XFF;
    prog=(float)pos/fsize;
    prog*=100;
    if(t!=prog)
    {
        LCD_ShowString(108,110,"%");
        t=prog;
        if(t>100)t=100;
        LCD_ShowNum(84,110,t,3,16);//显示数值
    }
    return 0;
}
/**
  * @brief: 提示校准结果(各个参数)
  */
void TP_Adj_Info_Show(u16 x0,u16 y0,u16 x1,u16 y1,u16 x2,u16 y2,u16 x3,u16 y3,u16 fac)
{	  
	POINT_COLOR=RED;
	LCD_ShowString(40,160,lcddev.width,lcddev.height,16,"x1:");
 	LCD_ShowString(40+80,160,lcddev.width,lcddev.height,16,"y1:");
 	LCD_ShowString(40,180,lcddev.width,lcddev.height,16,"x2:");
 	LCD_ShowString(40+80,180,lcddev.width,lcddev.height,16,"y2:");
	LCD_ShowString(40,200,lcddev.width,lcddev.height,16,"x3:");
 	LCD_ShowString(40+80,200,lcddev.width,lcddev.height,16,"y3:");
	LCD_ShowString(40,220,lcddev.width,lcddev.height,16,"x4:");
 	LCD_ShowString(40+80,220,lcddev.width,lcddev.height,16,"y4:");  
 	LCD_ShowString(40,240,lcddev.width,lcddev.height,16,"fac is:");     
	LCD_ShowNum(40+24,160,x0,4,16);			//显示数值
	LCD_ShowNum(40+24+80,160,y0,4,16);	//显示数值
	LCD_ShowNum(40+24,180,x1,4,16);			//显示数值
	LCD_ShowNum(40+24+80,180,y1,4,16);	//显示数值
	LCD_ShowNum(40+24,200,x2,4,16);			//显示数值
	LCD_ShowNum(40+24+80,200,y2,4,16);	//显示数值
	LCD_ShowNum(40+24,220,x3,4,16);			//显示数值
	LCD_ShowNum(40+24+80,220,y3,4,16);	//显示数值
 	LCD_ShowNum(40+56,lcddev.width,fac,3,16);	//显示数值,该数值必须在95~105范围之内.
}
 int main(void)
 { 
	u32 fontcnt;		  
	u8 i,j;
	u8 fontx[2];//gbk码
	u8 key,t;			 
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2 
	delay_init();	    	 //延时函数初始化	  
	uart_init(9600);	 	//串口初始化为9600			 
	LCD_Init();			//初始化液晶 
	LED_Init();         //LED初始化	 													    
	KEY_Init();				//按键初始化	  													    
	usmart_dev.init(72);	//usmart初始化	
 	mem_init();				//初始化内存池	    
 	exfuns_init();			//为fatfs相关变量申请内存  
  f_mount(fs[0],"0:",1); 	//挂载SD卡 
 	f_mount(fs[1],"1:",1); 	//挂载FLASH.
	while(font_init()) 	//检查字库
	{
UPD:    
		LCD_Clear(WHITE);		   	//清屏
 		POINT_COLOR=RED;			//设置字体为红色	   	   	  
		LCD_ShowString(60,50,200,16,16,"mini STM32");
		while(SD_Initialize())		//检测SD卡
		{
			LCD_ShowString(60,70,200,16,16,"SD Card Failed!");
			delay_ms(200);
			LCD_Fill(60,70,200+60,70+16,WHITE);
			delay_ms(200);		    
		}								 						    
		LCD_ShowString(60,70,200,16,16,"SD Card OK");
		LCD_ShowString(60,90,200,16,16,"Font Updating...");
	 	key=update_font(20,110,16);//更新字库
		while(key)//更新失败		
		{			 		  
			LCD_ShowString(60,110,200,16,16,"Font Update Failed!");
			delay_ms(200);
			LCD_Fill(20,110,200+20,110+16,WHITE);
			delay_ms(200);		       
		} 		  
		LCD_ShowString(60,110,200,16,16,"Font Update Success!");
		delay_ms(1500);	
		LCD_Clear(WHITE);//清屏	       
	}  
	POINT_COLOR=RED;       
	Show_Str(60,50,200,16,"Mini STM32开发板",16,0);				    	 
	Show_Str(60,70,200,16,"GBK字库测试程序",16,0);				    	 
	Show_Str(60,90,200,16,"正点原子@ALIENTEK",16,0);				    	 
	Show_Str(60,110,200,16,"2014年1月3日",16,0);
	Show_Str(60,130,200,16,"按KEY0,更新字库",16,0);
 	POINT_COLOR=BLUE;  
	Show_Str(60,150,200,16,"内码高字节:",16,0);				    	 
	Show_Str(60,170,200,16,"内码低字节:",16,0);				    	 
	Show_Str(60,190,200,16,"汉字计数器:",16,0);

	Show_Str(60,220,200,24,"对应汉字为:",24,0); 
	Show_Str(60,244,200,16,"对应汉字(16*16)为:",16,0);			 
	Show_Str(60,260,200,12,"对应汉字(12*12)为:",12,0);			 
	while(1)
	{
		fontcnt=0;
		for(i=0x81;i<0xff;i++)
		{		
			fontx[0]=i;
			LCD_ShowNum(148,150,i,3,16);		//显示内码高字节    
			for(j=0x40;j<0xfe;j++)
			{
				if(j==0x7f)continue;
				fontcnt++;
				LCD_ShowNum(148,170,j,3,16);	//显示内码低字节	 
				LCD_ShowNum(148,190,fontcnt,5,16);//汉字计数显示	 
			 	fontx[1]=j;
				Show_Font(60+132,220,fontx,24,0);	  
				Show_Font(60+144,244,fontx,16,0);	  		 		 
				Show_Font(60+108,260,fontx,12,0);	  		 		 
				t=200;
				while(t--)//延时,同时扫描按键
				{
					delay_ms(1);
					key=KEY_Scan(0);
					if(key==KEY0_PRES)goto UPD;
				}
				LED0=!LED0;
			}   
		}	
	} 
}
Exemple #9
0
void show_files(void)
{
	FRESULT f_res;			//FatFs通用结果码
	char c_path[50] = {"SD:"};
	char bmp_path[50];
	char temp[15];

	volatile uint32_t file_num = 0;
	volatile uint8_t update_file = 1, update_dir = 1;
	volatile uint8_t show_start = 1, show_end = ROW_PER_PAGE;
	volatile uint16_t image_height = 0 ,height_offset = 0;
	volatile uint8_t image_flag = 0;
	int8_t i;
	
	file_index.dir_depth = 1;
	file_index.page = 1;
	file_index.row = 1;
	file_index.file = 1;

	f_res = f_mount(&FatFs[0], "SD:", (BYTE)0);	//挂载SD卡
	f_res = f_res;

	while(file_index.dir_depth)
	{
		LCD_ShowIcon(2, file_index.row*8, 0, RED, BLACK);	//先清除之前的光标

		/* button LEFT */
		if(button_state[LEFT] == BUTTON_PRESS_UP)
		{
			button_state[LEFT] = BUTTON_NOT_PRESSED;

			file_index.page--;	//向左翻页显示,不能再翻时便是退回到上一级目录
			update_file = 1;
			file_index.row = 1;

			if(file_index.page < 1)	//左翻到头,则返回上一级目录
			{
				update_dir = 1;
				file_index.page = 1;
				file_index.dir_depth--;

				for(i=FILE_NAME_LEN-1;i>1;i--)	//清除 目录字符串中当前文件夹的名字,即得到上一级目录的路径
				{
					if((c_path[i]) == '/')
					{
						c_path[i] = 0;
						for(;i<FILE_NAME_LEN;i++)
							c_path[i] = 0;
						break;
					}
				}
				
				update_dir = 1;	//由于目录更改,需要更新目录的所有信息
				
				if(file_index.dir_depth == 0)	//若为根目录,则无需更新
				{
					update_file = 0;
					update_dir = 0;	//由于目录更改,需要更新目录的所有信息
				}
			}
		}

		/* button RIGHT */
		if(button_state[RIGHT] == BUTTON_PRESS_UP)
		{
			button_state[RIGHT] = BUTTON_NOT_PRESSED;

			if((file_num/ROW_PER_PAGE)<file_index.page)	//右翻到头,则留在当前页面上
			{
				;
			}
			else
			{
				update_file = 1;
				file_index.row = 1;
				file_index.page++;	//向右翻页显示
			}
		}

		/* button UP */
		if(button_state[UP] == BUTTON_PRESS_UP)
		{
			button_state[UP] = BUTTON_NOT_PRESSED;

			file_index.row--;	//光标上移
			if(file_index.row < 1 )	//翻过上界转到最后一行
			{
				file_index.row = file_num - ROW_PER_PAGE*(file_index.page-1);
				if(ROW_PER_PAGE < file_index.row)
					file_index.row = ROW_PER_PAGE;
			}
		}

		/* button DOWN */
		if(button_state[DOWN] == BUTTON_PRESS_UP)
		{
			button_state[DOWN] = BUTTON_NOT_PRESSED;

			file_index.row++;	//光标下移
			if( (file_num - ROW_PER_PAGE*(file_index.page-1)) < file_index.row 
					||  ROW_PER_PAGE < file_index.row)	//翻过下界返回到第一行
				file_index.row = 1;
		}

		/* button MIDDLE */
		if(button_state[MIDDLE] == BUTTON_PRESS_UP)	//选中或者确认
		{
			button_state[MIDDLE] = BUTTON_NOT_PRESSED;

			if(all_file_name[file_index.row][0] & AM_DIR)	//选中文件夹,则更新当前路径以及当前页面
			{
				file_index.dir_depth++;
				
				for(i=0;i<FILE_NAME_LEN-1;i++)
				{
					temp[i] = all_file_name[file_index.row + ROW_PER_PAGE*(file_index.page-1)][i+1];
				}
				sprintf(c_path, "%.*s%.*s%.*s", strlen(c_path),c_path,strlen("/"), "/", strlen(temp), temp);
				update_dir = 1;
				update_file = 1;
				file_index.row = 1;
			}
			else if(all_file_name[file_index.row][0] & AM_ARC)	//选中文图片,则显示图片
			{
				image_flag = 1;
				for(;;)
				{
					if(image_flag)
					{
						image_flag = 0;
						if(all_file_name[file_index.row][0] & AM_ARC)
						{
							for(i=0;i<50;i++)
							{
								bmp_path[i] = 0;
							}
							for(i=0;i<FILE_NAME_LEN-1;i++)
							{
								temp[i] = all_file_name[file_index.row + ROW_PER_PAGE*(file_index.page-1)][i+1];
							}
							sprintf(bmp_path, "%.*s%.*s%.*s", strlen(c_path),c_path,strlen("/"), "/", strlen(temp), temp);

							if(height_offset > 10000)
								height_offset = 0;

							if(height_offset > image_height - 128)
								height_offset = image_height - 129;
								
							if(image_height < 128)
								height_offset = 0;
							
							image_height = show_bmp_center(bmp_path);
						}
					}
					
					/* button UP */
					if(button_state[LEFT] == BUTTON_PRESS_UP)
					{
						button_state[LEFT] = BUTTON_NOT_PRESSED;

						file_index.row--;	//向左翻图片
						image_flag = 1;
						height_offset = 0;
						if(file_index.row < 1 )	//翻过上界转到最后一行
						{
							file_index.row = file_num - ROW_PER_PAGE*(file_index.page-1);
							if(ROW_PER_PAGE < file_index.row)
								file_index.row = ROW_PER_PAGE;
						}
					}

					/* button DOWN */
					if(button_state[RIGHT] == BUTTON_PRESS_UP)
					{
						button_state[RIGHT] = BUTTON_NOT_PRESSED;

						file_index.row++;	//向右翻图片
						image_flag = 1;
						height_offset = 0;
						if( (file_num - ROW_PER_PAGE*(file_index.page-1)) < file_index.row 
								||  ROW_PER_PAGE < file_index.row)	//翻过下界返回到第一行
							file_index.row = 1;
					}
					
					if(button_state[UP] == BUTTON_PRESS_UP)
					{
						button_state[UP] = BUTTON_NOT_PRESSED;

						height_offset+=30;
						image_flag = 1;
					}
					if(button_state[DOWN] == BUTTON_PRESS_UP)
					{
						button_state[DOWN] = BUTTON_NOT_PRESSED;

						height_offset-=30;
						image_flag = 1;
					}
					
					if(button_state[START] == BUTTON_PRESS_UP)	//选中或者确认
					{
						button_state[START] = BUTTON_NOT_PRESSED;

						led_blink(5,100);
						paint_bmp(bmp_path);
					}
					
					if(button_state[MIDDLE] == BUTTON_PRESS_UP)	//长按退出看图模式
					{
						button_state[MIDDLE] = BUTTON_NOT_PRESSED;

						update_dir = 1;
						update_file = 1;
						break;
					}

				}
			}
		}

		LCD_ShowIcon(2, file_index.row*8, 2, WHITE, BLACK);
		
		if(update_dir)
		{
			update_dir = 0;

			for(i=FILE_NAME_LEN-1;i>1;i--)
			{
				if( ((c_path[i]) == '/') && ((c_path[i+1]) == 0) )
				{
					c_path[i] = 0;
					break;
				}
			}
			scan_files(c_path, &file_num);

			LCD_DrawRectangle(0, 0, 127, 127, YELLOW);
			LCD_Fill(0, 0, 127, 8, YELLOW);
			LCD_ShowString(0, 0, &all_file_name[0][0], BLACK, YELLOW);
			LCD_ShowNum(100, 0, file_num, 2, BLACK, YELLOW);
		}
		
		if(update_file)
		{
			update_file = 0;
			show_start = ((file_index.page-1)*ROW_PER_PAGE)+1;
			show_end = show_end + ROW_PER_PAGE;
			if(show_end > file_num)
				show_end = file_num+1;
			show_menu(c_path, show_start, show_end);
		}
		delay_ms(20);
	}
}
Exemple #10
0
 int main(void)
 {
	u8 t=0;	
	SystemInit();
	delay_init(72);	     //延时初始化
	NVIC_Configuration();
 	uart_init(9600);
 	LED_Init();
 	KEY_Init();
	LCD_Init();
	RTC_Init();
	POINT_COLOR=RED;//设置字体为红色 
	LCD_ShowString(60,50,"Mini STM32");	
	LCD_ShowString(60,70,"RTC TEST");	
	LCD_ShowString(60,90,"ATOM@ALIENTEK");
	LCD_ShowString(60,110,"2010/12/30");	
	//显示时间
	POINT_COLOR=BLUE;//设置字体为蓝色
	LCD_ShowString(60,130,"    -  -  ");	   
	LCD_ShowString(60,162,"  :  :  ");		    
	while(1)
	{								    
		if(t!=timer.sec)
		{
			t=timer.sec;
			LCD_ShowNum(60,130,timer.w_year,4,16);									  
			LCD_ShowNum(100,130,timer.w_month,2,16);									  
			LCD_ShowNum(124,130,timer.w_date,2,16);	 
			switch(timer.week)
			{
				case 0:
					LCD_ShowString(60,148,"Sunday   ");
					break;
				case 1:
					LCD_ShowString(60,148,"Monday   ");
					break;
				case 2:
					LCD_ShowString(60,148,"Tuesday  ");
					break;
				case 3:
					LCD_ShowString(60,148,"Wednesday");
					break;
				case 4:
					LCD_ShowString(60,148,"Thursday ");
					break;
				case 5:
					LCD_ShowString(60,148,"Friday   ");
					break;
				case 6:
					LCD_ShowString(60,148,"Saturday ");
					break;  
			}
			LCD_ShowNum(60,162,timer.hour,2,16);									  
			LCD_ShowNum(84,162,timer.min,2,16);									  
			LCD_ShowNum(108,162,timer.sec,2,16);
			LED0=!LED0;
		}	
		delay_ms(10);								  
	};  

 }
Exemple #11
0
u8 Update_Font(void)
{
	u32 fcluster=0;	   
	u32 i;
	//u8 temp[512];  //零时空间	 在这里定义,会内存溢出
	u32 tempsys[2];  //临时记录文件起始位置和文件大小
	float prog;
	u8 t;		 
	FileInfoStruct FileTemp;//零时文件夹   				    	 
	//得到根目录的簇号
	if(FAT32_Enable)fcluster=FirstDirClust;
	else fcluster=0;			   
	FileTemp=F_Search(fcluster,(unsigned char *)folder[0],T_FILE);//查找system文件夹	  
	if(FileTemp.F_StartCluster==0)return 1;						  //系统文件夹丢失			  
	{	 										 
		//先查找字体
		FileTemp=F_Search(FileTemp.F_StartCluster,(unsigned char *)folder[1],T_FILE);//在system文件夹下查找FONT文件夹
		if(FileTemp.F_StartCluster==0)return 2;//字体文件夹丢失	

		fcluster=FileTemp.F_StartCluster;      //字体文件夹簇号	    
		FileTemp=F_Search(fcluster,(unsigned char *)sysfile[2],T_SYS);//在system文件夹下查找SYS文件
		if(FileTemp.F_StartCluster==0)return 3;//FONT12字体文件丢失	 
		LCD_ShowString(20,90,"Write UNI2GBK to FLASH...");		
		LCD_ShowString(108,110,"%");		
		F_Open(&FileTemp);//打开该文件
		i=0;	  
		while(F_Read(&FileTemp,temp))//成功读出512个字节
		{		 
			if(i<FileTemp.F_Size)//不超过文件大小
			{
				SPI_Flash_Write(temp,i+100000,512);//从100K字节处开始写入512个数据   
				i+=512;//增加512个字节
			}
			prog=(float)i/FileTemp.F_Size;
			prog*=100;
			if(t!=prog)
			{
				t=prog;
				if(t>100)t=100;
				LCD_ShowNum(84,110,t,3,16);//显示数值
			}					    
		}
		UNI2GBKADDR=100000;//UNI2GBKADDR从100K处开始写入.
		tempsys[0]=UNI2GBKADDR;
		tempsys[1]=FileTemp.F_Size;	 	  //UNI2GBKADDR 大小
		SPI_Flash_Write((u8*)tempsys,0,8);//记录在地址0~7处

		delay_ms(1000);			    
		//printf("UNI2GBK写入FLASH完毕!\n");
		//printf("写入数据长度:%d\n",FileTemp.F_Size);
		//printf("UNI2GBKSADDR:%d\n\n",UNI2GBKADDR);
		
		FONT16ADDR=FileTemp.F_Size+UNI2GBKADDR;//F16的首地址 
		FileTemp=F_Search(fcluster,(unsigned char *)sysfile[0],T_FON);//在system文件夹下查找FONT16字体文件
		if(FileTemp.F_StartCluster==0)return 4;//FONT16字体文件丢失	 
	
		LCD_ShowString(20,90,"Write FONT16 to FLASH... ");		
 		//printf("开始FONT16写入FLASH...\n");		
		F_Open(&FileTemp);//打开该文件
		i=0;	  
		while(F_Read(&FileTemp,temp))//成功读出512个字节
		{
			if(i<FileTemp.F_Size)//不超过文件大小
			{
				SPI_Flash_Write(temp,i+FONT16ADDR,512);//从0开始写入512个数据   
				i+=512;//增加512个字节
			}
			prog=(float)i/FileTemp.F_Size;
			prog*=100;
			if(t!=prog)
			{
				t=prog;
				if(t>100)t=100;
				LCD_ShowNum(84,110,t,3,16);//显示数值
			}
		}												   
		tempsys[0]=FONT16ADDR;
		tempsys[1]=FileTemp.F_Size;	 	  //FONT16ADDR 大小
		SPI_Flash_Write((u8*)tempsys,8,8);//记录在地址8~15处
		
		delay_ms(1000);	    
		//printf("FONT16写入FLASH完毕!\n");
		//printf("写入数据长度:%d\n",FileTemp.F_Size);


		FONT12ADDR=FileTemp.F_Size+FONT16ADDR;//F16的首地址
		//printf("FONT16SADDR:%d\n\n",FONT16ADDR);
		//LCD_ShowString(20,60,"Write FONT12 to FLASH... ");		
		//FONT12暂时不加入
		/*			  
		FileTemp=F_Search(fcluster,(unsigned char *)sysfile[1],T_FON);//在system文件夹下查找FONT12字体文件
		if(FileTemp.F_StartCluster==0)return 5;//FONT12字体文件丢失	 
		printf("开始FONT12写入FLASH...\n");		
		F_Open(&FileTemp);//打开该文件
		i=0;	  
		while(F_Read(&FileTemp,temp))//成功读出512个字节
		{
			if(i<FileTemp.F_Size)//不超过文件大小
			{
				SPI_Flash_Write(temp,i+FONT12ADDR,512);//从0开始写入512个数据   
				i+=512;//增加512个字节
			}
			prog=(float)i/FileTemp.F_Size;
			prog*=100;
			if(t!=prog)
			{
				t=prog;
				if(t>100)t=100;
				LCD_ShowNum(84,80,t,3,16);//显示数值
			}
		}	    
		tempsys[0]=FONT12ADDR;
		tempsys[1]=FileTemp.F_Size;	 	  //FONT16ADDR 大小
		SPI_Flash_Write((u8*)tempsys,16,8);//记录在地址16~23处

		printf("FONT12写入FLASH完毕!\n");
		printf("写入数据长度:%d\n",FileTemp.F_Size);   
		printf("FONT12SADDR:%d\n\n",FONT12ADDR); */
	}
	t=0XAA;
   	SPI_Flash_Write(&t,24,1);//写入字库存在标志	0XAA
	LCD_ShowString(20,90,"  Font Update Successed  ");		    
	delay_ms(1000);		
	delay_ms(1000);		
	return 0;//成功
}
Exemple #12
0
void KEY_Test(void)
{
	u8 i = 0;
	
	unsigned char key_flag = 0;
	unsigned char read_val = 0;
	LCD_Clear(BLACK);
	LCD_DrawRectangle(0,5, 479, 271);
	LCD_DrawRectangle(5,18, 474, 266);
	LCD_ShowString(150, 6, "--STC51 Platform--");  // 实验开发平台
	LCD_ShowString(150,60, "Step 1:Key and Led Testing");
	LCD_ShowString(150, 100,"Press K1,K2,K3,K4,Seee the LED"); 		 
	
	while(key_flag != 0x0F)
	{					
		
		LCD_ShowNum(150, 80,uart_flag, 0);
		
		if(strstr((const char*)gsm_ch, "OK"))
			LCD_ShowString(200, 150, "GSM_OK!"); 
		
		if(KEY4 == 0)				// K1   1110 0111
		{
			delayms(20);
			if(KEY4 == 0)
			{
				//Uart1_SendData('1');
				while(!KEY4);
				key_flag |= 0x01;
				PCF8574_Single_WriteI2C(UD_PCF8574_SlaveAddress, 0xE7);	
				
				Uart2_SendString("AT\r\n");					//GSM test
				
				//Uart1_SendString(mode_FLASH);	  		//MP3 test
				//Delay5ms();
				Uart1_SendString(play);	  		//MP3 test
			}
		}
	read_val = PCF8574_Single_ReadI2C(UD_PCF8574_SlaveAddress);	
/////////////////////////////////////////			
		if((read_val & 0x80) == 0)	//OUTC1				   K2  1110 0101
		{
			key_flag |= 0x08;	
			Uart1_SendData('2');			
			PCF8574_Single_WriteI2C(UD_PCF8574_SlaveAddress, 0xE5);	///led2 buzzer  1111 0011
		}
/////////////////////////////////////////
	
/////////////////////////////////////////
		if((read_val & 0x40) == 0)	//OUTC2				   K3  1110 0001 
		{
			Uart1_SendData('3');
			key_flag |= 0x04;		
			PCF8574_Single_WriteI2C(UD_PCF8574_SlaveAddress, 0xE1);	///led1  buzzer   1110 0111
		}
/////////////////////////////////////////		
		if((read_val & 0x20) == 0)	//OUTC5         K4  LED2 1111 0111
		{
			Uart1_SendData('4');	
			key_flag |= 0x02;			
			PCF8574_Single_WriteI2C(UD_PCF8574_SlaveAddress, 0xF7);	//led off!  1111 0101
			
		}
		
		if(strstr((const char*)gsm_ch, "OK"))
			LCD_ShowString(200, 150, "GSM_OK!"); 

	}           
		for(i; i < GSM_length; i++)
		gsm_ch[i] = 0;
		
	for(i=0;i<BufferCount;i++)
			BufferA[i]=0x00;
	
		BufferCount=0;
		uart_flag = 0;

}
Exemple #13
0
void Lcd_Init(void)
{

//调用一次这些函数,免得编译的时候提示警告
    LCD_CS =1;
    if(LCD_CS==0)
    {
        LCD_WR_REG_DATA(0,0);
        LCD_ShowString(0,0," ");
        LCD_ShowNum(0,0,0,0);
        LCD_Show2Num(0,0,0,0);
        LCD_DrawPoint_big(0,0);
        LCD_DrawRectangle(0,0,0,0);
        Draw_Circle(0,0,0);
    }
    LCD_REST=0;
    delayms(20);
    LCD_REST=1;
    delayms(20);
    LCD_CS =0;  //打开片选使能

    LCD_WR_REG(0xCB);
    LCD_WR_DATA8(0x39);
    LCD_WR_DATA8(0x2C);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x34);
    LCD_WR_DATA8(0x02);

    LCD_WR_REG(0xCF);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0XC1);
    LCD_WR_DATA8(0X30);

    LCD_WR_REG(0xE8);
    LCD_WR_DATA8(0x85);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x78);

    LCD_WR_REG(0xEA);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x00);

    LCD_WR_REG(0xED);
    LCD_WR_DATA8(0x64);
    LCD_WR_DATA8(0x03);
    LCD_WR_DATA8(0X12);
    LCD_WR_DATA8(0X81);

    LCD_WR_REG(0xF7);
    LCD_WR_DATA8(0x20);

    LCD_WR_REG(0xC0);    //Power control
    LCD_WR_DATA8(0x23);   //VRH[5:0]

    LCD_WR_REG(0xC1);    //Power control
    LCD_WR_DATA8(0x10);   //SAP[2:0];BT[3:0]

    LCD_WR_REG(0xC5);    //VCM control
    LCD_WR_DATA8(0x3e); //对比度调节
    LCD_WR_DATA8(0x28);

    LCD_WR_REG(0xC7);    //VCM control2
    LCD_WR_DATA8(0x86);  //--

    LCD_WR_REG(0x36);    // Memory Access Control
    LCD_WR_DATA8(0x48); //	   //48 68竖屏//28 E8 横屏

    LCD_WR_REG(0x3A);
    LCD_WR_DATA8(0x55);

    LCD_WR_REG(0xB1);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x18);

    LCD_WR_REG(0xB6);    // Display Function Control
    LCD_WR_DATA8(0x08);
    LCD_WR_DATA8(0x82);
    LCD_WR_DATA8(0x27);

    LCD_WR_REG(0xF2);    // 3Gamma Function Disable
    LCD_WR_DATA8(0x00);

    LCD_WR_REG(0x26);    //Gamma curve selected
    LCD_WR_DATA8(0x01);

    LCD_WR_REG(0xE0);    //Set Gamma
    LCD_WR_DATA8(0x0F);
    LCD_WR_DATA8(0x31);
    LCD_WR_DATA8(0x2B);
    LCD_WR_DATA8(0x0C);
    LCD_WR_DATA8(0x0E);
    LCD_WR_DATA8(0x08);
    LCD_WR_DATA8(0x4E);
    LCD_WR_DATA8(0xF1);
    LCD_WR_DATA8(0x37);
    LCD_WR_DATA8(0x07);
    LCD_WR_DATA8(0x10);
    LCD_WR_DATA8(0x03);
    LCD_WR_DATA8(0x0E);
    LCD_WR_DATA8(0x09);
    LCD_WR_DATA8(0x00);

    LCD_WR_REG(0XE1);    //Set Gamma
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x0E);
    LCD_WR_DATA8(0x14);
    LCD_WR_DATA8(0x03);
    LCD_WR_DATA8(0x11);
    LCD_WR_DATA8(0x07);
    LCD_WR_DATA8(0x31);
    LCD_WR_DATA8(0xC1);
    LCD_WR_DATA8(0x48);
    LCD_WR_DATA8(0x08);
    LCD_WR_DATA8(0x0F);
    LCD_WR_DATA8(0x0C);
    LCD_WR_DATA8(0x31);
    LCD_WR_DATA8(0x36);
    LCD_WR_DATA8(0x0F);

    LCD_WR_REG(0x2A);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0xEF);

    LCD_WR_REG(0x2B);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x01);
    LCD_WR_DATA8(0x3F);
    LCD_WR_REG(0x11);    //Exit Sleep
    delayms(120);

    LCD_WR_REG(0x29);    //Display on
    LCD_WR_REG(0x2c);

}
Exemple #14
0
void LCD_Init(void)
{
  P3OUT|=(BIT1+BIT2+BIT3+BIT6+BIT7);
  P4OUT=0xFF;
  P2OUT=0xFF;
  P1OUT|=BIT2;
  P3DIR|=(BIT1+BIT2+BIT3+BIT6+BIT7);
  P4DIR=0xFF;
  P2DIR=0xFF;
  P1DIR|=BIT2;
  P1OUT|=BIT2;
  
  SET_LCD_CS;
  if(GET_LCD_CS==0)
  {
      LCD_WR_REG_DATA(0,0);
      LCD_ShowString(0,0," ");
      LCD_ShowNum(0,0,0,0);
      LCD_Show2Num(0,0,0,0);
      LCD_DrawPoint_big(0,0);
      LCD_DrawRectangle(0,0,0,0);
      Draw_Circle(0,0,0);
  }

  SET_LCD_REST;
  delay_ms(5);	
  CLR_LCD_REST;
  delay_ms(5);
  SET_LCD_REST;
  SET_LCD_CS;
  SET_LCD_RD;
  SET_LCD_WR;
  delay_ms(5);
  CLR_LCD_CS ;  //打开片选使能

  LCD_WR_REG(0x00E2);	//PLL multiplier, set PLL clock to 120M
  LCD_WR_DATA(0x002d);	//N=0x36 for 6.5M, 0x23 for 10M crystal
  LCD_WR_DATA(0x0002);
  LCD_WR_DATA(0x0004);
  LCD_WR_REG(0x00E0);  // PLL enable
  LCD_WR_DATA(0x0001);
  delay_ms(1);
  LCD_WR_REG(0x00E0);
  LCD_WR_DATA(0x0003);
  delay_ms(5);
  LCD_WR_REG(0x0001);  // software reset
  delay_ms(5);
  LCD_WR_REG(0x00E6);	//PLL setting for PCLK, depends on resolution
  LCD_WR_DATA(0x0000);
  LCD_WR_DATA(0x00ff);
  LCD_WR_DATA(0x00be);

  LCD_WR_REG(0x00B0);	//LCD SPECIFICATION
  LCD_WR_DATA(0x0020);
  LCD_WR_DATA(0x0000);
  LCD_WR_DATA((HDP>>8)&0X00FF);  //Set HDP
  LCD_WR_DATA(HDP&0X00FF);
  LCD_WR_DATA((VDP>>8)&0X00FF);  //Set VDP
  LCD_WR_DATA(VDP&0X00FF);
  LCD_WR_DATA(0x0000);
  delay_ms(5);
  LCD_WR_REG(0x00B4);	//HSYNC
  LCD_WR_DATA((HT>>8)&0X00FF);  //Set HT
  LCD_WR_DATA(HT&0X00FF);
  LCD_WR_DATA((HPS>>8)&0X00FF);  //Set HPS
  LCD_WR_DATA(HPS&0X00FF);
  LCD_WR_DATA(HPW);			   //Set HPW
  LCD_WR_DATA((LPS>>8)&0X00FF);  //SetLPS
  LCD_WR_DATA(LPS&0X00FF);
  LCD_WR_DATA(0x0000);

  LCD_WR_REG(0x00B6);	//VSYNC
  LCD_WR_DATA((VT>>8)&0X00FF);   //Set VT
  LCD_WR_DATA(VT&0X00FF);
  LCD_WR_DATA((VPS>>8)&0X00FF);  //Set VPS
  LCD_WR_DATA(VPS&0X00FF);
  LCD_WR_DATA(VPW);			   //Set VPW
  LCD_WR_DATA((FPS>>8)&0X00FF);  //Set FPS
  LCD_WR_DATA(FPS&0X00FF);

  LCD_WR_REG(0x0036); //rotation
  LCD_WR_DATA(0x0000);
  LCD_WR_REG(0x00F0); //pixel data interface
  LCD_WR_DATA(0x0003);
  
  delay_ms(5);
  LCD_WR_REG(0x0029); //display on
  LCD_WR_REG(0x00BE); //set PWM for B/L
  LCD_WR_DATA(0x0006);
  LCD_WR_DATA(0x00f0);
  LCD_WR_DATA(0x0001);
  LCD_WR_DATA(0x00f0);
  LCD_WR_DATA(0x0000);
  LCD_WR_DATA(0x0000);

  LCD_WR_REG(0x00d0); 
  LCD_WR_DATA(0x000d);
  //----------LCD RESET---GPIO0-------------------//
  LCD_WR_REG(0x00B8);
  LCD_WR_DATA(0x0000);    //GPIO3=input, GPIO[2:0]=output
  LCD_WR_DATA(0x0001);    //GPIO0 normal
  LCD_WR_REG(0x00BA);
  LCD_WR_DATA(0x0000);  
}
Exemple #15
0
//触摸屏校准代码
//得到四个校准参数
void Touch_Adjust(void)
{								 
	signed short pos_temp[4][2];//坐标缓存值
	u8  cnt=0;	
	u16 d1,d2;
	u32 tem1,tem2;
	float fac; 	   
	cnt=0;				
	POINT_COLOR=BLUE;
	BACK_COLOR =WHITE;
	LCD_Clear(WHITE);//清屏   
	POINT_COLOR=RED;//红色 
	LCD_Clear(WHITE);//清屏 
	Drow_Touch_Point(20,20);//画点1 
	Pen_Point.Key_Sta=Key_Up;//消除触发信号 
	Pen_Point.xfac=0;//xfac用来标记是否校准过,所以校准之前必须清掉!以免错误	 
	while(1)
	{
		if(Pen_Point.Key_Sta==Key_Down)//按键按下了
		{
			if(Read_TP_Once())//得到单次按键值
			{  								   
				pos_temp[cnt][0]=Pen_Point.X;
				pos_temp[cnt][1]=Pen_Point.Y;
				cnt++;
			}			 
			switch(cnt)
			{			   
				case 1:
					LCD_Clear(WHITE);//清屏 
					Drow_Touch_Point(220,20);//画点2
					break;
				case 2:
					LCD_Clear(WHITE);//清屏 
					Drow_Touch_Point(20,300);//画点3
					break;
				case 3:
					LCD_Clear(WHITE);//清屏 
					Drow_Touch_Point(220,300);//画点4
					break;
				case 4:	 //全部四个点已经得到
	    		    //对边相等
					tem1=abs(pos_temp[0][0]-pos_temp[1][0]);//x1-x2
					tem2=abs(pos_temp[0][1]-pos_temp[1][1]);//y1-y2
					tem1*=tem1;
					tem2*=tem2;
					d1=sqrt(tem1+tem2);//得到1,2的距离
					
					tem1=abs(pos_temp[2][0]-pos_temp[3][0]);//x3-x4
					tem2=abs(pos_temp[2][1]-pos_temp[3][1]);//y3-y4
					tem1*=tem1;
					tem2*=tem2;
					d2=sqrt(tem1+tem2);//得到3,4的距离
					fac=(float)d1/d2;
					if(fac<0.95||fac>1.05||d1==0||d2==0)//不合格
					{
						cnt=0;
						LCD_Clear(WHITE);//清屏 
						Drow_Touch_Point(20,20);
						ADJ_INFO_SHOW("ver fac is:");   
						LCD_ShowNum(40+24,40,pos_temp[0][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,40,pos_temp[0][1],4,16);	//显示数值
						LCD_ShowNum(40+24,60,pos_temp[1][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,60,pos_temp[1][1],4,16);	//显示数值
						LCD_ShowNum(40+24,80,pos_temp[2][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,80,pos_temp[2][1],4,16);	//显示数值
						LCD_ShowNum(40+24,100,pos_temp[3][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,100,pos_temp[3][1],4,16);	//显示数值
						//扩大100倍显示
						LCD_ShowNum(40,140,fac*100,3,16);//显示数值,该数值必须在95~105范围之内.
						continue;
					}
					tem1=abs(pos_temp[0][0]-pos_temp[2][0]);//x1-x3
					tem2=abs(pos_temp[0][1]-pos_temp[2][1]);//y1-y3
					tem1*=tem1;
					tem2*=tem2;
					d1=sqrt(tem1+tem2);//得到1,3的距离
					
					tem1=abs(pos_temp[1][0]-pos_temp[3][0]);//x2-x4
					tem2=abs(pos_temp[1][1]-pos_temp[3][1]);//y2-y4
					tem1*=tem1;
					tem2*=tem2;
					d2=sqrt(tem1+tem2);//得到2,4的距离
					fac=(float)d1/d2;
					if(fac<0.95||fac>1.05)//不合格
					{
						cnt=0;
						LCD_Clear(WHITE);//清屏 
						Drow_Touch_Point(20,20);
						ADJ_INFO_SHOW("hor fac is:");   
						LCD_ShowNum(40+24,40,pos_temp[0][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,40,pos_temp[0][1],4,16);	//显示数值
						LCD_ShowNum(40+24,60,pos_temp[1][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,60,pos_temp[1][1],4,16);	//显示数值
						LCD_ShowNum(40+24,80,pos_temp[2][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,80,pos_temp[2][1],4,16);	//显示数值
						LCD_ShowNum(40+24,100,pos_temp[3][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,100,pos_temp[3][1],4,16);	//显示数值
						//扩大100倍显示
						LCD_ShowNum(40,140,fac*100,3,16);//显示数值,该数值必须在95~105范围之内.
 						continue;
					}//正确了
								   
					//对角线相等
					tem1=abs(pos_temp[1][0]-pos_temp[2][0]);//x1-x3
					tem2=abs(pos_temp[1][1]-pos_temp[2][1]);//y1-y3
					tem1*=tem1;
					tem2*=tem2;
					d1=sqrt(tem1+tem2);//得到1,4的距离
	
					tem1=abs(pos_temp[0][0]-pos_temp[3][0]);//x2-x4
					tem2=abs(pos_temp[0][1]-pos_temp[3][1]);//y2-y4
					tem1*=tem1;
					tem2*=tem2;
					d2=sqrt(tem1+tem2);//得到2,3的距离
					fac=(float)d1/d2;
					if(fac<0.95||fac>1.05)//不合格
					{
						cnt=0;
						LCD_Clear(WHITE);//清屏 
						Drow_Touch_Point(20,20);
						ADJ_INFO_SHOW("dia fac is:");   
						LCD_ShowNum(40+24,40,pos_temp[0][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,40,pos_temp[0][1],4,16);	//显示数值
						LCD_ShowNum(40+24,60,pos_temp[1][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,60,pos_temp[1][1],4,16);	//显示数值
						LCD_ShowNum(40+24,80,pos_temp[2][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,80,pos_temp[2][1],4,16);	//显示数值
						LCD_ShowNum(40+24,100,pos_temp[3][0],4,16);		//显示数值
						LCD_ShowNum(40+24+80,100,pos_temp[3][1],4,16);	//显示数值
						//扩大100倍显示
						LCD_ShowNum(40,140,fac*100,3,16);//显示数值,该数值必须在95~105范围之内.
						continue;
					}//正确了
					//计算结果
					Pen_Point.xfac=(float)200/(pos_temp[1][0]-pos_temp[0][0]);//得到xfac		 
					Pen_Point.xoff=(240-Pen_Point.xfac*(pos_temp[1][0]+pos_temp[0][0]))/2;//得到xoff
						  
					Pen_Point.yfac=(float)280/(pos_temp[2][1]-pos_temp[0][1]);//得到yfac
					Pen_Point.yoff=(320-Pen_Point.yfac*(pos_temp[2][1]+pos_temp[0][1]))/2;//得到yoff  

					if(abs(Pen_Point.xfac)>2||abs(Pen_Point.yfac)>2)//触屏和预设的相反了.
					{
						cnt=0;
						LCD_Clear(WHITE);//清屏 
						Drow_Touch_Point(20,20);
						LCD_ShowString(35,110,"TP Need readjust!");
						Pen_Point.touchtype=!Pen_Point.touchtype;//修改触屏类型.
						if(Pen_Point.touchtype)//X,Y方向与屏幕相反
						{
							CMD_RDX=0X90;
							CMD_RDY=0XD0;	 
						}else				   //X,Y方向与屏幕相同
						{
							CMD_RDX=0XD0;
							CMD_RDY=0X90;	 
						}
						delay_ms(500);
						continue;
					}
					POINT_COLOR=BLUE;
					LCD_Clear(WHITE);//清屏
					LCD_ShowString(35,110,"Touch Screen Adjust OK!");//校正完成
					delay_ms(500);
					LCD_Clear(WHITE);//清屏   
					return;//校正完成				 
			}
		}
	} 
}		    
Exemple #16
0
 int main(void)
 { 
	u8 t;
	u8 errcnt=0;		
	delay_init();	    	 //延时函数初始化	
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2
	uart_init(9600);	 	//串口初始化为9600
	LED_Init();		  		//初始化与LED连接的硬件接口
	LCD_Init();			   	//初始化LCD   
 	POINT_COLOR=RED;//设置字体为红色 
	LCD_ShowString(60,50,200,16,16,"Mini STM32");	
	LCD_ShowString(60,70,200,16,16,"Mouse TEST");	
	LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
	LCD_ShowString(60,110,200,16,16,"2014/3/12");		  
 	while(Init_Mouse())	//检查鼠标是否在位.	
	{
		LCD_ShowString(60,130,200,16,16,"Mouse Error");
		delay_ms(400);
		LCD_Fill(60,130,239,130+16,WHITE);	 
		delay_ms(100);
	}								   
	LCD_ShowString(60,130,200,16,16,"Mouse OK");
 	LCD_ShowString(60,150,200,16,16,"Mouse ID:");
 	LCD_ShowNum(132,150,MOUSE_ID,3,16);//填充模式

	POINT_COLOR=BLUE;
 	LCD_ShowString(30,170,200,16,16,"BUF[0]:");
	LCD_ShowString(30,186,200,16,16,"BUF[1]:");
	LCD_ShowString(30,202,200,16,16,"BUF[2]:"); 
	if(MOUSE_ID==3)LCD_ShowString(30,218,200,16,16,"BUF[3]:"); 

	LCD_ShowString(90+30,170,200,16,16,"X  POS:");
	LCD_ShowString(90+30,186,200,16,16,"Y  POS:");
	LCD_ShowString(90+30,202,200,16,16,"Z  POS:"); 
	if(MOUSE_ID==3)LCD_ShowString(90+30,218,200,16,16,"BUTTON:"); 
	t=0;
	while(1)
	{
		if(PS2_Status&0x80)//得到了一次数据
		{		  
			LCD_ShowNum(56+30,170,PS2_DATA_BUF[0],3,16);//填充模式
			LCD_ShowNum(56+30,186,PS2_DATA_BUF[1],3,16);//填充模式
			LCD_ShowNum(56+30,202,PS2_DATA_BUF[2],3,16);//填充模式
			if(MOUSE_ID==3)LCD_ShowNum(56+30,218,PS2_DATA_BUF[3],3,16);//填充模式

			Mouse_Data_Pro();//处理数据

			Mouse_Show_Pos(146+30,170,MouseX.x_pos);				//X坐标
			Mouse_Show_Pos(146+30,186,MouseX.y_pos);				//Y坐标
			if(MOUSE_ID==3)Mouse_Show_Pos(146+30,202,MouseX.z_pos);	//滚轮位置

		    if(MouseX.bt_mask&0x01)LCD_ShowString(146+30,218,200,16,16,"LEFT"); 
			else LCD_ShowString(146+30,218,200,16,16,"    "); 
		    if(MouseX.bt_mask&0x02)LCD_ShowString(146+30,234,200,16,16,"RIGHT"); 
			else LCD_ShowString(146+30,234,200,16,16,"     "); 				    
			if(MouseX.bt_mask&0x04)LCD_ShowString(146+30,250,200,16,16,"MIDDLE"); 
			else LCD_ShowString(146+30,250,200,16,16,"      ");   		 
			PS2_Status=MOUSE;
			PS2_En_Data_Report();//使能数据报告
		}else if(PS2_Status&0x40)
		{
			errcnt++;
			PS2_Status=MOUSE;
			LCD_ShowNum(86+30,234,errcnt,3,16);//填充模式
		}
		t++;
		delay_ms(1);
		if(t==200)
		{
			t=0;
			LED0=!LED0;
		}
	} 
}
Exemple #17
0
 int main(void)
 { 
	u16 i;
	u8 t=0; 
	float pro=0;			//进度 
	delay_init();	    	 //延时函数初始化	  
	uart_init(9600);	 	//串口初始化为9600
	LED_Init();		  		//初始化与LED连接的硬件接口
	LCD_Init();			   	//初始化LCD 
	KEY_Init();				//按键初始化		 	
 	MYDMA_Config(DMA1_Channel4,(u32)&USART1->DR,(u32)SendBuff,(TEXT_LENTH+2)*100);//DMA1通道4,外设为串口1,存储器为SendBuff,长(TEXT_LENTH+2)*100.
 	POINT_COLOR=RED;//设置字体为红色 
	LCD_ShowString(60,50,200,16,16,"Mini STM32");	
	LCD_ShowString(60,70,200,16,16,"DMA TEST");	
	LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
	LCD_ShowString(60,110,200,16,16,"2014/3/9");	
 	LCD_ShowString(60,130,200,16,16,"KEY0:Start");
	//显示提示信息	   
	for(i=0;i<(TEXT_LENTH+2)*100;i++)//填充ASCII字符集数据
    {
		if(t>=TEXT_LENTH)//加入换行符
		{ 
			SendBuff[i++]=0x0d; 
			SendBuff[i]=0x0a; 
			t=0;
		}else SendBuff[i]=TEXT_TO_SEND[t++];//复制TEXT_TO_SEND语句    
    }		 
	POINT_COLOR=BLUE;//设置字体为蓝色	  
	i=0;
	while(1)
	{
		t=KEY_Scan(0);
		if(t==KEY0_PRES)//KEY0按下
		{
			LCD_ShowString(60,150,200,16,16,"Start Transimit....");
			LCD_ShowString(60,170,200,16,16,"   %");//显示百分号
			printf("\r\nDMA DATA:\r\n "); 	    
		    USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE); //????1?DMA??        
			MYDMA_Enable(DMA1_Channel4);//开始一次DMA传输!	  
		    //等待DMA传输完成,此时我们来做另外一些事,点灯
		    //实际应用中,传输数据期间,可以执行另外的任务
		    while(1)
		    {
				if(DMA_GetFlagStatus(DMA1_FLAG_TC4)!=RESET)//等待通道4传输完成
				{
					DMA_ClearFlag(DMA1_FLAG_TC4);//清除通道4传输完成标志
					break; 
		        }
				pro=DMA_GetCurrDataCounter(DMA1_Channel4);//得到当前还剩余多少个数据
				pro=1-pro/((TEXT_LENTH+2)*100);//得到百分比	  
				pro*=100;      //扩大100倍
				LCD_ShowNum(60,170,pro,3,16);	  
		    }			    
			LCD_ShowNum(60,170,100,3,16);//显示100%	  
			LCD_ShowString(60,150,200,16,16,"Transimit Finished!");//提示传送完成
		}
		i++;
		delay_ms(10);
		if(i==20)
		{
			LED0=!LED0;//提示系统正在运行	
			i=0;
		}		   
	}
}