完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
emWin里按下按钮,先关闭中断,对SD操作,返回以后,emWin就触发HardFault_Handler ///////////////////////////////////////////////////////////////////////////////////////////////////////////// [C] 纯文本查看 复制代码 case ID_BUTTON_4505: // Notifications sent by 'Button' switch(NCode) { case WM_NOTIFICATION_CLICKED: break; case WM_NOTIFICATION_RELEASED: hItem = WM_GetDialogItem(hWin, ID_TEXT_4502); TEXT_SetText(hItem,"Saving Result to SD!");GUI_Delay(200); __disable_irq(); if(check_SD()==0){if(write_result_to_SD()==0){hItem = WM_GetDialogItem(hWin, ID_TEXT_4502);TEXT_SetText(hItem,"Save successfully!");}else{TEXT_SetText(hItem,"Test result writes error!");}}else{TEXT_SetText(hItem,"SD Error");}__enable_irq();GUI_Delay(500); break; 下面上面调用的两个函数。 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// [C] 纯文本查看 复制代码 int check_SD(void){ u32 total,free; u8 i; int flag=0; i=5; while(i) //检测SD卡 { if(SD_Initialize()) { delay_ms(100); i--; flag=1; } else i=0; } if(flag!=0) return flag; exfuns_init(); //为fatfs相关变量申请内存 f_mount(fs[0],"0:",1); //挂载SD卡 //f_mount(fs[1],"1:",1); //挂载FLASH. i=5; while(i) //得到SD卡的总容量和剩余容量 { if(exf_getfree("0",&total,&free)) { delay_ms(200); i--; flag=2; } else i=0; } if(flag!=0) {LED_B=1;LED_R=0;return flag; } else { LCD_ShowString(30,180,200,16,16,"SD Test Ok. Free Size: MB"); LCD_ShowNum(220,180,free>>10,5,16); //显示SD卡剩余容量 MB delay_ms(200); f_mount(NULL, "", 0); return flag; } }/////////////////////////////////////////////////////////////////////////////////////////////////////////////int write_result_to_SD(void){ int flag=0; uint8_t res; u8 i,k; FATFS fs; uint32_t index = 0x00; uint32_t reindex = 0x00; char buf[2000] = " "; uint8_t str[15]; char name[50] = "TestData_"; pht_read_test_result(); delay_ms(1000); RTC_get_date(str,0); for(i=0;i<10;i++) name[9+i]=str; name[19]='_'; RTC_get_time(str,1); for(i=0;i<6;i++) name[20+i]=str; name[26]='.'; name[27]='t'; name[28]='x'; name[29]='t'; name[30]=' |