MSP430的SD卡程序,谁能给我一份,本人自己写了几次老是读出来的数据有误,
unsignedcharDATA[512];//===========================================================//...
unsigned char DATA[512];
//===========================================================
//写一字节到SD卡,模拟SPI总线方式
void SdWrite(unsigned char n)
{
P5DIR = 0XFB;
unsigned char i;
for(i=8;i;i--)
{
SD_CLK_H;
SD_CLK_L;
if(n&0x80)
SD_DI_H;
else
SD_DI_L;
n<<=1;
}
SD_DI_H;
}
//===================================================================
//从SD卡读一字节,模拟SPI总线方式
unsigned char SdRead()
{
P5DIR = 0XFB;
unsigned char b=0,i;
for(i=8;i;i--)
{
b<<=1;
SD_CLK_L;
SD_CLK_H;
if(SD_DO_H)
b|=0x01;
}
return b;
}
//============================================================
//检测SD卡的响应
unsigned char SdResponse()
{
unsigned char i=0,response;
while(i<=8)
{
response = SdRead();
if(response==0x00)
break;
if(response==0x01)
break;
i++;
}
return response;
}
//================================================================
//发命令到SD卡
void SdCommand(unsigned char command, unsigned long argument, unsigned char CRC)
{
SdWrite(command|0x40);
SdWrite(((unsigned char *)&argument)[0]);
SdWrite(((unsigned char *)&argument)[1]);
SdWrite(((unsigned char *)&argument)[2]);
SdWrite(((unsigned char *)&argument)[3]);
SdWrite(CRC);
}
//================================================================
//初始化SD卡
unsigned char SdInit(void)
{
//int delay=0, trials=0;
unsigned char i;
unsigned char response=0x01;
SD_CS_H;
for(i=0;i<=9;i++)
SdWrite(0xff);
SD_CS_L;
//Send Command 0 to put MMC in SPI mode
SdCommand(0x00,0,0x95);
response=SdResponse();
if(response!=0x01)
{
return 0;
}
while(response==0x01)
{
SD_CS_H;
SdWrite(0xff);
SD_CS_L;
SdCommand(0x01,0x00ffc000,0xff);
response=SdResponse();
}
SD_CS_H;
SdWrite(0xff);
return 1;
}
如果有请发到我邮箱,598646744@qq.com 展开
//===========================================================
//写一字节到SD卡,模拟SPI总线方式
void SdWrite(unsigned char n)
{
P5DIR = 0XFB;
unsigned char i;
for(i=8;i;i--)
{
SD_CLK_H;
SD_CLK_L;
if(n&0x80)
SD_DI_H;
else
SD_DI_L;
n<<=1;
}
SD_DI_H;
}
//===================================================================
//从SD卡读一字节,模拟SPI总线方式
unsigned char SdRead()
{
P5DIR = 0XFB;
unsigned char b=0,i;
for(i=8;i;i--)
{
b<<=1;
SD_CLK_L;
SD_CLK_H;
if(SD_DO_H)
b|=0x01;
}
return b;
}
//============================================================
//检测SD卡的响应
unsigned char SdResponse()
{
unsigned char i=0,response;
while(i<=8)
{
response = SdRead();
if(response==0x00)
break;
if(response==0x01)
break;
i++;
}
return response;
}
//================================================================
//发命令到SD卡
void SdCommand(unsigned char command, unsigned long argument, unsigned char CRC)
{
SdWrite(command|0x40);
SdWrite(((unsigned char *)&argument)[0]);
SdWrite(((unsigned char *)&argument)[1]);
SdWrite(((unsigned char *)&argument)[2]);
SdWrite(((unsigned char *)&argument)[3]);
SdWrite(CRC);
}
//================================================================
//初始化SD卡
unsigned char SdInit(void)
{
//int delay=0, trials=0;
unsigned char i;
unsigned char response=0x01;
SD_CS_H;
for(i=0;i<=9;i++)
SdWrite(0xff);
SD_CS_L;
//Send Command 0 to put MMC in SPI mode
SdCommand(0x00,0,0x95);
response=SdResponse();
if(response!=0x01)
{
return 0;
}
while(response==0x01)
{
SD_CS_H;
SdWrite(0xff);
SD_CS_L;
SdCommand(0x01,0x00ffc000,0xff);
response=SdResponse();
}
SD_CS_H;
SdWrite(0xff);
return 1;
}
如果有请发到我邮箱,598646744@qq.com 展开
若以下回答无法解决问题,邀请你更新回答
3个回答
展开全部
8051单片机还用C#来编写啊,用C就可以了,8051读SD卡是用SPI方式读的,你去看看SD卡这方面的读写方式吧
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是温度控制还是检测?我前几天做了个温度检测的,凑合能用。要的话明天给你。程序现在不在我这儿
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询