//在指定位置显示指定颜色的按钮 //(x,y):按钮起始坐标 //xlen,ylen:x,y方向的长度 //str:按钮上要显示的字符 //color:字符颜色 void GUI_Draw_Button(u16 x,u16 y,u16 xlen,u16 ylen,u8 *str,u16 color) { u16 tback_color,tpoint_color; //////////////////画按钮部分////////////////////// LCD_Fill(x,y,x+xlen,y+ylen,LGRAY);//画实体 GUI_DrawLine(x,y,xlen,0,WHITE); //上外边框 GUI_DrawLine(x,y,0,ylen,WHITE); //左外边框 GUI_DrawLine(x+1,y+1,xlen-1,0,0XB5B6);//上内边框 GUI_DrawLine(x+1,y+1,0,ylen-1,0XB5B6);//左内边框 GUI_DrawLine(x,y+ylen,xlen,0,0X8431); //下外边框 GUI_DrawLine(x+xlen,y,0,ylen,0X8431); //右外边框 GUI_DrawLine(x+1,y+ylen-1,xlen-2,0,0XA535);//下内边框 GUI_DrawLine(x+xlen-1,y,0,ylen-1,0XA535); //右内边框 //////////////////显示按钮上面的信息/////////////// if(ylen<16)return;//不够画 tback_color=BACK_COLOR; tpoint_color=POINT_COLOR; BACK_COLOR=LGRAY; POINT_COLOR=color; Show_Str_Mid(x,y+(ylen-16)/2,str,16,xlen);//只对16字体 BACK_COLOR=tback_color; //恢复之前的颜色 POINT_COLOR=tpoint_color; }
/* ================================================================================= LCD_Init( ); Function : Initialize the OLED module INTPUT : none OUTPUT : None ================================================================================= */ void LCD_Init(void) { _PD3=0; INT16U x; OLED_RST_L() ;//LCD_RST=0; // _delay_ms(1); OLED_RST_H( );//LCD_RST=1; //从上电到下面开始初始化要有足够的时间,即等待RC复位完毕 LCD_WrCmd(0xae);//--turn off oled panel LCD_WrCmd(0x00);//---set low column address LCD_WrCmd(0x10);//---set high column address LCD_WrCmd(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F) LCD_WrCmd(0x81);//--set contrast control register LCD_WrCmd(0xcf); // Set SEG Output Current Brightness LCD_WrCmd(0xa1);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常 LCD_WrCmd(0xc8);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常 LCD_WrCmd(0xa6);//--set normal display LCD_WrCmd(0xa8);//--set multiplex ratio(1 to 64) LCD_WrCmd(0x3f);//--1/64 duty LCD_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F) LCD_WrCmd(0x00);//-not offset LCD_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency LCD_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec LCD_WrCmd(0xd9);//--set pre-charge period LCD_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock LCD_WrCmd(0xda);//--set com pins hardware configuration LCD_WrCmd(0x12); LCD_WrCmd(0xdb);//--set vcomh LCD_WrCmd(0x40);//Set VCOM Deselect Level LCD_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02) LCD_WrCmd(0x02);// LCD_WrCmd(0x8d);//--set Charge Pump enable/disable LCD_WrCmd(0x14);//--set(0x10) disable LCD_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5) LCD_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7) LCD_WrCmd(0xaf);//--turn on oled panel LCD_Fill(0x00); //初始清屏 }
portTASK_FUNCTION( vGUITask, pvParameters ) { portTickType xLastWakeTime; foutf(&debugOS, "xTask GUI started.\n"); xLastWakeTime = xTaskGetTickCount(); u8 timer_drawMap = 0; for(;;) { //foutf(&debugOS, "Watermark gui: %i\n", uxTaskGetStackHighWaterMark( NULL )); gui_handler(gui_element); if(STM_EVAL_PBGetState(BUTTON_USER)) { menu = MENU_CALIBRATION; } if(battery.percent != batt_percent_old) //Redraw statusbar if battery value changes { gui_drawAREAstatusbar(&gui_element[GUI_EL_AREA_STATUSBAR_TOP]); batt_percent_old = battery.percent; } switch (menu) { case MENU_INIT: LCD_Fill(LCD_COLOR_WHITE); gui_drawAREAstatusbar(&gui_element[GUI_EL_AREA_STATUSBAR_TOP]); gui_drawMBTN(&gui_element[GUI_EL_MBTN_MAP]); gui_drawMBTN(&gui_element[GUI_EL_MBTN_VIEW]); gui_drawMBTN(&gui_element[GUI_EL_MBTN_SETTINGS]); menu = MENU_INIT_IDLE; case MENU_INIT_IDLE: //Wait for events... if(gui_element[GUI_EL_MBTN_MAP].state == MBTN_ACTIVE) menu = MENU_MAP_INIT; else if(gui_element[GUI_EL_MBTN_VIEW].state == MBTN_ACTIVE) menu = MENU_VIEW_INIT; else if(gui_element[GUI_EL_MBTN_SETTINGS].state == MBTN_ACTIVE) menu = MENU_SETTINGS_INIT; break; case MENU_MAP_INIT: //Area Map //SW Startmapping //SW Show scan //BTN Clear map //BTN Set waypoint gui_element[GUI_EL_AREA_MAP].state = GUI_EL_INTOUCHABLE; gui_element[GUI_EL_SW_STARTMAPPING].state = mapping ? SW_ON : SW_OFF; gui_element[GUI_EL_SW_SHOWSCAN].state = show_scan ? SW_ON : SW_OFF; gui_element[GUI_EL_SW_PROCESSEDVIEW].state = processedView ? SW_ON : SW_OFF; gui_element[GUI_EL_AREA_MAP].state = MAP_ACTIVE; gui_element[GUI_EL_BTN_CLEARMAP].state = BTN_NOT_ACTIVE; if(setWaypoints) gui_element[GUI_EL_BTN_SETWP].state = BTN_ACTIVE; else gui_element[GUI_EL_BTN_SETWP].state = BTN_NOT_ACTIVE; gui_drawSW(&gui_element[GUI_EL_SW_STARTMAPPING]); gui_drawSW(&gui_element[GUI_EL_SW_SHOWSCAN]); gui_drawSW(&gui_element[GUI_EL_SW_PROCESSEDVIEW]); gui_drawBTN(&gui_element[GUI_EL_BTN_CLEARMAP]); gui_drawBTN(&gui_element[GUI_EL_BTN_SETWP]); timer_drawMap = 0; menu = MENU_MAP_IDLE; case MENU_MAP_IDLE: if(timer_drawMap == 0) { gui_drawAREAmap(&gui_element[GUI_EL_AREA_MAP]); timer_drawMap = MAP_REFRESHTIME; } timer_drawMap --; break; //Map idle (waiting for touch events) case MENU_VIEW_INIT: //Draw View menu = MENU_VIEW_IDLE; case MENU_VIEW_IDLE: break; //View idle (waiting for touch events) case MENU_SETTINGS_INIT: //Settings active switch (xv11_state(XV11_GETSTATE)) { //Lidar state? case XV11_OFF: gui_element[GUI_EL_SW_LIDAR].state = SW_OFF; break; case XV11_STARTING: gui_element[GUI_EL_SW_LIDAR].state = SW_BUSY; break; case XV11_ON: gui_element[GUI_EL_SW_LIDAR].state = SW_ON; break; default: break; } gui_drawSW(&gui_element[GUI_EL_SW_LIDAR]); gui_element[GUI_EL_SW_STRLIDAR].state = strlidar.active ? SW_ON : SW_OFF; //Streams on/off? gui_drawSW(&gui_element[GUI_EL_SW_STRLIDAR]); gui_element[GUI_EL_SW_STRDEBUG].state = debug.active ? SW_ON : SW_OFF; gui_drawSW(&gui_element[GUI_EL_SW_STRDEBUG]); gui_element[GUI_EL_SW_STRDEBUGOS].state = debugOS.active ? SW_ON : SW_OFF; gui_drawSW(&gui_element[GUI_EL_SW_STRDEBUGOS]); gui_element[GUI_EL_SW_STRERR].state = error.active ? SW_ON : SW_OFF; gui_drawSW(&gui_element[GUI_EL_SW_STRERR]); gui_element[GUI_EL_SW_STRSLAMUI].state = slamUI.active ? SW_ON : SW_OFF; gui_drawSW(&gui_element[GUI_EL_SW_STRSLAMUI]); gui_element[GUI_EL_BTN_CALTOUCH].state = BTN_NOT_ACTIVE; //Calibrate Touchscreen? gui_drawBTN(&gui_element[GUI_EL_BTN_CALTOUCH]); gui_element[GUI_EL_BTN_RESET].state = BTN_NOT_ACTIVE; //Reset system! gui_drawBTN(&gui_element[GUI_EL_BTN_RESET]); menu = MENU_SETTINGS_IDLE; case MENU_SETTINGS_IDLE: if(gui_element[GUI_EL_SW_LIDAR].state != GUI_EL_INVISIBLE) { if(xv11_state(XV11_GETSTATE) == XV11_STARTING) { if(gui_element[GUI_EL_SW_LIDAR].state != SW_BUSY) { gui_element[GUI_EL_SW_LIDAR].state = SW_BUSY; gui_drawSW(&gui_element[GUI_EL_SW_LIDAR]); } } else if(xv11_state(XV11_GETSTATE) == XV11_ON) { if(gui_element[GUI_EL_SW_LIDAR].state != SW_ON) { gui_element[GUI_EL_SW_LIDAR].state = SW_ON; gui_drawSW(&gui_element[GUI_EL_SW_LIDAR]); } } } break; //Settings idle (waiting for touch events) case MENU_CALIBRATION: //Calibration mode: if(UB_Touch_Calibrate() == 1) { menu = MENU_INIT; } break; default: menu = MENU_INIT; break; } vTaskDelayUntil( &xLastWakeTime, ( 50 / portTICK_RATE_MS ) ); } }
void piclib_draw_hline(u16 x0,u16 y0,u16 len,u16 color) { if((len==0)||(x0>lcddev.width)||(y0>lcddev.height))return; LCD_Fill(x0,y0,x0+len-1,y0,color); }
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); } }
//////////////////////////////与文件浏览相关的函数////////////////////////////// //功能选择调度函数 //list :功能条目指针 //title :标题 //func :选择/确定/。。。 //len :功能条目的个数(1~8) //sel :开始选中的条目(0~7) //返回值:0~7,选中的条目;8,没有选择任何条目。 u8 Load_Fun_Sel(const u8 * *list,const u8 *title,u8 *func,u8 len,u8 sel) { u8 t,key; Load_Gui_Bro(func); //显示标题 POINT_COLOR=WHITE; Show_Str_Mid(0,2,(u8*)title,16,240); //叠加模式,非自动换行 POINT_COLOR=DARKBLUE; Show_Str(0,23,"请选择:",16,0x01); //叠加模式,非自动换行 //加载条目信息 for(t=0;t<len;t++) { if(t==sel) { LCD_Fill(0,45+sel*32,239,37+(sel+1)*32,LBBLUE );//对选中的条目,填充棕色 POINT_COLOR=WHITE; }else POINT_COLOR=DARKBLUE; Show_Str(0,50+t*32,(u8*)list[t],16,0x01); //叠加模式,非自动换行 } key=0; Pen_Point.Key_Sta=Key_Up;//释放显示期间的触发 while(1)//等待按键 { key=AI_Read_TP(30); if(key)Pen_Point.Key_Reg|=0X80;//标记按键已经按下了 if(key==0&&(Pen_Point.Key_Reg&0X80))//按键松开了 { Pen_Point.Key_Reg=0; key=Touch_To_Num(2); if(key)//有按键按下 { switch(key) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9://确认键按下 key-=1; if(sel!=key&&key<len)//选中一个 { POINT_COLOR=DARKBLUE;//画笔颜色选择 LCD_Fill(0,45+sel*32,239,37+(sel+1)*32,WHITE);//清空上次选择的 Show_Str(0,50+sel*32,(u8*)list[sel],16,0x01);//重新显示上次的名字 sel=key;//选择这次选择的 LCD_Fill(0,45+sel*32,239,37+(sel+1)*32,LBBLUE);//填充底色 POINT_COLOR=WHITE;//画笔颜色选择 Show_Str(0,50+sel*32,(u8*)list[sel],16,0x01);//显示名字 }else if(sel==key||key==8)//选择按钮,或者双击 { return sel;//返回选择的条目号 } break; case 10:return 8;//选择了"返回"按钮,返回一个不可能值 } key=0;//取消按键值 } } delay_ms(1); } }
void LCD_Init_Oled(void) { //设置PORTA pin14,pin15为GPIO口 // PORTC_PCR12=(0|PORT_PCR_MUX(1)); // PORTC_PCR13=(0|PORT_PCR_MUX(1)); // PORTC_PCR14=(0|PORT_PCR_MUX(1)); // PORTC_PCR15=(0|PORT_PCR_MUX(1)); PORTE_PCR24=(0|PORT_PCR_MUX(1)); PORTA_PCR14=(0|PORT_PCR_MUX(1)); PORTE_PCR25=(0|PORT_PCR_MUX(1)); PORTA_PCR16=(0|PORT_PCR_MUX(1)); //设置PORTA pin14,pin15为输出方向;pin16,pin17为输入方向 // GPIOC_PDDR=GPIO_PDDR_PDD(GPIO_PIN(12)|GPIO_PIN(13)|GPIO_PIN(14)|GPIO_PIN(15)); GPIOA_PDDR=GPIO_PDDR_PDD(GPIO_PIN(14)|GPIO_PIN(16)); GPIOE_PDDR=GPIO_PDDR_PDD(GPIO_PIN(24)|GPIO_PIN(25)); // GPIOC_PDOR |= GPIO_PDOR_PDO(GPIO_PIN(12)); // //LCD_CS=1; //预制SLK和SS为高电平 // // GPIOC_PDOR &= ~GPIO_PDOR_PDO(GPIO_PIN(14)); // LCD_DLY_ms(50); // GPIOC_PDOR |= GPIO_PDOR_PDO(GPIO_PIN(14)); GPIOE_PDOR |= GPIO_PDOR_PDO(GPIO_PIN(25)); //LCD_CS=1; //预制SLK和SS为高电平 GPIOA_PDOR &= ~GPIO_PDOR_PDO(GPIO_PIN(14)); LCD_DLY_ms(50); GPIOA_PDOR |= GPIO_PDOR_PDO(GPIO_PIN(14)); LCD_WrCmd(0xae);//--turn off oled panel LCD_WrCmd(0x00);//---set low column address LCD_WrCmd(0x10);//---set high column address LCD_WrCmd(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F) LCD_WrCmd(0x81);//--set contrast control register LCD_WrCmd(0xcf); // Set SEG Output Current Brightness LCD_WrCmd(0xa1);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常 LCD_WrCmd(0xc8);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常 LCD_WrCmd(0xa6);//--set normal display LCD_WrCmd(0xa8);//--set multiplex ratio(1 to 64) LCD_WrCmd(0x3f);//--1/64 duty LCD_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F) LCD_WrCmd(0x00);//-not offset LCD_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency LCD_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec LCD_WrCmd(0xd9);//--set pre-charge period LCD_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock LCD_WrCmd(0xda);//--set com pins hardware configuration LCD_WrCmd(0x12); LCD_WrCmd(0xdb);//--set vcomh LCD_WrCmd(0x40);//Set VCOM Deselect Level LCD_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02) LCD_WrCmd(0x02);// LCD_WrCmd(0x8d);//--set Charge Pump enable/disable LCD_WrCmd(0x14);//--set(0x10) disable LCD_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5) LCD_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7) LCD_WrCmd(0xaf);//--turn on oled panel LCD_Fill(0x00); //初始清屏 LCD_Set_Pos(0,0); }
//播放音乐 void audio_play(void) { u8 res; DIR wavdir; //目录 FILINFO wavfileinfo;//文件信息 u8 *fn; //长文件名 u8 *pname; //带路径的文件名 u16 totwavnum; //音乐文件总数 u16 curindex; //图片当前索引 u8 key; //键值 u16 temp; u16 *wavindextbl; //音乐索引表 WM8978_ADDA_Cfg(1,0); //开启DAC WM8978_Input_Cfg(0,0,0);//关闭输入通道 WM8978_Output_Cfg(1,0); //开启DAC输出 while(f_opendir(&wavdir,"0:/MUSIC"))//打开音乐文件夹 { Show_Str(60,190,240,16,"MUSIC文件夹错误!",16,0); delay_ms(200); LCD_Fill(60,190,240,206,WHITE);//清除显示 delay_ms(200); } totwavnum=audio_get_tnum("0:/MUSIC"); //得到总有效文件数 while(totwavnum==NULL)//音乐文件总数为0 { Show_Str(60,190,240,16,"没有音乐文件!",16,0); delay_ms(200); LCD_Fill(60,190,240,146,WHITE);//清除显示 delay_ms(200); } wavfileinfo.lfsize=_MAX_LFN*2+1; //长文件名最大长度 wavfileinfo.lfname=mymalloc(SRAMIN,wavfileinfo.lfsize); //为长文件缓存区分配内存 pname=mymalloc(SRAMIN,wavfileinfo.lfsize); //为带路径的文件名分配内存 wavindextbl=mymalloc(SRAMIN,2*totwavnum); //申请2*totwavnum个字节的内存,用于存放音乐文件索引 while(wavfileinfo.lfname==NULL||pname==NULL||wavindextbl==NULL)//内存分配出错 { Show_Str(60,190,240,16,"内存分配失败!",16,0); delay_ms(200); LCD_Fill(60,190,240,146,WHITE);//清除显示 delay_ms(200); } //记录索引 res=f_opendir(&wavdir,"0:/MUSIC"); //打开目录 if(res==FR_OK) { curindex=0;//当前索引为0 while(1)//全部查询一遍 { temp=wavdir.index; //记录当前index res=f_readdir(&wavdir,&wavfileinfo); //读取目录下的一个文件 if(res!=FR_OK||wavfileinfo.fname[0]==0)break; //错误了/到末尾了,退出 fn=(u8*)(*wavfileinfo.lfname?wavfileinfo.lfname:wavfileinfo.fname); res=f_typetell(fn); if((res&0XF0)==0X40)//取高四位,看看是不是音乐文件 { wavindextbl[curindex]=temp;//记录索引 curindex++; } } } curindex=0; //从0开始显示 res=f_opendir(&wavdir,(const TCHAR*)"0:/MUSIC"); //打开目录 while(res==FR_OK)//打开成功 { dir_sdi(&wavdir,wavindextbl[curindex]); //改变当前目录索引 res=f_readdir(&wavdir,&wavfileinfo); //读取目录下的一个文件 if(res!=FR_OK||wavfileinfo.fname[0]==0)break; //错误了/到末尾了,退出 fn=(u8*)(*wavfileinfo.lfname?wavfileinfo.lfname:wavfileinfo.fname); strcpy((char*)pname,"0:/MUSIC/"); //复制路径(目录) strcat((char*)pname,(const char*)fn); //将文件名接在后面 LCD_Fill(60,190,240,190+16,WHITE); //清除之前的显示 Show_Str(60,190,240-60,16,fn,16,0); //显示歌曲名字 audio_index_show(curindex+1,totwavnum); key=audio_play_song(pname); //播放这个音频文件 if(key==KEY2_PRES) //上一曲 { if(curindex)curindex--; else curindex=totwavnum-1; }else if(key==KEY0_PRES)//下一曲 { curindex++; if(curindex>=totwavnum)curindex=0;//到末尾的时候,自动从头开始 }else break; //产生了错误 } myfree(SRAMIN,wavfileinfo.lfname); //释放内存 myfree(SRAMIN,pname); //释放内存 myfree(SRAMIN,wavindextbl); //释放内存 }
//触摸画板功能演示函数 void Wireless_Play(void) { u8 err=0,i; u8 key; u8 mode;//24L01的模式设置 u8 tmp_buf[5];//低4个字节,传递坐标值,最高一个字节:0,正常画图,1清除;2,退出; mode=Wireless_Mode_Set(); if(mode==0) { SPIx_Init();//设置回原来的 SPIx_SetSpeed(SPI_SPEED_4);//18Mhz return;//24L01检测失败,直接退出 } if(mode==2) { Load_Gui_Show("清除","发送","返回");//加载界面 TX_Mode();//发送模式 }else { Load_Gui_Show("清除","接收","返回");//加载界面 RX_Mode();//接收模式 } LCD_Fill(0,0,240,296,LGRAY);//填充灰色 POINT_COLOR=BLUE;//设置字体为蓝色 while(1) { key=AI_Read_TP(20);//得到触点的状态 if(mode==1)//接收模式 { if(NRF24L01_RxPacket(tmp_buf)==0)//一旦接收到信息,则显示出来. { Pen_Point.X=tmp_buf[0]; Pen_Point.X=(Pen_Point.X<<8)+tmp_buf[1]; Pen_Point.Y=tmp_buf[2]; Pen_Point.Y=(Pen_Point.Y<<8)+tmp_buf[3]; switch(tmp_buf[4]) { case 0://正常画点 Draw_Big_Point(Pen_Point.X,Pen_Point.Y);//画点 break; case 1://清除 LCD_Fill(0,0,240,296,LGRAY);//填充灰色 break; case 2://退出 Pen_Point.Key_Reg=0;//清除笔状态 SPIx_Init();//设置回原来的 SPIx_SetSpeed(SPI_SPEED_4);//18Mhz return; } } } if(key)//触摸屏被按下 { Pen_Point.Key_Reg|=0x80;//标记按下了按键 if(Pen_Point.Y<296&&mode==2)//在画图区域内,且为发送模式 { tmp_buf[0]=Pen_Point.X>>8; tmp_buf[1]=Pen_Point.X&0xFF; tmp_buf[2]=Pen_Point.Y>>8; tmp_buf[3]=Pen_Point.Y&0xFF; tmp_buf[4]=0;//功能为0,正常画图 Draw_Big_Point(Pen_Point.X,Pen_Point.Y);//画点 err=0; while(NRF24L01_TxPacket(tmp_buf)!=TX_OK)//等待发送完成 { err++; if(err>10)return;//连续超过10次错误,则返回 } } }else if(Pen_Point.Key_Reg&0X80)//按键松开了
/************************************************* 函数: void UP_LCD_ClearScreen(void) 功能: 清除屏幕内容 参数: 无 返回: 无 **************************************************/ void UP_LCD_ClearScreen(void) { LCD_Fill(0); g_LCD_X = g_LCD_Y = 0; }
int main(void) { //定义全局变量 u8 key,mode; u16 t=0; u8 tmp_buf[33]; //函数初始化 delay_init(); //延时函数初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级 uart_init(115200); //串口初始化为115200 usmart_dev.init(72); //初始化USMART LED_Init(); //初始化与LED连接的硬件接口 KEY_Init(); //初始化按键 NRF24L01_Init(); //初始化NRF24L01 W25QXX_Init(); //初始化W25Q128 my_mem_init(SRAMIN); //初始化内部内存池 LCD_Init(); //初始化LCD exfuns_init(); //为fatfs相关变量申请内存 f_mount(fs[0],"0:",1); //挂载SD卡 f_mount(fs[1],"1:",1); //挂载FLASH. //检查中文字库 while(font_init()) //检查字库 { LCD_Clear(WHITE); //清屏 POINT_COLOR=RED; //设置字体为红色 LCD_ShowString(30,50,200,16,16,"WarShip STM32"); while(SD_Init()) //检测SD卡 { LCD_ShowString(30,70,200,16,16,"SD Card Failed!"); delay_ms(200); LCD_Fill(30,70,200+30,70+16,WHITE); delay_ms(200); } LCD_ShowString(30,70,200,16,16,"SD Card OK"); LCD_ShowString(30,90,200,16,16,"Font Updating..."); key=update_font(20,110,16,"0:");//更新字库 while(key)//更新失败 { LCD_ShowString(30,110,200,16,16,"Font Update Failed!"); delay_ms(200); LCD_Fill(20,110,200+20,110+16,WHITE); delay_ms(200); } LCD_ShowString(30,110,200,16,16,"Font Update Success! "); delay_ms(1500); LCD_Clear(WHITE);//清屏 } //检查无线通信 while(NRF24L01_Check()) { LCD_ShowString(30,130,200,16,16,"NRF24L01 Error"); delay_ms(200); LCD_Fill(30,130,239,130+16,WHITE); delay_ms(200); } //初始化界面 POINT_COLOR = MAGENTA; Show_Str(20,20,200,24,"第十一届全国电子",24,0); Show_Str(80,50,200,24,"设计大赛",24,0); while(1) { //按键扫描 key=KEY_Scan(0); if(key!=0) { LCD_Clear(WHITE); Show_Str(60,20,200,24,"旋转倒立摆",24,0); Show_Str(20,50,200,24,"任务1:",24,0); Show_Str(20,80,200,24,"任务2:",24,0); Show_Str(20,110,200,24,"任务3:",24,0); Show_Str(20,140,200,24,"任务4:",24,0); Show_Str(20,170,200,24,"任务5:",24,0); Show_Str(20,200,200,24,"任务6:",24,0); while(1) { key=KEY_Scan(0); //WKUP_PRES 功能:返回主界面 if(key==WKUP_PRES) { MUSE_TASK(); } //KEY1_PRES 功能:执行任务1 else if(key==KEY0_PRES) { KEY0_TASK(); } // //KEY1_PRES 功能:执行任务1 // else if(key==KEY1_PRES) // { // mode=1; // break; // } // //KEY2_PRES 功能:执行任务2 // else if(key==KEY2_PRES) // { // mode=1; // break; // } // //KEY3_PRES 功能:执行任务3 // else if(key==KEY3_PRES) // { // mode=1; // break; // } // //KEY4_PRES 功能:执行任务4 // else if(key==KEY4_PRES) // { // mode=1; // break; // } // //KEY5_PRES 功能:执行任务5 // else if(key==KEY5_PRES) // { // mode=1; // break; // } // //KEY6_PRES 功能:执行任务6 // else if(key==KEY6_PRES) // { // mode=1; // break; // } // //KEY7_PRES 功能:执行任务7 // else if(key==KEY7_PRES) // { // mode=1; // break; // } // //KEY8_PRES 功能:执行任务8 // else if(key==KEY8_PRES) // { // mode=1; // break; // } // } } t++; if(t==100) //LCD_ShowString(10,150,230,16,16,"KEY0:RX_Mode KEY1:TX_Mode"); //闪烁显示提示信息 Show_Str(10,150,230,24,"按任意键进入主菜单",24,0); if(t==200) { LCD_Fill(10,150,240,150+50,WHITE); t=0; } delay_ms(5); } }
void main(void) { int i1=0; int count10S = 0; Device_init(); disable_irq(PIT0_IRQn); systick_delay_ms(50); FLOAT_LDC_init(SPI1); systick_delay_ms(50); FLOAT_LDC_init(SPI0); systick_delay_ms(1000); uart_init(UART3,115200); key_init(0); key_init(1); key_init(2); //LDC_EVM_TEST(); //Speed_Ctl_Init(short point_value, double dKpp, double dKii, double dKdd); while(1) { //value_collect(); LCD_P6x8Str(0,2,"Rmax Lmin"); printf("Rmax Rmin\r\n"); systick_delay_ms(1500); i1=50; while(i1--) { adjustment[2]=(float)filter(SPI1)/10;//右max LCD_BL(55,2,(uint16)adjustment[2]); printf("%d\r\n",adjustment[2]); } i1=50; while(i1--) { adjustment[1]=(float)filter(SPI0)/10;//左min LCD_BL(90,2,(uint16)adjustment[1]); printf("%d\r\n",adjustment[1]); } LCD_BL(55,2,(uint16)adjustment[1]); LCD_BL(90,2,(uint16)adjustment[2]); LCD_P6x8Str(0,4,"Lmax Rmin"); printf("Lmax Rmin\r\n"); systick_delay_ms(1500); i1=50; while(i1--) { adjustment[3]=(float)filter(SPI1)/10;//右min LCD_BL(55,4,(uint16)adjustment[3]); printf("%d\r\n",adjustment[3]); } i1=50; while(i1--) { adjustment[4]=(float)filter(SPI0)/10;//左max LCD_BL(90,4,(uint16)adjustment[4]); printf("%d\r\n",adjustment[4]); } LCD_BL(55,4,(uint16)adjustment[4]); LCD_BL(90,4,(uint16)adjustment[3]); if(adjustment[1]<=adjustment[3]) adjustment[5]=adjustment[1];//次小值 else adjustment[5]=adjustment[3];//次小值 if(adjustment[2]>=adjustment[4]) adjustment[6]=adjustment[2];//次大值 else adjustment[6]=adjustment[4];//次大值 divisor = (adjustment[2] - adjustment[3])/60; //48 //50 divisor2 = (adjustment[4] - adjustment[1])/59; //48 //45 zengfuzhi = (adjustment[2] - adjustment[3])/(adjustment[4] - adjustment[1]); // for(int i=0;i<10;i++) // { // printf("%d\r\n",adjustment[i]); // } // systick_delay_ms(1000); LCD_P6x8Str(0,6,"Mid value"); i1 = 50; systick_delay_ms(1500); while(i1--) { adjustment[7]=(float)filter(SPI0)/10;//左 adjustment[8]=(float)filter(SPI1)/10;//右 LCD_BL(55,6,(uint16)adjustment[7]); LCD_BL(90,6,(uint16)adjustment[8]); } if(adjustment[7]>=adjustment[8]) { flag=1; adjustment[0]=adjustment[7]-adjustment[8]; } else { flag=0; adjustment[0]=adjustment[8]-adjustment[7]; } LCD_Fill(0x00); Out_side_collect(); LCD_Fill(0x00); adjustment_change(); enable_irq(PIT0_IRQn); while(1) { if(PIT_1sFlag == 1) { gpio_turn(PTD4); PIT_1sFlag = 0; count10S ++; } if(key_check(2) == 0) { LCD_Fill(0x00); Motor_stop(); break; } else { if(PIT_5msFlag == 1) { LDC_get(); PIT_5msFlag = 0; Steering_Change(); } if(count10S > 10) { if(gpio_get(PTC4) == 0) { while(1) { Motor_stop(); Steering_Change(); } } } if(PIT_10msFlag == 1) { Quad_count(); now = (float)guad_val; Motor_PID(now); PIT_10msFlag = 0; } if(PIT_20msFlag == 1) { PIT_20msFlag = 0; } if(PIT_50msFlag == 1) { //Result_collect(); PIT_50msFlag = 0; } //printf("guad_val:%d \r\n",(guad_val)); //TEST_display(); speed_control(); //key_choice(); uint16 i23 = gpio_get(PTC4); //LCD_BL(50,2,(uint16)(i23)); } } } }
/*-----------------------------------------------------------------------*/ void init_all_and_POST(void) { int i = 0; /* TF卡 */ TCHAR *path = "0:"; disable_watchdog(); init_modes_and_clock(); initEMIOS_0MotorAndSteer(); initEMIOS_0Image();/* 摄像头输入中断初始化 */ init_pit(); init_led(); init_DIP(); init_serial_port_0(); init_serial_port_1(); init_serial_port_2(); //init_ADC(); //init_serial_port_3(); init_supersonic_receive_0(); init_supersonic_receive_1(); // init_supersonic_receive_2(); // init_supersonic_receive_3(); init_supersonic_trigger_0(); init_supersonic_trigger_1(); // init_supersonic_trigger_2(); // init_supersonic_trigger_3(); // init_optical_encoder(); //init_DSPI_2(); //init_I2C(); init_choose_mode(); /* 初始化SPI总线 */ init_DSPI_1(); /* 开启外部总中断 */ enable_irq(); /* 初始化显示屏 */ initLCD(); //LCD_DISPLAY(); LCD_Fill(0xFF); /* 亮屏 */ delay_ms(50); LCD_Fill(0x00); /* 黑屏 */ delay_ms(50); #if 1 /* 初始化TF卡 */ LCD_P8x16Str(0,0, (BYTE*)"TF.."); if (!SD_init()) { /* 挂载TF卡文件系统 */ if (FR_OK == f_mount(&fatfs1, path, 1)) { /* 文件读写测试 */ if (!test_file_system()) { g_devices_init_status.TFCard_is_OK = 1; } } } if (g_devices_init_status.TFCard_is_OK) { LCD_P8x16Str(0,0, (BYTE*)"TF..OK"); } else { LCD_P8x16Str(0,0, (BYTE*)"TF..NOK"); suicide(); } /* 读取设备号 */ LCD_P8x16Str(0, 4, (BYTE*)"DeviceNo="); if (!read_device_no_from_TF()) { if (WIFI_ADDRESS_WITHOUT_INIT != g_device_NO) { LCD_PrintoutInt(72, 4, g_device_NO); } else { suicide(); } } else { suicide(); } /* 开启RFID读卡器主动模式 */ if (!init_RFID_modul_type()) { g_devices_init_status.RFIDCard_energetic_mode_enable_is_OK = 1; LCD_P8x16Str(0, 6, (BYTE*)"RFID..OK"); } else { g_devices_init_status.RFIDCard_energetic_mode_enable_is_OK = 0; LCD_P8x16Str(0, 6, (BYTE*)"RFID..NOK"); suicide(); } delay_ms(1000); /* 换屏 */ LCD_Fill(0x00); /* 读取舵机参数 */ LCD_P8x16Str(0, 0, (BYTE*)"StH.L="); if (read_steer_helm_data_from_TF()) { suicide(); } update_steer_helm_basement_to_steer_helm(); LCD_PrintoutInt(48, 0, data_steer_helm_basement.left_limit); set_steer_helm_basement(data_steer_helm_basement.left_limit); delay_ms(500); LCD_P8x16Str(0, 2, (BYTE*)"StH.R="); LCD_PrintoutInt(48, 2, data_steer_helm_basement.right_limit); set_steer_helm_basement(data_steer_helm_basement.right_limit); delay_ms(500); LCD_P8x16Str(0, 4, (BYTE*)"StH.C="); LCD_PrintoutInt(48, 4, data_steer_helm_basement.center); set_steer_helm_basement(data_steer_helm_basement.center); /* 读取mode号 */ LCD_P8x16Str(0, 6, (BYTE*)"MODE="); LCD_PrintoutInt(40, 6, mode); //set_pos_target(); delay_ms(1000); /* 换屏 */ LCD_Fill(0x00); /* 速度闭环测试 */ g_f_enable_speed_control = 1; LCD_P8x16Str(0, 4, (BYTE*)"S.T=0"); set_speed_target(0); delay_ms(2000); /* 换屏 */ LCD_Fill(0x00); #endif }
//画一个大点 //POINT_COLOR:此点的颜色 void LCD_DrawPoint_big(u16 x,u16 y) { LCD_Fill(x-1,y-1,x+1,y+1,POINT_COLOR); }
/*-----------------------------------------------------------------------*/ void init_all_and_POST(void) { int i = 0; disable_watchdog(); init_modes_and_clock(); initEMIOS_0MotorAndSteer(); /* PIT:光编读值&速度控制 */ // init_pit_10ms(); /* PIT:步进电机控制&角度控制标志位 */ init_pit_1ms(); //init_Stepmotor(); /* 初始化步进电机 */ init_led(); //init_DIP(); /* 拨码开关 */ init_serial_port_1(); /* BlueTooth */ init_ADC(); /* 陀螺仪读值 - 其中一路ADC与MPU9250片选冲突,不要同时打开*/ init_optical_encoder(); /* 光编 */ //init_I2C(); //init_choose_mode(); /* 拨码开关模式选择 */ /* 初始化SPI总线 */ init_DSPI_1(); /* 开启外部总中断 */ enable_irq(); /* 初始化显示屏 */ initLCD(); LCD_DISPLAY(); LCD_Fill(0xFF); /* 亮屏 */ delay_ms(50); LCD_Fill(0x00); /* 黑屏 */ delay_ms(50); /*初始化螺旋桨电机,给1000占空比*/ set_PropellerA_motor_pwm(1000); set_PropellerB_motor_pwm(1000); /* 初始化TF卡 */ //test_init_TF(); /* 读取设备号 */ //read_device_no(); /* 初始化陀螺仪 */ // init_MPU9250(); //delay_ms(1000); /* 换屏 */ //LCD_Fill(0x00); /* 读取舵机参数 */ //read_display_helm(); /* 读取拨码开关模式号 */ //read_DIP_mode(); //delay_ms(1000); /* 换屏 */ //LCD_Fill(0x00); /* 速度闭环开启及测试 速度=0 */ //init_speed_control(); // g_f_enable_supersonic=1; //delay_ms(2000); /* 换屏 */ //LCD_Fill(0x00); }
int main(void) { u8 offline_cnt=0; u8 tct=0; u8 USB_STA; u8 Divece_STA; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//中断分组设置 delay_init(); //延时函数初始化 uart_init(9600); //串口初始化为9600 LCD_Init(); //初始化液晶 LED_Init(); //LED初始化 KEY_Init(); //按键初始化 POINT_COLOR=RED; //设置字体为红色 LCD_ShowString(60,50,200,16,16,"Mini STM32"); LCD_ShowString(60,70,200,16,16,"USB Card Reader TEST"); LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK"); LCD_ShowString(60,110,200,16,16,"2014/3/15"); SPI_Flash_Init(); if(SD_Initialize())LCD_ShowString(60,130,200,16,16,"SD Card Error!"); //检测SD卡错误 else //SD 卡正常 { LCD_ShowString(60,130,200,16,16,"SD Card Size: MB"); Mass_Memory_Size[0]=(long long)SD_GetSectorCount()*512;//得到SD卡容量(字节),当SD卡容量超过4G的时候,需要用到两个u32来表示 Mass_Block_Size[0] =512;//因为我们在Init里面设置了SD卡的操作字节为512个,所以这里一定是512个字节. Mass_Block_Count[0]=Mass_Memory_Size[0]/Mass_Block_Size[0]; LCD_ShowNum(164,130,Mass_Memory_Size[0]>>20,5,16); //显示SD卡容量 } if(SPI_FLASH_TYPE!=W25Q64)LCD_ShowString(60,130,200,16,16,"W25Q64 Error!"); //检测SD卡错误 else //SPI FLASH 正常 { Mass_Memory_Size[1]=4916*1024;//前4.8M字节 Mass_Block_Size[1] =512;//因为我们在Init里面设置了SD卡的操作字节为512个,所以这里一定是512个字节. Mass_Block_Count[1]=Mass_Memory_Size[1]/Mass_Block_Size[1]; LCD_ShowString(60,150,200,16,16,"SPI FLASH Size:4916KB"); } delay_ms(1800); USB_Port_Set(0); //USB先断开 delay_ms(300); USB_Port_Set(1); //USB再次连接 LCD_ShowString(60,170,200,16,16,"USB Connecting...");//提示SD卡已经准备了 Data_Buffer=mymalloc(BULK_MAX_PACKET_SIZE*2*4); //为USB数据缓存区申请内存 Bulk_Data_Buff=mymalloc(BULK_MAX_PACKET_SIZE); //申请内存 //USB配置 USB_Interrupts_Config(); Set_USBClock(); USB_Init(); delay_ms(1800); while(1) { delay_ms(1); if(USB_STA!=USB_STATUS_REG)//状态改变了 { LCD_Fill(60,190,240,190+16,WHITE);//清除显示 if(USB_STATUS_REG&0x01)//正在写 { LCD_ShowString(60,190,200,16,16,"USB Writing...");//提示USB正在写入数据 } if(USB_STATUS_REG&0x02)//正在读 { LCD_ShowString(60,190,200,16,16,"USB Reading...");//提示USB正在读出数据 } if(USB_STATUS_REG&0x04)LCD_ShowString(60,210,200,16,16,"USB Write Err ");//提示写入错误 else LCD_Fill(60,210,240,210+16,WHITE);//清除显示 if(USB_STATUS_REG&0x08)LCD_ShowString(60,230,200,16,16,"USB Read Err ");//提示读出错误 else LCD_Fill(60,230,240,230+16,WHITE);//清除显示 USB_STA=USB_STATUS_REG;//记录最后的状态 } if(Divece_STA!=bDeviceState) { if(bDeviceState==CONFIGURED)LCD_ShowString(60,170,200,16,16,"USB Connected ");//提示USB连接已经建立 else LCD_ShowString(60,170,200,16,16,"USB DisConnected ");//提示USB被拔出了 Divece_STA=bDeviceState; } tct++; if(tct==200) { tct=0; LED0=!LED0;//提示系统在运行 if(USB_STATUS_REG&0x10) { offline_cnt=0;//USB连接了,则清除offline计数器 bDeviceState=CONFIGURED; }else//没有得到轮询 { offline_cnt++; if(offline_cnt>10)bDeviceState=UNCONNECTED;//2s内没收到在线标记,代表USB被拔出了 } USB_STATUS_REG=0; } }; }
//TCP Server 测试 void tcp_server_test(void) { err_t err; struct tcp_pcb *tcppcbnew; //定义一个TCP服务器控制块 struct tcp_pcb *tcppcbconn; //定义一个TCP服务器控制块 u8 *tbuf; u8 key; u8 res=0; u8 t=0; u8 connflag=0; //连接标记 LCD_Clear(WHITE); //清屏 POINT_COLOR=RED; //红色字体 LCD_ShowString(30,30,200,16,16,"Explorer STM32F4"); LCD_ShowString(30,50,200,16,16,"TCP Server Test"); LCD_ShowString(30,70,200,16,16,"ATOM@ALIENTEK"); LCD_ShowString(30,90,200,16,16,"KEY0:Send data"); LCD_ShowString(30,110,200,16,16,"KEY_UP:Quit"); tbuf=mymalloc(SRAMIN,200); //申请内存 if(tbuf==NULL)return ; //内存申请失败了,直接退出 sprintf((char*)tbuf,"Server IP:%d.%d.%d.%d",lwipdev.ip[0],lwipdev.ip[1],lwipdev.ip[2],lwipdev.ip[3]);//服务器IP LCD_ShowString(30,130,210,16,16,tbuf); sprintf((char*)tbuf,"Server Port:%d",TCP_SERVER_PORT);//服务器端口号 LCD_ShowString(30,150,210,16,16,tbuf); tcppcbnew=tcp_new(); //创建一个新的pcb if(tcppcbnew) //创建成功 { err=tcp_bind(tcppcbnew,IP_ADDR_ANY,TCP_SERVER_PORT); //将本地IP与指定的端口号绑定在一起,IP_ADDR_ANY为绑定本地所有的IP地址 if(err==ERR_OK) //绑定完成 { tcppcbconn=tcp_listen(tcppcbnew); //设置tcppcb进入监听状态 tcp_accept(tcppcbconn,tcp_server_accept); //初始化LWIP的tcp_accept的回调函数 }else res=1; }else res=1; POINT_COLOR=BLUE;//蓝色字体 while(res==0) { key=KEY_Scan(0); if(key==WKUP_PRES)break; if(key==KEY0_PRES)//KEY0按下了,发送数据 { tcp_server_flag|=1<<7;//标记要发送数据 } if(tcp_server_flag&1<<6)//是否收到数据? { LCD_Fill(30,210,lcddev.width-1,lcddev.height-1,WHITE);//清上一次数据 LCD_ShowString(30,210,lcddev.width-30,lcddev.height-210,16,tcp_server_recvbuf);//显示接收到的数据 tcp_server_flag&=~(1<<6);//标记数据已经被处理了. } if(tcp_server_flag&1<<5)//是否连接上? { if(connflag==0) { sprintf((char*)tbuf,"Client IP:%d.%d.%d.%d",lwipdev.remoteip[0],lwipdev.remoteip[1],lwipdev.remoteip[2],lwipdev.remoteip[3]);//客户端IP LCD_ShowString(30,170,230,16,16,tbuf); POINT_COLOR=RED; LCD_ShowString(30,190,lcddev.width-30,lcddev.height-190,16,"Receive Data:");//提示消息 POINT_COLOR=BLUE;//蓝色字体 connflag=1;//标记连接了 } }else if(connflag) { LCD_Fill(30,170,lcddev.width-1,lcddev.height-1,WHITE);//清屏 connflag=0; //标记连接断开了 } lwip_periodic_handle(); delay_ms(2); t++; if(t==200) { t=0; LED0=!LED0; } } tcp_server_connection_close(tcppcbnew,0);//关闭TCP Server连接 tcp_server_connection_close(tcppcbconn,0);//关闭TCP Server连接 tcp_server_remove_timewait(); memset(tcppcbnew,0,sizeof(struct tcp_pcb)); memset(tcppcbconn,0,sizeof(struct tcp_pcb)); myfree(SRAMIN,tbuf); }
//触摸画板功能演示函数 void Touch_Play(void) { u8 i; u8 key; u8 M_STA=0; u16 temp_color; LCD_Clear(WHITE); Load_Gui_Show("重画","颜色","返回");//加载界面 POINT_COLOR=RED; while(1) { key=AI_Read_TP(20);//得到触点的状态 if(key)//触摸屏被按下 { Pen_Point.Key_Reg|=0x80;//标记按下了按键 if(Pen_Point.Y<296&&M_STA==0)//在画图区域内,并且颜色框没有弹出来 { Draw_Big_Point(Pen_Point.X,Pen_Point.Y);//画点 } }else if(Pen_Point.Key_Reg&0X80)//按键松开了 { if(Pen_Point.Key_Reg&0x02)//点动按下 { if(M_STA)//菜单已经弹出来了 { if(Pen_Point.X>88&&Pen_Point.X<153&&Pen_Point.Y>268)//在颜色框内 { temp_color=LCD_ReadPoint(Pen_Point.X,Pen_Point.Y);//读取该点的颜色 if(temp_color!=FRAME2)//不是按在边框上 { Reshow_Temp_Color(88,268,65,29);//恢复之前的颜色 POINT_COLOR=temp_color;//修改画笔颜色 M_STA=0; } }else { Reshow_Temp_Color(88,268,65,29);//恢复之前的颜色 M_STA=0; } } if(Is_In_Area(5,300,32,16))//清除按钮按下了 { LCD_Fill(0,0,239,296,WHITE);//清屏 }else if(Is_In_Area(104,300,32,16))//颜色按钮按下了 { Read_Temp_Color(88,268,65,29);//先读出之前的颜色值 Draw_Color_Table(88,268); M_STA=1;//标记颜色框已经显示出来了 }else if(Is_In_Area(203,300,32,16))//返回按钮按下了 { Pen_Point.Key_Reg=0;//清除笔状态 return; } } Pen_Point.Key_Reg=0;//清除笔状态 }else delay_ms(1); i++; if(i==200) { i=0; LED0=!LED0; } } }
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; } } }
int main(void) { u8 key; u8 lightmode=0,saturation=2,contrast=2; u8 effect=0; u8 i=0; u8 msgbuf[15]; //消息缓存区 u8 tm=0; delay_init(); //延时函数初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级 uart_init(115200); //串口初始化为 115200 usmart_dev.init(72); //初始化USMART LED_Init(); //初始化与LED连接的硬件接口 KEY_Init(); //初始化按键 LCD_Init(); //初始化LCD TPAD_Init(6); //触摸按键初始化 POINT_COLOR=RED; //设置字体为红色 LCD_ShowString(30,50,200,16,16,"ELITE STM32F103 ^_^"); LCD_ShowString(30,70,200,16,16,"OV7670 TEST"); LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK"); LCD_ShowString(30,110,200,16,16,"2015/1/18"); LCD_ShowString(30,130,200,16,16,"KEY0:Light Mode"); LCD_ShowString(30,150,200,16,16,"KEY1:Saturation"); LCD_ShowString(30,170,200,16,16,"KEY_UP:Contrast"); LCD_ShowString(30,190,200,16,16,"TPAD:Effects"); LCD_ShowString(30,210,200,16,16,"OV7670 Init..."); while(OV7670_Init())//初始化OV7670 { LCD_ShowString(30,210,200,16,16,"OV7670 Error!!"); delay_ms(200); LCD_Fill(30,210,239,246,WHITE); delay_ms(200); } LCD_ShowString(30,210,200,16,16,"OV7670 Init OK"); delay_ms(1500); OV7670_Light_Mode(lightmode); OV7670_Color_Saturation(saturation); OV7670_Contrast(contrast); OV7670_Special_Effects(effect); TIM6_Int_Init(10000,7199); //10Khz计数频率,1秒钟中断 EXTI8_Init(); //使能定时器捕获 OV7670_Window_Set(12,176,240,320); //设置窗口 OV7670_CS=0; LCD_Clear(BLACK); while(1) { key=KEY_Scan(0);//不支持连按 if(key) { tm=20; switch(key) { case KEY0_PRES: //灯光模式Light Mode lightmode++; if(lightmode>4)lightmode=0; OV7670_Light_Mode(lightmode); sprintf((char*)msgbuf,"%s",LMODE_TBL[lightmode]); break; case KEY1_PRES: //饱和度Saturation saturation++; if(saturation>4)saturation=0; OV7670_Color_Saturation(saturation); sprintf((char*)msgbuf,"Saturation:%d",(signed char)saturation-2); break; case WKUP_PRES: //对比度Contrast contrast++; if(contrast>4)contrast=0; OV7670_Contrast(contrast); sprintf((char*)msgbuf,"Contrast:%d",(signed char)contrast-2); break; } } if(TPAD_Scan(0))//检测到触摸按键 { effect++; if(effect>6)effect=0; OV7670_Special_Effects(effect);//设置特效 sprintf((char*)msgbuf,"%s",EFFECTS_TBL[effect]); tm=20; } camera_refresh();//更新显示 if(tm) { LCD_ShowString((lcddev.width-240)/2+30,(lcddev.height-320)/2+60,200,16,16,msgbuf); tm--; } i++; if(i==15)//DS0闪烁. { i=0; LED0=!LED0; } } }
//加载游戏界面 //size:3,3*3图片 // 4,4*4图片 // 5,5*5图片 //#define FRAME1 0XBC40 //棕色 void Load_Game_ICO(u8 size) { u8 i; LCD_Clear(LGRAY);//清屏 for(i=0;i<4;i++)//画大边框 { POINT_COLOR=FRAME1; LCD_DrawRectangle(i,i,239-i,239-i); } if(size==3) { for(i=0;i<4;i++)//画小边框 { POINT_COLOR=FRAME1; LCD_DrawRectangle(154+i,235+i,239-i,316-i); } LCD_Fill(158,235,235,239,WHITE);//把多余的去掉 POINT_COLOR=RED; LCD_DrawRectangle(158,235,235,312);//画空的方框,事先不放图片 LCD_DrawRectangle(4,4,235,235); //画最大的红框 LCD_DrawLine(81,4,81,235); //画内部红框 LCD_DrawLine(158,4,158,235);//画内部红框 LCD_DrawLine(4,81,235,81); //画内部红框 LCD_DrawLine(4,158,235,158);//画内部红框 }else if(size==4) { for(i=0;i<4;i++)//画小边框 { POINT_COLOR=FRAME1; LCD_DrawRectangle(174+i,236+i,239-i,298-i); } LCD_Fill(178,236,236,240,WHITE);//把多余的去掉 POINT_COLOR=RED; LCD_DrawRectangle(178,236,236,294);//画空的方框,第十六格 LCD_DrawRectangle(4,4,236,236); //画最大的红框 for(i=0;i<size;i++)LCD_DrawLine(4,4+58*i,236,4+58*i); //画内部横网格线 for(i=0;i<size;i++)LCD_DrawLine(4+58*i,4,4+58*i,236); //画内部竖网格线 }else if(size==5) { for(i=0;i<4;i++)//画小边框 { POINT_COLOR=FRAME1; LCD_DrawRectangle(184+i,234+i,239-i,284-i); } LCD_DrawLine(4,235,236,235); //误差横线填充线 LCD_DrawLine(235,4,235,281); //误差竖线填充线 LCD_Fill(188,234,234,239,WHITE);//把多余的去掉 POINT_COLOR=RED; LCD_DrawRectangle(188,234,234,280);//画空的方框,第十六格 LCD_DrawRectangle(4,4,234,234); //画最大的红框 for(i=0;i<size;i++)LCD_DrawLine(4,4+46*i,234,4+46*i); //画内部横网格线 for(i=0;i<size;i++)LCD_DrawLine(4+46*i,4,4+46*i,234); //画内部竖网格线 } LCD_DrawRectangle(2,241,79,318);//包括预览图片 BACK_COLOR=WHITE; POINT_COLOR=BLUE;//画笔颜色 Show_Str(81,242,"等级:",16,0x01); POINT_COLOR=RED;//画笔颜色 if(size==3)Show_Str(121,242,"简单",16,0x01); else if(size==4)Show_Str(121,242,"一般",16,0x01); else Show_Str(121,242,"困难",16,0x01); POINT_COLOR=BLUE;//画笔颜色 Show_Str(81,258,"步数:",16,0x01); Show_Str(81,274,"用时:",16,0x01); GUI_Draw_Button(98,298,37,20,"退出",BLACK); }
//ATK-RM04 串口以太网测试 //用于测试TCP/UDP连接 //返回值:0,正常 // 其他,错误代码 u8 atk_rm04_cometh_test(void) { u8 netpro=0; //网络模式 u8 key; u8 timex=0; u8 ipbuf[16]; //IP缓存 u8 *p; u16 t=999; //加速第一次获取链接状态 u8 res=0; u16 rlen=0; u8 constate=0; //连接状态 p=mymalloc(SRAMIN,32); //申请32字节内存 atk_rm04_send_cmd("at+netmode=1","ok",500); //设置串口以太网模式 atk_rm04_send_cmd("at+dhcpd=0","ok",500); //DHCP服务器关闭(仅AP模式有效) atk_rm04_send_cmd("at+dhcpc=1","ok",500); //DHCP客户端使能(net_ip无效) PRESTA: netpro=atk_rm04_netpro_sel(50,30,(u8*)ATK_RM04_NETMODE_TBL[1]); //选择网络模式 if(netpro&0X02)atk_rm04_send_cmd("at+remotepro=udp","ok",500); //UDP协议 else atk_rm04_send_cmd("at+remotepro=tcp","ok",500); //TCP协议 sprintf((char*)p,"at+remoteport=%s",portnum); atk_rm04_send_cmd(p,"ok",500); //设置 端口号. if(netpro&0X01) //客户端 { if(atk_rm04_ip_set("ETH-COM 远端IP设置",(u8*)ATK_RM04_WORKMODE_TBL[netpro],(u8*)portnum,ipbuf))goto PRESTA; //IP输入 sprintf((char*)p,"at+remoteip=%s",ipbuf); atk_rm04_send_cmd(p,"ok",500); //设置远端(连接)IP地址. atk_rm04_send_cmd("at+mode=client","ok",500); //设置为客户端 }else atk_rm04_send_cmd("at+mode=server","ok",500); //设置为服务端 LCD_Clear(WHITE); POINT_COLOR=RED; Show_Str_Mid(0,30,"ATK-RM04 ETH-COM 测试",16,240); Show_Str(30,50,200,16,"正在配置ATK-RM04模块,请稍等...",12,0); if(atk_rm04_send_cmd("at+net_commit=1","\r\n",4000))//提交网络配置,最长可能需要等待40s { LCD_Fill(30,50,239,50+12,WHITE); //清除之前的显示 Show_Str(30,50,200,16,"配置ATK-RM04模块失败!",12,0); delay_ms(800); res=1; }else { atk_rm04_send_cmd("at+reconn=1","ok",500); //重启串口转换服务 LCD_Fill(30,50,239,50+12,WHITE);//清除之前的显示 Show_Str(30,50,200,16,"配置ATK-RM04模块成功!",12,0); delay_ms(600); Show_Str(30,50,210,16,"KEY_UP:退出测试 KEY0:发送数据",12,0); atk_rm04_quit_trans(); //退出透传 while(1) //等待ATK-RM04连接上路由器 { atk_rm04_get_wanip(p); //获取WAN IP if(p[0]!=0)break; //成功获取到了IP地址 Show_Str(30,80,200,12,"ATK-RM04 连接路由器失败",12,0); //连接失败 delay_ms(800); Show_Str(30,80,200,12,"ATK-RM04 等待连接中....",12,0); delay_ms(800); } LCD_Fill(30,80,239,80+12,WHITE); if((netpro&0X01)==0)atk_rm04_get_wanip(ipbuf);//服务器模式,获取WAN IP sprintf((char*)p,"IP地址:%s 端口:%s",ipbuf,(u8*)portnum); Show_Str(30,65,200,12,p,12,0); //显示IP地址和端口 Show_Str(30,80,200,12,"状态:",12,0); //连接状态 Show_Str(120,80,200,12,"模式:",12,0); //连接状态 Show_Str(30,100,200,12,"发送数据:",12,0); //发送数据 Show_Str(30,115,200,12,"接收数据:",12,0); //接收数据 POINT_COLOR=BLUE; Show_Str(120+30,80,200,12,(u8*)ATK_RM04_WORKMODE_TBL[netpro],12,0); //连接状态 USART3_RX_STA=0; while(1) { key=KEY_Scan(0); if(key==WKUP_PRES) //KEY_UP 退出测试 { res=0; break; }else if(key==KEY0_PRES) //KEY0 发送数据 { sprintf((char*)p,"ATK-RM04 %s测试%02d\r\n",ATK_RM04_WORKMODE_TBL[netpro],t/10);//测试数据 Show_Str(30+54,100,200,12,p,12,0); u3_printf("%s",p); //发送该数据到ATK-RM04模块 timex=100; } if(timex)timex--; if(timex==1)LCD_Fill(30+54,100,239,112,WHITE); t++; delay_ms(10); if(USART3_RX_STA&0X8000) //接收到一次数据了 { rlen=USART3_RX_STA&0X7FFF; //得到本次接收到的数据长度 USART3_RX_BUF[rlen]=0; //添加结束符 printf("%s",USART3_RX_BUF); //发送到串口 sprintf((char*)p,"收到%d字节,内容如下",rlen);//接收到的字节数 LCD_Fill(30+54,115,239,130,WHITE); POINT_COLOR=BRED; Show_Str(30+54,115,156,12,p,12,0); //显示接收到的数据长度 POINT_COLOR=BLUE; LCD_Fill(30,130,239,319,WHITE); Show_Str(30,130,180,190,USART3_RX_BUF,12,0);//显示接收到的数据 USART3_RX_STA=0; if(constate==0)t=1000; //状态为还未连接,立即更新连接状态 else t=0; //状态为已经连接了,10秒后再检查 } if(t==1000)//连续10秒钟没有收到任何数据,检查连接是不是还存在. { constate=atk_rm04_consta_check()-'0';//得到连接状态 if(constate)Show_Str(30+30,80,200,12,"连接成功",12,0); //连接状态 else Show_Str(30+30,80,200,12,"连接失败",12,0); t=0; } if((t%20)==0)LED0=!LED0; atk_rm04_at_response(1); } } myfree(SRAMIN,p); //释放内存 atk_rm04_quit_trans(); //退出透传 return res; }
//显示文件 //fcnt:要显示文件的多少 //sel :选中第几个1~8 //返回值:要打开的文件编号1~8(包括文件夹,在FileInfo里面的) //返回9,代表直接退回上一层目录 //显示文件 //check ok 09/04/19 u8 Show_File(u8 fcnt,u8 sel) { u16 t; u8 key; FileInfoStruct temp; temp.F_Type=T_BMP;//文件属性设置 sel-=1; LCD_Fill(0,42,239,297,WHITE);//填充白色,清空上次的显示 for(t=0;t<fcnt;t++) { if(F_Info[t].F_Type==T_FILE)temp.F_StartCluster=file_ico[0];//文件夹图标 else { if(F_Info[t].F_Type&(T_JPG|T_JPEG|T_BMP))temp.F_StartCluster=file_ico[2];//图片类图标 else if(F_Info[t].F_Type&(T_MP3|T_OGG|T_WMA|T_WAV|T_FLAC|T_MID))temp.F_StartCluster=file_ico[1];//音乐类图标 else if(F_Info[t].F_Type&(T_LRC|T_TXT|T_C|T_H))temp.F_StartCluster=file_ico[3];//文字类图标 } AI_LoadPicFile(&temp,0,42+t*32,32,42+t*32+32);//加载图标 if(t==sel) { LCD_Fill(32,45,239,69,LBBLUE);//填充棕色 BROWN POINT_COLOR=WHITE; }else POINT_COLOR=DARKBLUE; Show_Str(32,50+t*32,F_Info[t].F_Name,16,0x03); //叠加模式,非自动换行 //printf("N[%d]%s\n",t,F_Info[t].F_Name); } key=0; Pen_Point.Key_Sta=Key_Up;//释放显示期间的触发 while(1)//等待按键操作 { key=AI_Read_TP(50);//适合滑动检测 if(key) { if((Pen_Point.Key_Reg&0x03)==1)//第一次是滑动按下 { t=KEY_Move_Check();//检查滑动按下 if(t) { key=t; goto KEY_D; } } Pen_Point.Key_Reg|=0X80; //标记按键已经按下 } if(key==0&&(Pen_Point.Key_Reg&0X80))//按键松开了 { key=Touch_To_Num(1); KEY_D: Pen_Point.Key_Reg=0; if(key)//有按键按下 { switch(key) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: key-=1; if(sel!=key&&key<fcnt)//选中一个 { POINT_COLOR=DARKBLUE;//画笔颜色选择 LCD_Fill(32,45+sel*32,239,37+(sel+1)*32,WHITE);//清空上次选择的 Show_Str(32,50+sel*32,F_Info[sel].F_Name,16,0x03);//重新显示上次的名字 sel=key;//选择这次选择的 LCD_Fill(32,45+sel*32,239,37+(sel+1)*32,LBBLUE);//清空上次选择的 POINT_COLOR=WHITE;//画笔颜色选择 Show_Str(32,50+sel*32,F_Info[sel].F_Name,16,0x03);//显示名字 }else if(sel==key)return sel+1;//再次选择,双击打开. break; case 9: //选择了"选择"按钮 return sel+1; case 10://选择了"返回"按钮 return 9; case MOVE_UP: //翻页操作 case MOVE_LEFT: case MOVE_DOWN: case MOVE_RIGHT: return key; } key=0;//把按键值取消掉 Pen_Point.Key_Sta=Key_Up;//释放显示期间的触发 } } delay_ms(1); t++; if(t%500==0)LED0=!LED0; } }
/****************************************************************** 函数名: LCD_DrawFillRectangle 作者: Anti_CDQ 日期: 2017-09-10 功能: GUI画矩形(填充) 输入参数:(x1,y1),(x2,y2):矩形的对角坐标 返回值: 无 修改记录:无 ******************************************************************/ void LCD_DrawFillRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { LCD_Fill(x1,y1,x2,y2,POINT_COLOR); }
int main(void) { u32 fontcnt; u8 i,j; u8 fontx[2];//gbk码 u8 key,t; delay_init(); //延时函数初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级 uart_init(115200); //串口初始化为115200 usmart_dev.init(72); //初始化USMART LED_Init(); //初始化与LED连接的硬件接口 KEY_Init(); //初始化按键 LCD_Init(); //初始化LCD W25QXX_Init(); //初始化W25Q128 my_mem_init(SRAMIN); //初始化内部内存池 exfuns_init(); //为fatfs相关变量申请内存 f_mount(fs[0],"0:",1); //挂载SD卡 f_mount(fs[1],"1:",1); //挂载FLASH. while(font_init()) //检查字库 { LCD_Clear(WHITE); //清屏 POINT_COLOR=RED; //设置字体为红色 LCD_ShowString(30,50,200,16,16,"WarShip STM32"); while(SD_Init()) //检测SD卡 { LCD_ShowString(30,70,200,16,16,"SD Card Failed!"); delay_ms(200); LCD_Fill(30,70,200+30,70+16,WHITE); delay_ms(200); } LCD_ShowString(30,70,200,16,16,"SD Card OK"); LCD_ShowString(30,90,200,16,16,"Font Updating..."); key=update_font(20,110,16,"0:");//更新字库 while(key)//更新失败 { LCD_ShowString(30,110,200,16,16,"Font Update Failed!"); delay_ms(200); LCD_Fill(20,110,200+20,110+16,WHITE); delay_ms(200); } LCD_ShowString(30,110,200,16,16,"Font Update Success! "); delay_ms(1500); LCD_Clear(WHITE);//清屏 } POINT_COLOR = MAGENTA; Show_Str(20,20,200,24,"第十一届全国电子",24,0); Show_Str(80,50,200,24,"设计大赛",24,0); POINT_COLOR = BLUE; Show_Str(60,80,200,24,"武昌首义学院",24,0); Show_Str(30,130,200,24,"参赛题目课题:",24,0); Show_Str(45,160,200,24,"旋转倒立摆",24,0); Show_Str(30,210,200,24,"参赛者:李观称",24,0); Show_Str(45,240,200,24,"赖丽清,张建",24,0); while(1) { fontcnt=0; for(i=0x81; i<0xff; i++) { fontx[0]=i; // LCD_ShowNum(118,150,i,3,16); //显示内码高字节 for(j=0x40; j<0xfe; j++) { if(j==0x7f)continue; fontcnt++; // LCD_ShowNum(118,170,j,3,16); //显示内码低字节 // LCD_ShowNum(118,190,fontcnt,5,16);//汉字计数显示 // fontx[1]=j; // Show_Font(30+132,220,fontx,24,0); // Show_Font(30+144,244,fontx,16,0); // Show_Font(30+108,260,fontx,12,0); t=200; while(t--)//延时,同时扫描按键 { delay_ms(1); } LED0=!LED0; } } } }
/************************************************************************************** * Function Implementation **************************************************************************************/ void p_drUser_SystemInit(void) { // u8 key,mode; // u16 t=0; // u8 tmp_buf[33]; SystemInit(); delay_init(72); NVIC_Configuration(); p_dr_UartInit(9600); p_dr_LedInit(); //LCD_Init(); //p_dr_NRF24L01Init(); p_dr_KeyInit(); p_dr_MatrixKeyBoardInit(); //POINT_COLOR=RED; //LCD_ShowString(60,50,"Mini STM32"); //LCD_ShowString(60,70,"USART TEST"); //LCD_ShowString(60,90,"2016/4/24"); while(1) { p_dr_KeyScan(); p_dr_KeyDebug(); delay_ms(500); DR_LED_LED0 = !DR_LED_LED0; } #if 0 mode = 0; LCD_Fill(10,150,240,166,WHITE); POINT_COLOR=BLUE; if(mode==0) { LCD_ShowString(60,150,"NRF24L01 RX_Mode"); LCD_ShowString(60,170,"Received DATA:"); p_dr_NRF24L01RXMode(); while(1) { if(p_dr_NRF24L01TxPacket(tmp_buf)==0) { tmp_buf[32]=0; LCD_ShowString(0,190,tmp_buf); }else delay_us(100); t++; if(t==10000) { t=0; DR_LED_LED0=!DR_LED_LED0; } }; }else { LCD_ShowString(60,150,"NRF24L01 TX_Mode"); p_dr_NRF24L01TXMode(); mode=' '; while(1) { if(p_dr_NRF24L01TxPacket(tmp_buf)==TX_OK) { LCD_ShowString(60,170,"Sended DATA:"); LCD_ShowString(0,190,tmp_buf); key=mode; for(t=0;t<32;t++) { key++; if(key>('~'))key=' '; tmp_buf[t]=key; } mode++; if(mode>'~')mode=' '; tmp_buf[32]=0; }else { LCD_ShowString(60,170,"Send Failed "); LCD_Fill(0,188,240,218,WHITE); }; DR_LED_LED0=!DR_LED_LED0; delay_ms(1500); }; } #endif }
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; } } } }
int main(void) { u16 tcnt=0; u8 key; delay_init(); //延时函数初始化 NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级 uart_init(9600); //串口初始化为9600 LED_Init(); //LED端口初始化 LCD_Init(); KEY_Init(); //初始化按键 RTC_Init(); //初始化RTC //Adc_Init(); //初始化ADC POINT_COLOR=RED; //设置为红色 LCD_ShowString(60,30,200,16,16,"ENC28J60 TEST"); LCD_ShowString(60,70,200,16,16,"KEY_UP:Select"); LCD_ShowString(60,90,200,16,16,"KEY_DOWN:Confirm"); LCD_ShowString(60,110,200,16,16,"IP:192.168.1.16"); LCD_ShowString(60,130,200,16,16,"MASK:255.255.255.0"); LCD_ShowString(60,150,200,16,16,"GATEWAY:192.168.1.1"); LCD_ShowString(60,200,200,16,16,"RX:"); LCD_ShowString(60,220,200,16,16,"TX:"); #if LWIP_DHCP>0 //若使用DHCP协议 ipaddr.addr = 0; netmask.addr = 0; gw.addr = 0; #else // IP4_ADDR(&ipaddr, 192, 168, 2, 16); //设置本地ip地址 IP4_ADDR(&gw, 192, 168, 1, 1); //网关 IP4_ADDR(&netmask, 255, 255, 255, 0); //子网掩码 #endif init_lwip_timer(); //初始化LWIP定时器 //初始化LWIP协议栈,执行检查用户所有可配置的值,初始化所有的模块 lwip_init(); //添加网络接口 while((netif_add(&enc28j60_netif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, ðernet_input)==NULL)) { LCD_ShowString(60,170,200,16,16,"ENC28J60 Init Error!"); delay_ms(200); LCD_Fill(60,170,240,186,WHITE);//清除之前显示 delay_ms(200); } //注册默认的网络接口 netif_set_default(&enc28j60_netif); //建立网络接口用于处理通信 netif_set_up(&enc28j60_netif); /* Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at the predefined regular intervals after starting the client. You can peek in the netif->dhcp struct for the actual DHCP status. ip_addr_t offered_ip_addr; ip_addr_t offered_sn_mask; ip_addr_t offered_gw_addr; dhcp_ip = enc28j60_netif.dhcp->offered_ip_addr.addr; printf("IP地址:%ld,%ld,%ld,%ld\t\n",(dhcp_ip&0x000000ff),(dhcp_ip&0x0000ff00)>>8,(dhcp_ip&0x00ff0000)>>16,(dhcp_ip&0xff000000)>>24); */ #if LWIP_DHCP>0 //若使用DHCP协议 dhcp_start(&enc28j60_netif); //为网卡创建一个新的DHCP客户端 #endif select_lwip_mode(); //选择需要进行的实验 lwip_demo_init(); //初始化lwip_demo while (1) { LWIP_Polling(); //LWIP查询 key=KEY_Scan(); if(key==KEY_DOWN){ //发送数据 if((lwip_flag&LWIP_CONNECTED)==LWIP_CONNECTED){ //连接上了才可以发送数据 主要针对TCP来说 UDP就不需要连接了 tcnt++; sprintf((char*)lwip_demo_buf,"This is a test %d\r\n",tcnt); LCD_Fill(86,220,240,236,WHITE); //清除之前显示 LCD_ShowString(86,220,154,16,16,lwip_demo_buf);//显示当前发送数据 lwip_flag |= LWIP_SEND_DATA; //标记有数据需要发送 }else if(lwip_test_mode == LWIP_TCP_CLIENT){ //没有连接上,此时处于TCP客户端模式,则尝试重新连接 tcp_client_connect_remotehost(); }else if(lwip_test_mode == LWIP_UDP_SERVER){ tcnt++; sprintf((char*)lwip_demo_buf,"This is a test %d\r\n",tcnt); LCD_Fill(86,220,240,236,WHITE); //清除之前显示 LCD_ShowString(86,220,154,16,16,lwip_demo_buf);//显示当前发送数据 lwip_flag |= LWIP_SEND_DATA; //标记有数据需要发送 udp_server_send_data(); }else if(lwip_test_mode == LWIP_UDP_CLIENT){ tcnt++; sprintf((char*)lwip_demo_buf,"This is a test %d\r\n",tcnt); LCD_Fill(86,220,240,236,WHITE); //清除之前显示 LCD_ShowString(86,220,154,16,16,lwip_demo_buf);//显示当前发送数据 lwip_flag |= LWIP_SEND_DATA; //标记有数据需要发送 udp_client_send_data(); } } if((lwip_flag&LWIP_NEW_DATA)==LWIP_NEW_DATA){ LCD_Fill(86,200,240,216,WHITE); //清除之前显示 LCD_ShowString(86,200,154,16,16,lwip_demo_buf); printf("LWIP RX:%s\r\n",lwip_demo_buf);//打印数据 lwip_flag &=~LWIP_NEW_DATA; //清除接受数据的标志 } delay_ms(1); } }
int main(void) { u8 res; DIR picdir; //图片目录 FILINFO picfileinfo;//文件信息 u8 *fn; //长文件名 u8 *pname; //带路径的文件名 u16 totpicnum; //图片文件总数 u16 curindex; //图片当前索引 u8 key; //键值 u8 pause=0; //暂停标记 u8 t; u16 temp; u16 *picindextbl; //图片索引表 delay_init(); //延时函数初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2 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. POINT_COLOR=RED; while(font_init()) //检查字库 { LCD_ShowString(60,50,200,16,16,"Font Error!"); delay_ms(200); LCD_Fill(60,50,240,66,WHITE);//清除显示 delay_ms(200); } Show_Str(60,50,200,16,"Mini STM32开发板",16,0); Show_Str(60,70,200,16,"图片显示程序",16,0); Show_Str(60,90,200,16,"KEY0:NEXT KEY1:PREV",16,0); Show_Str(60,110,200,16,"WK_UP:PAUSE",16,0); Show_Str(60,130,200,16,"正点原子@ALIENTEK",16,0); Show_Str(60,150,200,16,"2014年3月14日",16,0); while(f_opendir(&picdir,"0:/PICTURE"))//打开图片文件夹 { Show_Str(60,170,240,16,"PICTURE文件夹错误!",16,0); delay_ms(200); LCD_Fill(60,170,240,186,WHITE);//清除显示 delay_ms(200); } totpicnum=pic_get_tnum("0:/PICTURE"); //得到总有效文件数 while(totpicnum==NULL)//图片文件为0 { Show_Str(60,170,240,16,"没有图片文件!",16,0); delay_ms(200); LCD_Fill(60,170,240,186,WHITE);//清除显示 delay_ms(200); } picfileinfo.lfsize=_MAX_LFN*2+1; //长文件名最大长度 picfileinfo.lfname=mymalloc(picfileinfo.lfsize); //为长文件缓存区分配内存 pname=mymalloc(picfileinfo.lfsize); //为带路径的文件名分配内存 picindextbl=mymalloc(2*totpicnum); //申请2*totpicnum个字节的内存,用于存放图片索引 while(picfileinfo.lfname==NULL||pname==NULL||picindextbl==NULL)//内存分配出错 { Show_Str(60,170,240,16,"内存分配失败!",16,0); delay_ms(200); LCD_Fill(60,170,240,186,WHITE);//清除显示 delay_ms(200); } //记录索引 res=f_opendir(&picdir,"0:/PICTURE"); //打开目录 if(res==FR_OK) { curindex=0;//当前索引为0 while(1)//全部查询一遍 { temp=picdir.index; //记录当前index res=f_readdir(&picdir,&picfileinfo); //读取目录下的一个文件 if(res!=FR_OK||picfileinfo.fname[0]==0)break; //错误了/到末尾了,退出 fn=(u8*)(*picfileinfo.lfname?picfileinfo.lfname:picfileinfo.fname); res=f_typetell(fn); if((res&0XF0)==0X50)//取高四位,看看是不是图片文件 { picindextbl[curindex]=temp;//记录索引 curindex++; } } } Show_Str(60,170,240,16,"开始显示...",16,0); delay_ms(1500); piclib_init(); //初始化画图 curindex=0; //从0开始显示 res=f_opendir(&picdir,(const TCHAR*)"0:/PICTURE"); //打开目录 while(res==FR_OK)//打开成功 { dir_sdi(&picdir,picindextbl[curindex]); //改变当前目录索引 res=f_readdir(&picdir,&picfileinfo); //读取目录下的一个文件 if(res!=FR_OK||picfileinfo.fname[0]==0)break; //错误了/到末尾了,退出 fn=(u8*)(*picfileinfo.lfname?picfileinfo.lfname:picfileinfo.fname); strcpy((char*)pname,"0:/PICTURE/"); //复制路径(目录) strcat((char*)pname,(const char*)fn); //将文件名接在后面 LCD_Clear(BLACK); ai_load_picfile(pname,0,0,lcddev.width,lcddev.height,1);//显示图片 Show_Str(2,2,240,16,pname,16,1); //显示图片名字 t=0; while(1) { key=KEY_Scan(0); //扫描按键 if(t>250)key=1; //模拟一次按下KEY0 if((t%20)==0)LED0=!LED0;//LED0闪烁,提示程序正在运行. if(key==KEY1_PRES) //上一张 { if(curindex)curindex--; else curindex=totpicnum-1; break; }else if(key==KEY0_PRES)//下一张 { curindex++; if(curindex>=totpicnum)curindex=0;//到末尾的时候,自动从头开始 break; }else if(key==WKUP_PRES) { pause=!pause; LED1=!pause; //暂停的时候LED1亮. } if(pause==0)t++; delay_ms(10); } res=0; } myfree(picfileinfo.lfname); //释放内存 myfree(pname); //释放内存 myfree(picindextbl); //释放内存 }
/*玩游戏具体过程*/ void GamePlay(void) { srand();/*随机数发生器*/ food.yes=0;/*1表示需要出现新食物,0表示已经存在食物*/ snake.life=0;/*活着*/ snake.direction=1;/*方向往右*/ snake.x[0]=50;snake.y[0]=50;/*蛇头*/ snake.x[1]=60;snake.y[1]=50; snake.node=2;/*节数*/ food.x=150; food.y=150; PrScore();/*输出得分*/ key=255; while(1)/*在没有按键的情况下,蛇自己移动身体*/ { if(food.yes==1)/*需要出现新食物*/ { food.x=rand()%200+40; food.y=rand()%175+30; while(food.x%10!=0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/ food.x++; while(food.y%10!=0) food.y++; food.yes=0;/*画面上有食物了*/ } if(food.yes==0)/*画面上有食物了就要显示*/ { //setcolor(GREEN); LCD_Fill(food.x,food.y-9,food.x+9,food.y,LCD_COLOR_GREEN); } for(i=snake.node-1;i>0;i--)/*蛇的每个环节往前移动,也就是贪吃蛇的关键算法*/ { snake.x[i]=snake.x[i-1]; snake.y[i]=snake.y[i-1]; } /*1,2,3,4表示右,左,上,下四个方向,通过这个判断来移动蛇头*/ switch(snake.direction) { case 1:snake.x[0]+=10;break; case 2:snake.x[0]-=10;break; case 3:snake.y[0]-=10;break; case 4:snake.y[0]+=10;break; } for(i=3;i<snake.node;i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节,第三节不可能拐过来*/ { if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0]) { GameOver();/*显示失败*/ snake.life=1; break; } } if(snake.x[0]<20||snake.x[0]>290||snake.y[0]<40|| snake.y[0]>227)/*蛇是否撞到墙壁*/ { GameOver();/*本次游戏结束*/ snake.life=1; /*蛇死*/ break; } if(snake.life==1)/*以上两种判断以后,如果蛇死就跳出内循环,重新开始*/ break; if(snake.x[0]==food.x&&snake.y[0]==food.y)/*吃到食物以后*/ { //setcolor(0);/*把画面上的食物东西去掉*/ LCD_Fill(food.x,food.y-9,food.x+9,food.y,0); snake.x[snake.node]=-5;snake.y[snake.node]=-5; /*新的一节先放在看不见的位置,下次循环就取前一节的位置*/ snake.node++;/*蛇的身体长一节*/ food.yes=1;/*画面上需要出现新的食物*/ score+=10; PrScore();/*输出新得分*/ } //setcolor(4);/*画出蛇*/ for(i=0;i<snake.node;i++) LCD_Fill(snake.x[i],snake.y[i]-9,snake.x[i]+9, snake.y[i],LCD_COLOR_RED); Delay(gamespeed); //setcolor(0);/*用黑色去除蛇的的最后一节*/ LCD_Fill(snake.x[snake.node-1],snake.y[snake.node-1]-9, snake.x[snake.node-1]+9,snake.y[snake.node-1],0); key=LastKey;/*接收按键*/ if (key!=255) LCD_DispNum(0,0,key,3,0xffff); if(key==ESC)/*按ESC键退出*/ break; else if((key==UP)&&(snake.direction!=4)) /*判断是否往相反的方向移动*/ snake.direction=3; else if((key==RIGHT)&&(snake.direction!=2)) snake.direction=1; else if((key==LEFT)&&(snake.direction!=1)) snake.direction=2; else if((key==DOWN)&&(snake.direction!=3)) snake.direction=4; LastKey=255; key=255; } /*endwhile(!kbhit)*/ }