我用串口向spi flash 里面写入了汉字字库,但是我不知道有没有写入成功,取出来的字是乱码的?怎么检查有没有写入成功啊?
#include "stm32f10x_conf.h"
#include "bsp_ili9341_lcd.h"
#include "bsp_led.h"
//#include "tupian.h"
#include "spi_flash.h"
#include "bsp_usart1.h"
#include "stdio.h"
void Delay(uint32_t N)
{
int i;
for(i=0;i<N;i--);
}
//???¨?ò???? usart1
int fputc(int ch, FILE *f)
{
/* ?????????USART1 */
USART_SendData(USART1, (uint8_t) ch);
/* ?????? */
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_ClearFlag( USART1, USART_FLAG_TXE);
return (ch);
}
///???c???scanf?USART1
int fgetc(FILE *f)
{
/* ????1???? */
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
USART_ClearFlag(USART1,USART_FLAG_RXNE);
return (int)USART_ReceiveData(USART1);
}
void GetGBKCode(unsigned char* pBuffer,unsigned char * c)
{
unsigned char High8bit,Low8bit;
High8bit=*c; /* ????8?????? */
Low8bit=*(c+1); /* ????8?????? */
SPI_FLASH_PageWrite(pBuffer,(94*(High8bit-0xa0-1)+(Low8bit-0xa0-1))*32,32);
// SPI_FLASH_BufferWrite(pBuffer,((High8bit-0xb0)*94+Low8bit-0xa1)*64,64);
printf("
??W25x16 SPI FLASH????????????: %s",pBuffer);
}
void PutChinese(uint16_t Xpos,uint16_t Ypos,uint8_t *str,uint16_t Color,uint16_t bkColor)
{
uint8_t i=0,j=0;
uint8_t buffer[32];
GetGBKCode(buffer,str); /* ??×??????? */
for (i=0;i<16;i++)
{
for(j=0;j<8;j++)
{
if ( (buffer[i*2] >> 7-j) & 0x01 == 0x01)
{
LCD_SetPoint(Xpos+i,Ypos+j,Color); /* ×?·????? */
}
else
{
LCD_SetPoint(Xpos+i,Ypos+j,bkColor); /* ±??°???? */
}
if ( (buffer[i*2+1] >> 7-j) & 0x01 == 0x01)
{
LCD_SetPoint(Xpos+i,Ypos+j+8,Color); /* ×?·????? */
}
else
{
LCD_SetPoint(Xpos+i,Ypos+j+8,bkColor); /* ±??°???? */
}
}
}
}
void GUI_Chinese(uint16_t Xpos, uint16_t Ypos, uint8_t *str,uint16_t Color, uint16_t bkColor)
{
do
{
PutChinese(Xpos,Ypos,str++,Color,bkColor);
str++;
if (Ypos<304)
{
Ypos+=16;
}
else if (Xpos<224)
{
Ypos=0;
Xpos+=16;
}
else
{
Xpos=0;
Ypos=0;
}
}
while(*str!=0);
}
int main()
{
// int i,num;
LCD_Init();
Lcd_GramScan(1);
LED_GPIO_Config();
LCD_Clear(0,0,240,320,BLUE);
USART1_Config();
NVIC_Config();
SPI_GPIO_Config();
// SPI_flash_Sectorall();
LED1_ON;
LED2_ON;
LED3_ON;
printf("???ò????????");
GUI_Chinese(20,20,"????",YELLOW,BLACK);
while(1)
{
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>