解决了因为汉字在两个数据块直接导致的数据流乱码,
下个版本打算两字节两个字节的读取,这样就就不怕数据块中 换行太多导致显示不下。 Signed-off-by: 无闻风 <53944749+wuwenfengmi1998@users.noreply.github.com>
This commit is contained in:
+51
-5
@@ -9,15 +9,24 @@
|
||||
#include "text.h"
|
||||
#include "fatfs.h"
|
||||
#include "fatfs_sd.h"
|
||||
|
||||
#define KEY_UP HAL_GPIO_ReadPin(KEY_UP_GPIO_Port,KEY_UP_Pin)
|
||||
#define KEY_B HAL_GPIO_ReadPin(KEY_B_GPIO_Port,KEY_B_Pin)
|
||||
#define KEY_DOWN HAL_GPIO_ReadPin(KEY_DOWN_GPIO_Port,KEY_DOWN_Pin)
|
||||
|
||||
FATFS SD;
|
||||
|
||||
#define fuck 256
|
||||
|
||||
int my_main()
|
||||
{
|
||||
uint8_t res;
|
||||
FIL fil;
|
||||
char fil_buff[128];
|
||||
uint16_t br=128;
|
||||
char str[16];
|
||||
char fil_buff[fuck+1]={0};
|
||||
char fuck_flag=0;
|
||||
char fuck_buff;
|
||||
uint16_t br=0;
|
||||
char str[fuck+1]={0};
|
||||
LCD_BL(0);
|
||||
LCDx_Init();
|
||||
LCD_Clear(GRAY);
|
||||
@@ -29,8 +38,7 @@ int my_main()
|
||||
|
||||
f_mount(&SD,"0:",1);
|
||||
res=f_open(&fil,"0:/demo.txt",FA_READ);
|
||||
res=f_read(&fil,fil_buff,64,(UINT*)&br);
|
||||
LCD_ShowString(0,0,fil_buff,16,RED,BLUE,64);
|
||||
|
||||
|
||||
/*
|
||||
sprintf(str,"%02x\n%02x\n%02x\n%02x\n%02x",ftinfo.fontok,ftinfo.ugbkaddr,ftinfo.ugbksize,ftinfo.f12addr,ftinfo.gbk12size);
|
||||
@@ -40,6 +48,44 @@ int my_main()
|
||||
*/
|
||||
while(1)
|
||||
{
|
||||
if(KEY_UP==0)
|
||||
{
|
||||
HAL_Delay(10);
|
||||
while(KEY_UP==0);
|
||||
LCD_Clear(WHITE);
|
||||
for(int a=0;a<fuck+1;a++)
|
||||
{
|
||||
fil_buff[a]=0;
|
||||
str[a]=0;
|
||||
}
|
||||
|
||||
if(fuck_flag==1)
|
||||
{
|
||||
fuck_flag=0;
|
||||
res=f_read(&fil,fil_buff,fuck-1,(UINT*)&br);
|
||||
for(int a=fuck-2;a>0;a--)
|
||||
{
|
||||
fil_buff[a+1]=fil_buff[a];
|
||||
}
|
||||
fil_buff[0]=fuck_buff;
|
||||
|
||||
}else
|
||||
{
|
||||
res=f_read(&fil,fil_buff,fuck,(UINT*)&br);
|
||||
}
|
||||
|
||||
if((fil_buff[fuck-1]>127)&&(fil_buff[fuck-2]<128))
|
||||
{
|
||||
fuck_buff=fil_buff[fuck-1];
|
||||
fil_buff[fuck-1]='\0';
|
||||
fuck_flag=1;
|
||||
|
||||
}
|
||||
|
||||
sprintf(str,"%s\0",fil_buff);
|
||||
LCD_ShowString(0,0,str,16,WHITE,BLACK,fuck);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+15
-10
@@ -24,15 +24,19 @@ static uint8_t PowerFlag = 0;
|
||||
#define SD_CS_GPIO_Port GPIOD
|
||||
#define SD_CS_Pin GPIO_PIN_2
|
||||
|
||||
volatile uint8_t Timer1, Timer2;
|
||||
volatile uint32_t Timer1, Timer2;
|
||||
|
||||
void SDTimer_Handler(void)
|
||||
{
|
||||
if(Timer1 > 0)
|
||||
Timer1--;
|
||||
|
||||
{
|
||||
Timer1--;
|
||||
}
|
||||
if(Timer2 > 0)
|
||||
Timer2--;
|
||||
{
|
||||
Timer2--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* SPI Chip Select */
|
||||
@@ -79,13 +83,14 @@ static uint8_t SD_ReadyWait(void)
|
||||
uint8_t res;
|
||||
|
||||
|
||||
Timer2 = 50;
|
||||
Timer2 = 50000;
|
||||
SPI_RxByte();
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
res = SPI_RxByte();
|
||||
Timer2--;
|
||||
} while ((res != 0xFF) && Timer2);
|
||||
|
||||
return res;
|
||||
@@ -152,13 +157,11 @@ static bool SD_RxDataBlock(BYTE *buff, UINT btr)
|
||||
{
|
||||
uint8_t token;
|
||||
|
||||
|
||||
Timer1 = 10;
|
||||
|
||||
|
||||
Timer1 = 10000;
|
||||
do
|
||||
{
|
||||
token = SPI_RxByte();
|
||||
Timer1--;
|
||||
} while((token == 0xFF) && Timer1);
|
||||
|
||||
|
||||
@@ -297,7 +300,7 @@ DSTATUS SD_disk_initialize(BYTE drv)
|
||||
if (SD_SendCmd(CMD0, 0) == 1)
|
||||
{
|
||||
|
||||
Timer1 = 100;
|
||||
Timer1 = 100000;
|
||||
|
||||
|
||||
if (SD_SendCmd(CMD8, 0x1AA) == 1)
|
||||
@@ -314,6 +317,7 @@ DSTATUS SD_disk_initialize(BYTE drv)
|
||||
do {
|
||||
if (SD_SendCmd(CMD55, 0) <= 1 && SD_SendCmd(CMD41, 1UL << 30) == 0)
|
||||
break; /* ACMD41 with HCS bit */
|
||||
Timer1--;
|
||||
} while (Timer1);
|
||||
|
||||
if (Timer1 && SD_SendCmd(CMD58, 0) == 0)
|
||||
@@ -344,6 +348,7 @@ DSTATUS SD_disk_initialize(BYTE drv)
|
||||
if (SD_SendCmd(CMD1, 0) == 0)
|
||||
break; /* CMD1 */
|
||||
}
|
||||
Timer1--;
|
||||
} while (Timer1);
|
||||
|
||||
if (!Timer1 || SD_SendCmd(CMD16, 512) != 0)
|
||||
|
||||
+11
-5
@@ -361,6 +361,10 @@ void LCD_ShowString(uint16_t x,uint16_t y,uint8_t *p,uint8_t size,uint16_t bg,ui
|
||||
if(*p=='\r')
|
||||
{
|
||||
p++;
|
||||
if(*p!='\n')
|
||||
{
|
||||
return ;
|
||||
}
|
||||
}
|
||||
if(*p=='\n')
|
||||
{
|
||||
@@ -368,15 +372,17 @@ void LCD_ShowString(uint16_t x,uint16_t y,uint8_t *p,uint8_t size,uint16_t bg,ui
|
||||
y+=size;
|
||||
p++;
|
||||
}
|
||||
if(*p<127)
|
||||
{
|
||||
LCD_ShowChar(x,y,*p,size,bg,color);
|
||||
x+=(size/2);
|
||||
}else
|
||||
if(*p>127)
|
||||
{
|
||||
|
||||
|
||||
Show_Font(x,y,p,size,bg,color);
|
||||
p++;
|
||||
x+=size;
|
||||
}else
|
||||
{
|
||||
LCD_ShowChar(x,y,*p,size,bg,color);
|
||||
x+=(size/2);
|
||||
}
|
||||
p++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user