最近在学习原子老大的SD卡实验
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "key.h"
#include "malloc.h"
#include "MMC_SD.h"
void SD_Read_Sectorx(u32 sec)
{
u8 *buf;
u16 i;
buf=mymalloc(512); //éêÇëÄú′æ
if(SD_ReadDisk(buf,sec,1)==0) //¶áè¡0éèÇøμÄÄúèY
{
LCD_ShowString(60,190,200,16,16,"USART1 Sending Data...");
printf("SECTOR 0 DATA:
");
for(i=0;i<512;i++)printf("%x ",buf
);//′òó¡secéèÇøêy¾Y
printf("
DATA ENDED
");
LCD_ShowString(60,190,200,16,16,"USART1 Send Data Over!");
}
myfree(buf);//êí·ÅÄú′æ
}
//ALIENTEK Mini STM32¿a·¢°å·¶ày′úÂë11
//TFTLCDÏÔê¾êμÑé
//¼¼êõÖ§3Ö£owww.openedv.com
//1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾
int main(void)
{
u8 key;
u32 sd_size;
u8 t=0;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// éèÖÃÖD¶ÏóÅÏ輶·Ö×é2
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
uart_init(9600); //′®¿ú3õê¼»ˉÎa9600
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
LCD_Init(); //3õê¼»ˉLCD
KEY_Init(); //°′¼ü3õê¼»ˉ
mem_init(); //3õê¼»ˉÄú′æ3Ø
POINT_COLOR=RED;//éèÖÃ×ÖìåÎaoìé«
LCD_ShowString(60,50,200,16,16,"Mini STM32");
LCD_ShowString(60,70,200,16,16,"SD CARD TEST");
LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(60,110,200,16,16,"2014/3/13");
LCD_ShowString(60,130,200,16,16,"KEY0:Read Sector 0");
while(SD_Initialize())//¼ì2a2»μ½SD¿¨
{
LCD_ShowString(60,150,200,16,16,"SD Card Error!");
delay_ms(500);
LCD_ShowString(60,150,200,16,16,"Please Check! ");
delay_ms(500);
LED0=!LED0;//DS0éá˸
}
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
//¼ì2aSD¿¨3é1|
LCD_ShowString(60,150,200,16,16,"SD Card OK ");
LCD_ShowString(60,170,200,16,16,"SD Card Size: MB");
sd_size=SD_GetSectorCount();//μÃμ½éèÇøêy
LCD_ShowNum(164,170,sd_size>>11,5,16);//ÏÔê¾SD¿¨èYá¿
while(1)
{
key=KEY_Scan(0);
if(key==KEY0_PRES)SD_Read_Sectorx(0);//KEY0°′,¶áè¡SD¿¨éèÇø0μÄÄúèY
t++;
delay_ms(10);
if(t==20)
{
LED0=!LED0;
t=0;
}
}
}
但是如图片中红 {MOD}矩形框内判断是否能检测到SD卡的while()语句,如果测试的时候不插SD卡,软件没有检测到SD卡,就会形成死循环,程序一直在while中打转转,有没有一个好的办法,就是检测不到SD卡,程序还能往下走。
一周热门 更多>