博士
最后登录1970-1-1
在线时间 小时
注册时间2014-10-31
|
LCD与SPI FLASH结合就不行了,我想把SPI FLASH写入和读出数据显示在开发板LCD上,结果几条带汉字的printf语句打叹号
LCD什么也不显示,去掉两个带汉字的printf语句后,LCD可正常显示,我迷 LCD显示和串口有什么关系,说是与串口有关,为什么printf打印英文语句没问题呢?
说与汉字显示有关,但最后两句带汉字的printf语句不用删LCD也能正常工作呢?
#include "bsp_usart1.h"
#include "bsp_spi_flash.h"
#include "bsp_ili9341_lcd.h"
#include "math.h"
typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;
/* 获取缓冲区的长度 */
#define TxBufferSize1 (countof(TxBuffer1) - 1)
#define RxBufferSize1 (countof(TxBuffer1) - 1)
#define countof(a) (sizeof(a) / sizeof(*(a)))
#define BufferSize (countof(Tx_Buffer)-1)
#define FLASH_WriteAddress 0x00000
#define FLASH_ReadAddress FLASH_WriteAddress
#define FLASH_SectorToErase FLASH_WriteAddress
//#define sFLASH_ID 0xEF3015 //W25X16
#define sFLASH_ID 0xEF4015 //W25Q16
/* 发送缓冲区初始化 */
uint8_t Tx_Buffer[]={12,13,14,15,16,185,186,187,188,199};
uint8_t Rx_Buffer[BufferSize];
uint8_t n;
__IO uint32_t DeviceID = 0;
__IO uint32_t FlashID = 0;
__IO TestStatus TransferStatus1 = FAILED;
// 函数原型声明
void Delay(__IO uint32_t nCount);
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);
int main(void)
{
/* 配置串口1为:115200 8-N-1 */
USART1_Config();
SPI_FLASH_Init();
LCD_Init();
//printf("\r\n 这是一个2M串行flash(W25Q16)实验 \r\n");
/* 2M串行flash W25Q16初始化 */
LCD_Clear(0, 0, 240, 320, BACKGROUND);
LCD_DispStr(10, 10, (uint8_t *)"This is a flash test program", RED);
/* Get SPI Flash Device ID */
DeviceID = SPI_FLASH_ReadDeviceID();
Delay( 200 );
/* Get SPI Flash ID */
FlashID = SPI_FLASH_ReadID();
printf("\r\n FlashID is 0x%X, Manufacturer Device ID is 0x%X\r\n", FlashID, DeviceID);
/* Check the SPI Flash ID */
if (FlashID == sFLASH_ID) /* #define sFLASH_ID 0xEF3015 */
{
// printf("\r\n 检测到华邦串行flash W25Q16 !\r\n");
/* Erase SPI FLASH Sector to write on */
SPI_FLASH_SectorErase(FLASH_SectorToErase);
for( n=0; n<10; n++ )
{
LCD_DispStr(10, 40, (uint8_t *)"WRITE ", RED);
LCD_DisNum(100, 60, n, WHITE);
LCD_DisNum(100, 80, Tx_Buffer[n], RED);
Lcd_Delay(0x6FFF00);
}
/* 将发送缓冲区的数据写到flash中 */
SPI_FLASH_BufferWrite(Tx_Buffer, FLASH_WriteAddress, BufferSize);
//printf("\r\n 写入的数据为:%s \r\t", Tx_Buffer);
/* 将刚刚写入的数据读出来放到接收缓冲区中 */
SPI_FLASH_BufferRead(Rx_Buffer, FLASH_ReadAddress, BufferSize);
//printf("\r\n 读出的数据为:%s \r\n", Tx_Buffer);
/* 检查写入的数据与读出的数据是否相等 */
TransferStatus1 = Buffercmp(Tx_Buffer, Rx_Buffer, BufferSize);
if( PASSED == TransferStatus1 )
{
//printf("\r\n 2M串行flash(W25Q16)测试成功!\n\r");
for( n=0; n<10; n++ )
{
LCD_DisNum(100, 100, Rx_Buffer[n], RED);
Lcd_Delay(0xAFFF00);
}
}
else
{
printf("\r\n 2M串行flash(W25Q16)测试失败!\n\r");
}
}// if (FlashID == sFLASH_ID)
else
{
printf("\r\n 获取不到 W25Q16 ID!\n\r");
}
SPI_Flash_PowerDown();
while(1);
}
/*
* 函数名:Buffercmp
* 描述 :比较两个缓冲区中的数据是否相等
* 输入 :-pBuffer1 src缓冲区指针
* -pBuffer2 dst缓冲区指针
* -BufferLength 缓冲区长度
* 输出 :无
* 返回 :-PASSED pBuffer1 等于 pBuffer2
* -FAILED pBuffer1 不同于 pBuffer2
*/
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
{
while(BufferLength--)
{
if(*pBuffer1 != *pBuffer2)
{
return FAILED;
}
pBuffer1++;
pBuffer2++;
}
return PASSED;
}
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
|
|