在线时间289 小时
UID198020
ST金币0
蝴蝶豆32
注册时间2007-7-22
金牌会员
- 最后登录
- 2020-11-10
|
a0a.1 0b0c
sd卡读出数据后,如何送入ILI9325的屏进行显示 | 请教高手:我现在可以从SD卡中读出数据(抄袭的),但是从SD中读出一个字符他也会认为是一个字节的数据,请问这个要怎么改啊?不知道是不是这个读出一个字节的函数有问题还是???望高人指点!!
我的QQ:519212866
unsigned char bdata _dat;
sbit _dat7 = _dat^7;
sbit _dat6 = _dat^6;
sbit _dat5 = _dat^5;
sbit _dat4 = _dat^4;
sbit _dat3 = _dat^3;
sbit _dat2 = _dat^2;
sbit _dat1 = _dat^1;
sbit _dat0 = _dat^0;
unsigned char SD_spi_read() //SPI读一个字节
{
SD_SO=1;
SD_SCL=1;
SD_SCL=0;
_dat7=SD_SO;
SD_SCL=1;
SD_SCL=0;
_dat6=SD_SO;
SD_SCL=1;
SD_SCL=0;
_dat5=SD_SO;
SD_SCL=1;
SD_SCL=0;
_dat4=SD_SO;
SD_SCL=1;
SD_SCL=0;
_dat3=SD_SO;
SD_SCL=1;
SD_SCL=0;
_dat2=SD_SO;
SD_SCL=1;
SD_SCL=0;
_dat1=SD_SO;
SD_SCL=1;
SD_SCL=0;
_dat0=SD_SO;
return (_dat);
}
unsigned char SD_Read_Sector(unsigned long addr,unsigned char *buffer)//从SD卡的指定扇区中读出512个字节,使用CMD17(17号命令)
{
unsigned int j;
unsigned char time,temp;
unsigned char pcmd[]={0x51,0x00,0x00,0x00,0x00,0xff}; //CMD17的字节序列
addr16)>>8); //12T 0.13835ms
pcmd[2] = (unsigned char)((unsigned int)(addr>>16)); //10T 0.00271ms
pcmd[3] = (unsigned char)(((unsigned int)addr)>>8); //7T 0.0038ms
//pcmd[4] = (unsigned char)((unsigned int)addr); //5T 0.00271ms
SD_CS=0;//打开片选
time=0;
do
{
temp=SD_Write_Cmd(pcmd); //写入CMD17
time++;
if(time==TRY_TIME)
{
return(READ_BLOCK_ERROR); //读块失败
}
}while(temp!=0);
while (SD_spi_read()!= 0xfe); //一直读,当读到0xfe时,说明后面的是512字节的数据了
for(j=0;jpfi->FileSize) len=pfi->FileSize-offset;
znFAT_Seek_File(pfi,offset);
znFAT_ReadSector(pfi->FileCurSector,znFAT_Buffer);
for(i=pfi->FileCurPos;iBytesPerSector;i++)
{
if(counter>=len)
{
return len;
}
(*pfun)(znFAT_Buffer);
counter++;
pfi->FileCurPos++;
pfi->FileCurOffset++;
}
if(pfi->FileCurSector-(SOC(pfi->FileCurCluster))!=(pArg->SectorsPerClust-1))
{
for(j=pfi->FileCurSector+1;jFileCurCluster))+pArg->SectorsPerClust;j++)
{
znFAT_ReadSector(j,znFAT_Buffer);
pfi->FileCurSector=j;
for(i=0;iBytesPerSector;i++)
{
if(counter>=len)
{
return len;
}
(*pfun)(znFAT_Buffer);
counter++;
pfi->FileCurPos++;
pfi->FileCurOffset++;
}
}
}
temp=(len-counter)/(pArg->BytesPerSector*pArg->SectorsPerClust);
for(k=0;kFileCurCluster=znFAT_GetNextCluster(pfi->FileCurCluster);
for(j=(SOC(pfi->FileCurCluster));jFileCurCluster))+pArg->SectorsPerClust;j++)
{
znFAT_ReadSector(j,znFAT_Buffer);
pfi->FileCurSector=j;
for(i=0;iBytesPerSector;i++)
{
if(counter>=len)
{
return len;
}
(*pfun)(znFAT_Buffer);
counter++;
pfi->FileCurOffset++;
pfi->FileCurPos++;
pfi->FileCurPos%=pArg->BytesPerSector;
}
}
}
pfi->FileCurCluster=znFAT_GetNextCluster(pfi->FileCurCluster);
temp=(SOC(pfi->FileCurCluster))+((len-counter)/pArg->BytesPerSector);
pfi->FileCurSector=(SOC(pfi->FileCurCluster));
for(j=(SOC(pfi->FileCurCluster));jFileCurSector=j;
for(i=0;iBytesPerSector;i++)
{
if(counter>=len)
{
return len;
}
(*pfun)(znFAT_Buffer);
counter++;
pfi->FileCurPos++;
pfi->FileCurPos%=pArg->BytesPerSector;
pfi->FileCurOffset++;
}
}
pfi->FileCurSector=j;
znFAT_ReadSector(pfi->FileCurSector,znFAT_Buffer);
temp=len-counter;
for(i=0;i=len)
{
return len;
}
(*pfun)(znFAT_Buffer);
counter++;
pfi->FileCurPos++;
pfi->FileCurPos%=pArg->BytesPerSector;
pfi->FileCurOffset++;
}
}
else
{
len=0;
}
return len;
}
| |
|