试验要求:
1、通过串口,下发两个命令 STR和PIC;
2、STR模式:
(1)串口输入什么,屏幕上显示什么
(2)如果屏幕满,自动下滚
(3)输入回车,进行换行
(4)输入PIC切换到PIC模式
3、PIC模式:
(1)快速连续播放内置的单片机图片(以达到动图效果)
(2)串口输入STR切换至STR模式
1、运行效果展示
1.1 STR模式(最终运行效果)
串口输入:
LCD液晶屏显示:
2.1 PIC模式(GIF图片效果,并非最终运行效果)
1、配置工程
1.1、通过原理图找对应的功能引脚(SPI+UART)
spi:
uart:
1.2、配置spi和uart
略。
1.3、找ILI9341驱动库并修改
主要是注意修改对应的管脚功能,例如下图,需要改成实际使用的管脚。
2、STR模式的准备工作
2.1、字模原理及验证
原理:通过以下网址学习
26. LCD—液晶显示中英文 — [野火]STM32 HAL库开发实战指南——基于F103系列开发板 文档
通过工具生成的字符A和B的字模:
/* 16X32的字模: 大写 */
unsigned char capLetterSet[2][64]={
{// A 0x41 //
0x00,0x00,0x00,0x00,0x01,0x80,0x03,0x80,0x02,0xC0,0x02,0xC0,0x06,0xC0,0x04,0xE0,
0x04,0x60,0x04,0x60,0x04,0x60,0x0C,0x70,0x08,0x30,0x08,0x30,0x08,0x30,0x1F,0xF8,
0x10,0x18,0x10,0x18,0x10,0x18,0x10,0x18,0x10,0x1C,0x30,0x0C,0x20,0x0C,0x20,0x0C,
0x60,0x0E,0xF8,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
},
{// B 0x42 //
0x00,0x00,0x00,0x00,0x3F,0xE0,0x18,0x38,0x18,0x18,0x18,0x0C,0x18,0x0C,0x18,0x0C,
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x18,0x18,0x30,0x1F,0xE0,0x18,0x30,0x18,0x18,
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x1C,
0x18,0x38,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
}
};
普通的C工程验证:
void Printf_Charater(unsigned char* matrix, int matrixLen)
{
int i,j;
unsigned char kk;
/*i用作行计数*/
for ( i=0; i<32; i++) {
/*j用作一字节内数据的移位计数*/
/*一行像素的第一个字节*/
for (j=0; j<8; j++) {
/*一个数据位一个数据位地处理*/
kk = matrix[2*i] << j ; //左移J位
if ( kk & 0x80) {
printf("*"); //如果最高位为1,输出*号,表示笔迹
} else {
printf(" "); //如果最高位为0,输出空格,表示空白
}
}
/*一行像素的第二个字节*/
for (j=0; j<8; j++) {
kk = matrix[2*i+1] << j ; //左移J位
if ( kk & 0x80) {
printf("*"); //如果最高位为1,输出*号,表示笔迹
} else {
printf(" "); //如果最高位为0,输出空格,表示空白
}
}
printf("\n"); //输出完一行像素,换行
}
printf("\n\n"); //一个字输出完毕
}
void screen_print(char* str){
for(int i=0;str[i]!=0;i++){
char ch=str[i];
unsigned char *charater_matrix=capLetterSet[ch-'A'];
Printf_Charater(charater_matrix, 64);
}
}
结论:本试验中采用16x32的字模。按照我的理解,就是把对应的字符转换成字模,液晶屏显示是,以16位为1行,每位代表这个像素点显示还是不显示(1-显示,0-不显示),共32行。本案例中,每个字节的高位代表较小的列号(MSP)
3、源码
3.1、main.c
int fputc(int ch, FILE * fp){
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 10);
return ch;
}
char uart_buff[128]={0};
int uart_buff_index=0;
char uart_ch;
typedef enum{
MODE_STR,
MODE_PIC
}mode_t;
mode_t mode;
extern unsigned char gImages[5][153600];
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
//只处理串叿 1 的数据中斿
if(huart != &huart1){
HAL_UART_Receive_IT(&huart1, (uint8_t*)&uart_ch, 1);
return;
}
uart_buff[uart_buff_index++]=uart_ch;
printf("%c",uart_ch);
if(uart_ch != '\r'){
HAL_UART_Receive_IT(&huart1, (uint8_t*)&uart_ch, 1);
return;
}
uart_buff[uart_buff_index-1]=0;//将\r替换成\0
printf("串口收到数据:[%s],uart_buff_index=[%d]!!!\n\r", uart_buff, uart_buff_index);
uart_buff_index=0;//重新计数
if(strcmp("STR", uart_buff)==0){//字符串模式 STR
printf("当前模式:STR(字符串显示模式(STR)\n\r");
HAL_UART_Receive_IT(&huart1, (uint8_t*)&uart_ch, 1);
mode = MODE_STR;
//清屏
return;
}
if(strcmp("PIC", uart_buff)==0){//图片模式
printf("当前模式:PIC(图片显示模式)\n\r");
HAL_UART_Receive_IT(&huart1, (uint8_t*)&uart_ch, 1);
//
mode = MODE_PIC;
//清屏
return;
}
if(mode == MODE_STR){
//显示uart_buff的内容,并且换行
printf("STR模式调用, uart_buff=[%s]\n\r", uart_buff);
LCD_str_print(uart_buff);
LCD_str_print("\n");
}
//
HAL_UART_Receive_IT(&huart1, (uint8_t*)&uart_ch, 1);
}
int main(void)
{
HAL_Init();
SystemClock_Config();
SystemPower_Config();
MX_GPIO_Init();
MX_ICACHE_Init();
MX_USART1_UART_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
ILI9341_Init();
HAL_UART_Receive_IT(&huart1, (uint8_t*)&uart_ch, 1);
int i=0;
while (1)
{
if(mode == MODE_PIC){//图片显示模式
LCD_picture(gImages[i%5]);
i++;
HAL_Delay(25);
}else{
HAL_Delay(1000);
}
}
}
/* 其他代码是cube自动生成的,略... */
3.2、LCD_font.c 字模集合(26个大写英文字母、*和空格)
#include "LCD_str.h"
unsigned char starMatrix[64]={//*
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,// * //
0x00,0x80,0x00,0x80,0x00,0x80,0x40,0x81,0x20,0x82,0x10,0x84,0x08,0x88,0x04,0x90,
0x02,0xA0,0x01,0xC0,0x02,0x20,0x04,0x10,0x08,0x08,0x10,0x04,0x20,0x02,0x40,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
unsigned char spaceMatrix[64]={//空格
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
unsigned char font_lowChSet[26][64]={//A-0x41
{
0x00,0x00,0x00,0x00,0x01,0x80,0x03,0x80,0x02,0xC0,0x02,0xC0,0x06,0xC0,0x04,0xE0,// A //
0x04,0x60,0x04,0x60,0x04,0x60,0x0C,0x70,0x08,0x30,0x08,0x30,0x08,0x30,0x1F,0xF8,
0x10,0x18,0x10,0x18,0x10,0x18,0x10,0x18,0x10,0x1C,0x30,0x0C,0x20,0x0C,0x20,0x0C,
0x60,0x0E,0xF8,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3F,0xE0,0x18,0x38,0x18,0x18,0x18,0x0C,0x18,0x0C,0x18,0x0C,// B //
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x18,0x18,0x30,0x1F,0xE0,0x18,0x30,0x18,0x18,
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x1C,
0x18,0x38,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x03,0xE4,0x07,0x34,0x0E,0x1C,0x1C,0x0C,0x18,0x06,0x38,0x06,// C //
0x38,0x02,0x30,0x02,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,
0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x02,0x38,0x02,0x18,0x06,0x18,0x04,0x0E,0x0C,
0x07,0x38,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3F,0xE0,0x18,0x30,0x18,0x18,0x18,0x1C,0x18,0x0C,0x18,0x0C,// D //
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x1C,0x18,0x18,
0x18,0x30,0x3F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3F,0xFC,0x18,0x0C,0x18,0x04,0x18,0x04,0x18,0x00,0x18,0x00,// E //
0x18,0x00,0x18,0x00,0x18,0x08,0x18,0x08,0x18,0x18,0x1F,0xF8,0x18,0x18,0x18,0x08,
0x18,0x08,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x04,0x18,0x04,
0x18,0x0C,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3F,0xFC,0x18,0x0C,0x18,0x06,0x18,0x06,0x18,0x02,0x18,0x00,// F //
0x18,0x00,0x18,0x00,0x18,0x08,0x18,0x08,0x18,0x18,0x1F,0xF8,0x18,0x18,0x18,0x08,
0x18,0x08,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,
0x3C,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x03,0xE4,0x07,0x34,0x0E,0x1C,0x1C,0x0C,0x18,0x06,0x38,0x06,// G //
0x30,0x02,0x30,0x02,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,0x30,0x00,
0x30,0x3F,0x30,0x0E,0x30,0x0E,0x30,0x0E,0x38,0x0E,0x18,0x0E,0x1C,0x0E,0x0E,0x1E,
0x07,0x30,0x03,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3E,0x3E,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,// H //
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x1F,0xFC,0x18,0x0C,0x18,0x0C,
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,
0x3C,0x1E,0x7E,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x0F,0xF0,0x03,0xC0,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,// I //
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
0x03,0xC0,0x0F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x0F,0xFC,0x01,0xE0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,// J //
0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,
0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x60,0xC0,0x70,0xC0,0x70,0xC0,
0x39,0x80,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3E,0x3E,0x18,0x18,0x18,0x10,0x18,0x20,0x18,0x20,0x18,0x40,// K //
0x18,0x40,0x18,0x80,0x18,0x80,0x19,0x00,0x1E,0x00,0x1F,0x00,0x1B,0x80,0x19,0x80,
0x18,0xC0,0x18,0xC0,0x18,0x60,0x18,0x70,0x18,0x30,0x18,0x18,0x18,0x1C,0x18,0x0C,
0x18,0x0E,0x3E,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x7F,0x00,0x3C,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,// L //
0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,
0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x04,0x18,0x04,0x18,0x0C,
0x18,0x1C,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x78,0x07,0x38,0x0E,0x38,0x0E,0x38,0x0E,0x34,0x16,0x34,0x16,// M //
0x34,0x16,0x36,0x36,0x32,0x26,0x32,0x26,0x32,0x26,0x33,0x66,0x31,0x46,0x31,0x46,
0x31,0x46,0x31,0xC6,0x30,0x86,0x30,0x86,0x30,0x06,0x30,0x06,0x30,0x06,0x30,0x06,
0x30,0x06,0x78,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3C,0x1E,0x1C,0x0C,0x1C,0x0C,0x1C,0x0C,0x1E,0x0C,0x1A,0x0C,// N //
0x1A,0x0C,0x1B,0x0C,0x19,0x0C,0x19,0x0C,0x19,0x8C,0x18,0x8C,0x18,0x8C,0x18,0xCC,
0x18,0x4C,0x18,0x4C,0x18,0x6C,0x18,0x2C,0x18,0x2C,0x18,0x3C,0x18,0x1C,0x18,0x1C,
0x18,0x1C,0x3C,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x07,0xE0,0x18,0x18,0x30,0x0C,0x60,0x06,0x60,0x06,0x60,0x06,// O //
0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,
0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x30,0x0C,
0x18,0x18,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3F,0xF0,0x18,0x38,0x18,0x1C,0x18,0x0C,0x18,0x0C,0x18,0x0C,// P //
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x1C,0x18,0x38,0x1F,0xF0,0x18,0x00,0x18,0x00,
0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,
0x3C,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x03,0xC0,0x0E,0x70,0x1C,0x38,0x18,0x18,0x30,0x0C,0x30,0x0C,// Q //
0x30,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0C,
0x30,0x0C,0x30,0x0C,0x30,0x0C,0x30,0x0C,0x33,0xCC,0x36,0x6C,0x1C,0x38,0x1C,0x39,
0x0E,0x79,0x03,0xCF,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3F,0xF0,0x18,0x38,0x18,0x1C,0x18,0x0C,0x18,0x0C,0x18,0x0C,// R //
0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x1C,0x18,0x38,0x1F,0xE0,0x19,0xC0,0x18,0xE0,
0x18,0xE0,0x18,0x70,0x18,0x70,0x18,0x38,0x18,0x38,0x18,0x1C,0x18,0x1C,0x18,0x0E,
0x3C,0x0E,0x7E,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x03,0xE4,0x0E,0x74,0x1C,0x1C,0x18,0x0C,0x30,0x06,0x30,0x02,// S //
0x30,0x02,0x38,0x00,0x18,0x00,0x1E,0x00,0x0F,0x00,0x03,0xC0,0x01,0xE0,0x00,0x70,
0x00,0x38,0x00,0x1C,0x00,0x0C,0x40,0x0C,0x40,0x0C,0x60,0x0C,0x30,0x1C,0x38,0x38,
0x2E,0x70,0x27,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x3F,0xFC,0x31,0x8C,0x21,0x84,0x61,0x86,0x41,0x82,0x01,0x80,// T //
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
0x03,0xC0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x7E,0x1F,0x3C,0x0E,0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,// U //
0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,
0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,0x18,0x04,0x0C,0x0C,
0x06,0x18,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x7E,0x3F,0x38,0x0E,0x18,0x0C,0x18,0x0C,0x18,0x0C,0x18,0x0C,// V //
0x0C,0x08,0x0C,0x08,0x0C,0x18,0x0C,0x10,0x0C,0x10,0x06,0x10,0x06,0x30,0x06,0x20,
0x06,0x20,0x06,0x20,0x03,0x60,0x03,0x40,0x03,0x40,0x03,0x40,0x03,0xC0,0x01,0x80,
0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0xFB,0xEF,0x61,0x82,0x61,0x82,0x61,0x82,0x61,0x82,0x31,0x86,// W //
0x31,0x84,0x31,0x84,0x31,0x84,0x31,0xC4,0x31,0xC4,0x31,0xC4,0x31,0x44,0x12,0x48,
0x1A,0x48,0x1A,0x48,0x1A,0x48,0x1A,0x68,0x1A,0x68,0x0C,0x30,0x0C,0x30,0x0C,0x30,
0x0C,0x30,0x0C,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0xFC,0x3F,0x70,0x0C,0x30,0x0C,0x38,0x08,0x18,0x10,0x1C,0x10,// X //
0x0C,0x10,0x0E,0x20,0x06,0x20,0x07,0x40,0x03,0x40,0x03,0x80,0x01,0x80,0x01,0xC0,
0x02,0xC0,0x02,0xC0,0x04,0x60,0x04,0x70,0x08,0x30,0x08,0x38,0x10,0x18,0x30,0x1C,
0x30,0x0E,0xFE,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x78,0x1F,0x30,0x06,0x18,0x04,0x18,0x04,0x18,0x04,0x0C,0x08,// Y //
0x0C,0x08,0x0C,0x08,0x06,0x10,0x06,0x10,0x03,0x20,0x03,0xE0,0x01,0xC0,0x01,0xC0,
0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,
0x03,0xE0,0x0F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
},
{
0x00,0x00,0x00,0x00,0x1F,0xFE,0x18,0x0C,0x10,0x0C,0x30,0x1C,0x20,0x18,0x20,0x18,// Z //
0x00,0x38,0x00,0x30,0x00,0x70,0x00,0x60,0x00,0xE0,0x00,0xC0,0x00,0xC0,0x01,0xC0,
0x01,0x80,0x03,0x80,0x03,0x00,0x07,0x00,0x06,0x02,0x0E,0x02,0x0C,0x06,0x1C,0x04,
0x1C,0x0C,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
}
};
3.3、LCD_str.c 字符和字符串的LCD打印
#include "LCD_str.h"
#include "bsp_ili9341_4line.h"
#include <stdio.h>
void LCD_str_print(char* str){
static int global_x=0;
static int global_y=0;
//
for(int i=0;str[i]!=0;i++){
if(str[i]=='\n'){
global_x=0;
global_y+=32;
continue;
}
if(global_x+16 > 240){
global_x=0;
global_y+=32;
}
LCD_ch_show(global_x, global_y, str[i]);
global_x+=16;
}
}
void LCD_ch_show(int start_x, int start_y, char ch){
//获取对应字符的字模
unsigned char* matrix;
if(ch == ' '){//空格
matrix = spaceMatrix;
}else if(ch < 'A' || ch > 'Z'){
matrix = starMatrix;
}else{//A-Z之间
matrix = font_lowChSet[ch-'A'];
}
//显示
for(int row=0;row<32;row++){//16x32 每行2字节 从高位开始计数
//第一个字符
unsigned char mm=matrix[row*2];
int col=0;
for(col=0; col<8;col++){
if(mm & 0x80){
//显示 x在变, y没变,y代表row
_HW_DrawPoint(col+start_x,row+start_y, GREEN);
}
mm <<= 1;
}
//第二个字符
mm=matrix[row*2+1];
for(col=8; col<16;col++){
if(mm & 0x80){
//显示 x在变, y没变,y代表row
_HW_DrawPoint(col+start_x,row+start_y, GREEN);
}
mm <<= 1;
}
}
}
3.4、LCD图片打印相关函数代码
void LCD_picture(unsigned char* pic)
{
uint8_t temp[2] = {};
//1. 给 ILI9341寄存器 写入 写数据命令
ILI9341_WR_REG(0x2C);
//屏幕中, 一个像素点占用两个字节
uint32_t len = 2*240*320;
uint32_t i = 0;
while(i < len)
{
temp[0] = pic[i];
temp[1] = pic[i+1];
HAL_SPI_Transmit(&hspi1,temp,2,0);
i = i+2;
}
}
void LCD_pictures(unsigned char (*pics)[153600], int picPages)
{
unsigned int i=0;
while(1){
LCD_picture(pics[i%picPages]);
i++;
}
}
4、小结
关于原理图:SPI的转接板的序号并没有对上,不知道是原理图有错还是我的查找方法不正确。
关于字模:
(1)本试验采用的16x32的字模,若是需要更小或更大的字体,需要重新生成字模或者通过某种算法扩展;
(2)本试验仅支持A-Z的大写字母,如果需要更多的字符需要重新生成字模;
(3)多字节的字符,例如中文,应该需要某种算法来找到对应的字模矩阵,没研究。
关于cube:关于cubeMax,重新生成导入到keil中,可能会有中文的乱码。还不知道怎么解决
关于烧录程序:本次的试验,用到的图片和字模都比较占用空间,目前是直接写到.c文件中,这样的话会占用较多的栈空间。按我的理解,应该放到硬盘中(例如flash),需要的时候再加载进来,单目前还不知道怎么使用flash。