软件SPI可以驱动屏幕
This commit is contained in:
297
STM32F103C8T6/Drivers/BSP/LCD/lcd_data.c
Normal file
297
STM32F103C8T6/Drivers/BSP/LCD/lcd_data.c
Normal file
@@ -0,0 +1,297 @@
|
||||
#include "lcd_data.h"
|
||||
/*ASCII字模数据*********************/
|
||||
|
||||
/*宽8像素,高16像素*/
|
||||
const uint8_t LCD_F8x16[][16] =
|
||||
{
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
|
||||
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,// ! 1
|
||||
0x00,0x16,0x0E,0x00,0x16,0x0E,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// " 2
|
||||
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,
|
||||
0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,// # 3
|
||||
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,
|
||||
0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,// $ 4
|
||||
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,
|
||||
0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,// % 5
|
||||
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,
|
||||
0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,// & 6
|
||||
0x00,0x00,0x00,0x16,0x0E,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ' 7
|
||||
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,
|
||||
0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,// ( 8
|
||||
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,
|
||||
0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,// ) 9
|
||||
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,
|
||||
0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,// * 10
|
||||
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
|
||||
0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,// + 11
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,// , 12
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,// - 13
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,// . 14
|
||||
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,
|
||||
0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,// / 15
|
||||
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
|
||||
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,// 0 16
|
||||
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
|
||||
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// 1 17
|
||||
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
|
||||
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,// 2 18
|
||||
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
|
||||
0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,// 3 19
|
||||
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
|
||||
0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,// 4 20
|
||||
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
|
||||
0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,// 5 21
|
||||
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
|
||||
0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,// 6 22
|
||||
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
|
||||
0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,// 7 23
|
||||
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
|
||||
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,// 8 24
|
||||
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
|
||||
0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,// 9 25
|
||||
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,// : 26
|
||||
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
|
||||
0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,// ; 27
|
||||
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,
|
||||
0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,// < 28
|
||||
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
|
||||
0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,// = 29
|
||||
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,
|
||||
0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,// > 30
|
||||
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,
|
||||
0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,// ? 31
|
||||
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,
|
||||
0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,// @ 32
|
||||
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,
|
||||
0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,// A 33
|
||||
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,
|
||||
0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,// B 34
|
||||
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,
|
||||
0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,// C 35
|
||||
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,
|
||||
0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,// D 36
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
|
||||
0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,// E 37
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
|
||||
0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,// F 38
|
||||
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,
|
||||
0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,// G 39
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
|
||||
0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,// H 40
|
||||
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,
|
||||
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// I 41
|
||||
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,
|
||||
0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,// J 42
|
||||
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,
|
||||
0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,// K 43
|
||||
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,
|
||||
0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,// L 44
|
||||
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,
|
||||
0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,// M 45
|
||||
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,
|
||||
0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,// N 46
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
|
||||
0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,// O 47
|
||||
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,
|
||||
0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,// P 48
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
|
||||
0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,// Q 49
|
||||
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,
|
||||
0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,// R 50
|
||||
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,
|
||||
0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,// S 51
|
||||
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,
|
||||
0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,// T 52
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
|
||||
0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,// U 53
|
||||
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,
|
||||
0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,// V 54
|
||||
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,
|
||||
0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,// W 55
|
||||
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,
|
||||
0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,// X 56
|
||||
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,
|
||||
0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,// Y 57
|
||||
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,
|
||||
0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,// Z 58
|
||||
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,
|
||||
0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,// [ 59
|
||||
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,// \ 60
|
||||
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,
|
||||
0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,// ] 61
|
||||
0x00,0x20,0x10,0x08,0x04,0x08,0x10,0x20,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ^ 62
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,// _ 63
|
||||
0x00,0x02,0x04,0x08,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ` 64
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
|
||||
0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,// a 65
|
||||
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,
|
||||
0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,// b 66
|
||||
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,
|
||||
0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,// c 67
|
||||
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,
|
||||
0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,// d 68
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
|
||||
0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,// e 69
|
||||
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,
|
||||
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// f 70
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
|
||||
0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,// g 71
|
||||
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,
|
||||
0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,// h 72
|
||||
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,
|
||||
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// i 73
|
||||
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,
|
||||
0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,// j 74
|
||||
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,
|
||||
0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,// k 75
|
||||
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,
|
||||
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// l 76
|
||||
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
|
||||
0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,// m 77
|
||||
0x00,0x80,0x80,0x00,0x80,0x80,0x00,0x00,
|
||||
0x00,0x20,0x3F,0x21,0x00,0x20,0x3F,0x20,// n 78
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
|
||||
0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,// o 79
|
||||
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,
|
||||
0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,// p 80
|
||||
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,
|
||||
0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,// q 81
|
||||
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
|
||||
0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,// r 82
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
|
||||
0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,// s 83
|
||||
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,
|
||||
0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,// t 84
|
||||
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,
|
||||
0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,// u 85
|
||||
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
|
||||
0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,// v 86
|
||||
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,
|
||||
0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,// w 87
|
||||
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
|
||||
0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,// x 88
|
||||
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
|
||||
0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,// y 89
|
||||
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
|
||||
0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,// z 90
|
||||
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,
|
||||
0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,// { 91
|
||||
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,// | 92
|
||||
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,
|
||||
0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,// } 93
|
||||
0x00,0x80,0x40,0x40,0x80,0x00,0x00,0x80,
|
||||
0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,// ~ 94
|
||||
};
|
||||
|
||||
/*宽6像素,高8像素*/
|
||||
const uint8_t LCD_F6x8[][6] =
|
||||
{
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,// 0
|
||||
0x00,0x00,0x00,0x2F,0x00,0x00,// ! 1
|
||||
0x00,0x00,0x07,0x00,0x07,0x00,// " 2
|
||||
0x00,0x14,0x7F,0x14,0x7F,0x14,// # 3
|
||||
0x00,0x24,0x2A,0x7F,0x2A,0x12,// $ 4
|
||||
0x00,0x23,0x13,0x08,0x64,0x62,// % 5
|
||||
0x00,0x36,0x49,0x55,0x22,0x50,// & 6
|
||||
0x00,0x00,0x00,0x07,0x00,0x00,// ' 7
|
||||
0x00,0x00,0x1C,0x22,0x41,0x00,// ( 8
|
||||
0x00,0x00,0x41,0x22,0x1C,0x00,// ) 9
|
||||
0x00,0x14,0x08,0x3E,0x08,0x14,// * 10
|
||||
0x00,0x08,0x08,0x3E,0x08,0x08,// + 11
|
||||
0x00,0x00,0x00,0xA0,0x60,0x00,// , 12
|
||||
0x00,0x08,0x08,0x08,0x08,0x08,// - 13
|
||||
0x00,0x00,0x60,0x60,0x00,0x00,// . 14
|
||||
0x00,0x20,0x10,0x08,0x04,0x02,// / 15
|
||||
0x00,0x3E,0x51,0x49,0x45,0x3E,// 0 16
|
||||
0x00,0x00,0x42,0x7F,0x40,0x00,// 1 17
|
||||
0x00,0x42,0x61,0x51,0x49,0x46,// 2 18
|
||||
0x00,0x21,0x41,0x45,0x4B,0x31,// 3 19
|
||||
0x00,0x18,0x14,0x12,0x7F,0x10,// 4 20
|
||||
0x00,0x27,0x45,0x45,0x45,0x39,// 5 21
|
||||
0x00,0x3C,0x4A,0x49,0x49,0x30,// 6 22
|
||||
0x00,0x01,0x71,0x09,0x05,0x03,// 7 23
|
||||
0x00,0x36,0x49,0x49,0x49,0x36,// 8 24
|
||||
0x00,0x06,0x49,0x49,0x29,0x1E,// 9 25
|
||||
0x00,0x00,0x36,0x36,0x00,0x00,// : 26
|
||||
0x00,0x00,0x56,0x36,0x00,0x00,// ; 27
|
||||
0x00,0x08,0x14,0x22,0x41,0x00,// < 28
|
||||
0x00,0x14,0x14,0x14,0x14,0x14,// = 29
|
||||
0x00,0x00,0x41,0x22,0x14,0x08,// > 30
|
||||
0x00,0x02,0x01,0x51,0x09,0x06,// ? 31
|
||||
0x00,0x3E,0x49,0x55,0x59,0x2E,// @ 32
|
||||
0x00,0x7C,0x12,0x11,0x12,0x7C,// A 33
|
||||
0x00,0x7F,0x49,0x49,0x49,0x36,// B 34
|
||||
0x00,0x3E,0x41,0x41,0x41,0x22,// C 35
|
||||
0x00,0x7F,0x41,0x41,0x22,0x1C,// D 36
|
||||
0x00,0x7F,0x49,0x49,0x49,0x41,// E 37
|
||||
0x00,0x7F,0x09,0x09,0x09,0x01,// F 38
|
||||
0x00,0x3E,0x41,0x49,0x49,0x7A,// G 39
|
||||
0x00,0x7F,0x08,0x08,0x08,0x7F,// H 40
|
||||
0x00,0x00,0x41,0x7F,0x41,0x00,// I 41
|
||||
0x00,0x20,0x40,0x41,0x3F,0x01,// J 42
|
||||
0x00,0x7F,0x08,0x14,0x22,0x41,// K 43
|
||||
0x00,0x7F,0x40,0x40,0x40,0x40,// L 44
|
||||
0x00,0x7F,0x02,0x0C,0x02,0x7F,// M 45
|
||||
0x00,0x7F,0x04,0x08,0x10,0x7F,// N 46
|
||||
0x00,0x3E,0x41,0x41,0x41,0x3E,// O 47
|
||||
0x00,0x7F,0x09,0x09,0x09,0x06,// P 48
|
||||
0x00,0x3E,0x41,0x51,0x21,0x5E,// Q 49
|
||||
0x00,0x7F,0x09,0x19,0x29,0x46,// R 50
|
||||
0x00,0x46,0x49,0x49,0x49,0x31,// S 51
|
||||
0x00,0x01,0x01,0x7F,0x01,0x01,// T 52
|
||||
0x00,0x3F,0x40,0x40,0x40,0x3F,// U 53
|
||||
0x00,0x1F,0x20,0x40,0x20,0x1F,// V 54
|
||||
0x00,0x3F,0x40,0x38,0x40,0x3F,// W 55
|
||||
0x00,0x63,0x14,0x08,0x14,0x63,// X 56
|
||||
0x00,0x07,0x08,0x70,0x08,0x07,// Y 57
|
||||
0x00,0x61,0x51,0x49,0x45,0x43,// Z 58
|
||||
0x00,0x00,0x7F,0x41,0x41,0x00,// [ 59
|
||||
0x00,0x02,0x04,0x08,0x10,0x20,// \ 60
|
||||
0x00,0x00,0x41,0x41,0x7F,0x00,// ] 61
|
||||
0x00,0x04,0x02,0x01,0x02,0x04,// ^ 62
|
||||
0x00,0x40,0x40,0x40,0x40,0x40,// _ 63
|
||||
0x00,0x00,0x01,0x02,0x04,0x00,// ` 64
|
||||
0x00,0x20,0x54,0x54,0x54,0x78,// a 65
|
||||
0x00,0x7F,0x48,0x44,0x44,0x38,// b 66
|
||||
0x00,0x38,0x44,0x44,0x44,0x20,// c 67
|
||||
0x00,0x38,0x44,0x44,0x48,0x7F,// d 68
|
||||
0x00,0x38,0x54,0x54,0x54,0x18,// e 69
|
||||
0x00,0x08,0x7E,0x09,0x01,0x02,// f 70
|
||||
0x00,0x18,0xA4,0xA4,0xA4,0x7C,// g 71
|
||||
0x00,0x7F,0x08,0x04,0x04,0x78,// h 72
|
||||
0x00,0x00,0x44,0x7D,0x40,0x00,// i 73
|
||||
0x00,0x40,0x80,0x84,0x7D,0x00,// j 74
|
||||
0x00,0x7F,0x10,0x28,0x44,0x00,// k 75
|
||||
0x00,0x00,0x41,0x7F,0x40,0x00,// l 76
|
||||
0x00,0x7C,0x04,0x18,0x04,0x78,// m 77
|
||||
0x00,0x7C,0x08,0x04,0x04,0x78,// n 78
|
||||
0x00,0x38,0x44,0x44,0x44,0x38,// o 79
|
||||
0x00,0xFC,0x24,0x24,0x24,0x18,// p 80
|
||||
0x00,0x18,0x24,0x24,0x18,0xFC,// q 81
|
||||
0x00,0x7C,0x08,0x04,0x04,0x08,// r 82
|
||||
0x00,0x48,0x54,0x54,0x54,0x20,// s 83
|
||||
0x00,0x04,0x3F,0x44,0x40,0x20,// t 84
|
||||
0x00,0x3C,0x40,0x40,0x20,0x7C,// u 85
|
||||
0x00,0x1C,0x20,0x40,0x20,0x1C,// v 86
|
||||
0x00,0x3C,0x40,0x30,0x40,0x3C,// w 87
|
||||
0x00,0x44,0x28,0x10,0x28,0x44,// x 88
|
||||
0x00,0x1C,0xA0,0xA0,0xA0,0x7C,// y 89
|
||||
0x00,0x44,0x64,0x54,0x4C,0x44,// z 90
|
||||
0x00,0x00,0x08,0x7F,0x41,0x00,// { 91
|
||||
0x00,0x00,0x00,0x7F,0x00,0x00,// | 92
|
||||
0x00,0x00,0x41,0x7F,0x08,0x00,// } 93
|
||||
0x00,0x08,0x04,0x08,0x10,0x08,// ~ 94
|
||||
};
|
||||
10
STM32F103C8T6/Drivers/BSP/LCD/lcd_data.h
Normal file
10
STM32F103C8T6/Drivers/BSP/LCD/lcd_data.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __LCD_DATA_H_
|
||||
#define __LCD_DATA_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*ASCII字模数据声明*/
|
||||
extern const uint8_t LCD_F8x16[][16];
|
||||
extern const uint8_t LCD_F6x8[][6];
|
||||
|
||||
#endif
|
||||
621
STM32F103C8T6/Drivers/BSP/LCD/st7735s.c
Normal file
621
STM32F103C8T6/Drivers/BSP/LCD/st7735s.c
Normal file
@@ -0,0 +1,621 @@
|
||||
/*
|
||||
* 模块名称:ST7735S LCD驱动
|
||||
* 模块功能:提供128x160 RGB TFT屏幕的初始化、画点、画线、填充、显示字符串等功能
|
||||
* 适用平台:STM32F103C8T6 + SPI2
|
||||
* 作者:王建锋
|
||||
* 创建日期:2026-07-13
|
||||
* 修改记录:
|
||||
* 2026-07-13 王建锋 创建初始版本
|
||||
*/
|
||||
|
||||
#include "st7735s.h"
|
||||
#include "lcd_data.h"
|
||||
#include "spi.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static uint16_t s_lcd_width = LCD_WIDTH;
|
||||
static uint16_t s_lcd_height = LCD_HEIGHT;
|
||||
|
||||
extern DMA_HandleTypeDef hdma_spi2_tx;
|
||||
|
||||
/* 8x16 ASCII字体(ASCII 32-126),每字符16字节 - 定义在 lcd_data.c 中 */
|
||||
|
||||
/*
|
||||
* 函数功能:软件SPI写一个字节
|
||||
* 入口参数:data - 要发送的数据
|
||||
* 返回值:无
|
||||
* 函数说明:模拟SPI时序发送一个字节,MSB先
|
||||
*/
|
||||
static void st7735s_spi_write_byte(uint8_t data)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
HAL_GPIO_WritePin(LCD_SCL_PORT, LCD_SCL_PIN, GPIO_PIN_RESET);
|
||||
if (data & 0x80) {
|
||||
HAL_GPIO_WritePin(LCD_SDA_PORT, LCD_SDA_PIN, GPIO_PIN_SET);
|
||||
} else {
|
||||
HAL_GPIO_WritePin(LCD_SDA_PORT, LCD_SDA_PIN, GPIO_PIN_RESET);
|
||||
}
|
||||
__NOP();
|
||||
__NOP();
|
||||
HAL_GPIO_WritePin(LCD_SCL_PORT, LCD_SCL_PIN, GPIO_PIN_SET);
|
||||
__NOP();
|
||||
__NOP();
|
||||
data <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:写入命令
|
||||
* 入口参数:cmd - 命令字节
|
||||
* 返回值:无
|
||||
* 函数说明:拉低DC,选择芯片,发送命令,释放芯片
|
||||
*/
|
||||
static void st7735s_write_cmd(uint8_t cmd)
|
||||
{
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_RESET);
|
||||
st7735s_spi_write_byte(cmd);
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:写入数据
|
||||
* 入口参数:data - 数据字节
|
||||
* 返回值:无
|
||||
* 函数说明:拉高DC,选择芯片,发送数据,释放芯片
|
||||
*/
|
||||
static void st7735s_write_data(uint8_t data)
|
||||
{
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
|
||||
st7735s_spi_write_byte(data);
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:写入多字节数据(CS保持低)
|
||||
* 入口参数:p_data - 数据缓冲区指针
|
||||
* len - 字节数
|
||||
* 返回值:无
|
||||
* 函数说明:用于连续写入多个数据字节,省去中间CS跳变
|
||||
*/
|
||||
static void st7735s_write_data_multi(const uint8_t *p_data, uint16_t len)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
|
||||
for (i = 0; i < len; i++) {
|
||||
st7735s_spi_write_byte(p_data[i]);
|
||||
}
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:写入16位颜色数据
|
||||
* 入口参数:p_color - 16位颜色缓冲区指针
|
||||
* len - 像素个数
|
||||
* 返回值:无
|
||||
* 函数说明:MSB先发送RGB565数据
|
||||
*/
|
||||
static void st7735s_write_colors(uint16_t *p_color, uint16_t len)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
|
||||
for (i = 0; i < len; i++) {
|
||||
st7735s_spi_write_byte((uint8_t)(p_color[i] >> 8));
|
||||
st7735s_spi_write_byte((uint8_t)(p_color[i] & 0xFF));
|
||||
}
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:LCD初始化
|
||||
* 入口参数:无
|
||||
* 返回值:无
|
||||
* 函数说明:执行ST7735S标准初始化序列
|
||||
*/
|
||||
void st7735s_init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
printf("LCD init start (soft SPI)...\r\n");
|
||||
|
||||
/* 将SCL和SDA引脚切换为GPIO输出(软件SPI) */
|
||||
GPIO_InitStruct.Pin = LCD_SCL_PIN | LCD_SDA_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
HAL_GPIO_WritePin(LCD_SCL_PORT, LCD_SCL_PIN, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(LCD_SDA_PORT, LCD_SDA_PIN, GPIO_PIN_SET);
|
||||
|
||||
/* 确保CS和RST初始为高,避免LCD在初始化期间被错误选中 */
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_RESET);
|
||||
HAL_Delay(10);
|
||||
|
||||
printf("IO: RST=%d DC=%d CS=%d\r\n",
|
||||
(int)HAL_GPIO_ReadPin(LCD_RST_PORT, LCD_RST_PIN),
|
||||
(int)HAL_GPIO_ReadPin(LCD_DC_PORT, LCD_DC_PIN),
|
||||
(int)HAL_GPIO_ReadPin(LCD_CS_PORT, LCD_CS_PIN));
|
||||
|
||||
/* 硬件复位 */
|
||||
printf("HW reset...\r\n");
|
||||
HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_RESET);
|
||||
HAL_Delay(10);
|
||||
HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_SET);
|
||||
HAL_Delay(120);
|
||||
|
||||
/* 软件复位 */
|
||||
printf("SW reset...\r\n");
|
||||
st7735s_write_cmd(LCD_CMD_SWRESET);
|
||||
HAL_Delay(150);
|
||||
|
||||
/* 退出睡眠模式 */
|
||||
printf("Sleep out...\r\n");
|
||||
st7735s_write_cmd(LCD_CMD_SLPOUT);
|
||||
HAL_Delay(500);
|
||||
|
||||
/* 帧率控制 */
|
||||
printf("Frame rate...\r\n");
|
||||
st7735s_write_cmd(LCD_CMD_FRMCTR1);
|
||||
st7735s_write_data(0x01);
|
||||
st7735s_write_data(0x2C);
|
||||
st7735s_write_data(0x2D);
|
||||
|
||||
st7735s_write_cmd(LCD_CMD_FRMCTR2);
|
||||
st7735s_write_data(0x01);
|
||||
st7735s_write_data(0x2C);
|
||||
st7735s_write_data(0x2D);
|
||||
|
||||
st7735s_write_cmd(LCD_CMD_FRMCTR3);
|
||||
st7735s_write_data(0x01);
|
||||
st7735s_write_data(0x2C);
|
||||
st7735s_write_data(0x2D);
|
||||
st7735s_write_data(0x01);
|
||||
st7735s_write_data(0x2C);
|
||||
st7735s_write_data(0x2D);
|
||||
|
||||
/* 显示反转控制 */
|
||||
st7735s_write_cmd(LCD_CMD_INVCTR);
|
||||
st7735s_write_data(0x07);
|
||||
|
||||
/* 功率控制 */
|
||||
printf("Power ctrl...\r\n");
|
||||
st7735s_write_cmd(LCD_CMD_PWCTR1);
|
||||
st7735s_write_data(0xA2);
|
||||
st7735s_write_data(0x02);
|
||||
st7735s_write_data(0x84);
|
||||
|
||||
st7735s_write_cmd(LCD_CMD_PWCTR2);
|
||||
st7735s_write_data(0xC5);
|
||||
|
||||
st7735s_write_cmd(LCD_CMD_PWCTR3);
|
||||
st7735s_write_data(0x0A);
|
||||
st7735s_write_data(0x00);
|
||||
|
||||
st7735s_write_cmd(LCD_CMD_PWCTR4);
|
||||
st7735s_write_data(0x8A);
|
||||
st7735s_write_data(0x2A);
|
||||
|
||||
st7735s_write_cmd(LCD_CMD_PWCTR5);
|
||||
st7735s_write_data(0x8A);
|
||||
st7735s_write_data(0xEE);
|
||||
|
||||
/* VCOM控制 */
|
||||
st7735s_write_cmd(LCD_CMD_VMCTR1);
|
||||
st7735s_write_data(0x0E);
|
||||
|
||||
/* 竖屏模式 */
|
||||
printf("MADCTL...\r\n");
|
||||
st7735s_write_cmd(LCD_CMD_MADCTL);
|
||||
st7735s_write_data(0xC8);
|
||||
|
||||
/* 像素格式: 16位RGB565 */
|
||||
printf("COLMOD...\r\n");
|
||||
st7735s_write_cmd(LCD_CMD_COLMOD);
|
||||
st7735s_write_data(0x05);
|
||||
|
||||
/* Gamma校正 */
|
||||
printf("Gamma...\r\n");
|
||||
st7735s_write_cmd(LCD_CMD_GMCTRP1);
|
||||
st7735s_write_data(0x02);
|
||||
st7735s_write_data(0x1C);
|
||||
st7735s_write_data(0x07);
|
||||
st7735s_write_data(0x12);
|
||||
st7735s_write_data(0x37);
|
||||
st7735s_write_data(0x32);
|
||||
st7735s_write_data(0x29);
|
||||
st7735s_write_data(0x2D);
|
||||
st7735s_write_data(0x29);
|
||||
st7735s_write_data(0x25);
|
||||
st7735s_write_data(0x2B);
|
||||
st7735s_write_data(0x39);
|
||||
st7735s_write_data(0x00);
|
||||
st7735s_write_data(0x01);
|
||||
st7735s_write_data(0x03);
|
||||
st7735s_write_data(0x10);
|
||||
|
||||
st7735s_write_cmd(LCD_CMD_GMCTRN1);
|
||||
st7735s_write_data(0x03);
|
||||
st7735s_write_data(0x1D);
|
||||
st7735s_write_data(0x07);
|
||||
st7735s_write_data(0x06);
|
||||
st7735s_write_data(0x2E);
|
||||
st7735s_write_data(0x2C);
|
||||
st7735s_write_data(0x29);
|
||||
st7735s_write_data(0x2D);
|
||||
st7735s_write_data(0x2E);
|
||||
st7735s_write_data(0x2E);
|
||||
st7735s_write_data(0x37);
|
||||
st7735s_write_data(0x3F);
|
||||
st7735s_write_data(0x00);
|
||||
st7735s_write_data(0x00);
|
||||
st7735s_write_data(0x02);
|
||||
st7735s_write_data(0x10);
|
||||
|
||||
/* 关闭反转 */
|
||||
st7735s_write_cmd(0x20);
|
||||
|
||||
/* 进入正常显示模式(关键!) */
|
||||
printf("NORON...\r\n");
|
||||
st7735s_write_cmd(0x13);
|
||||
HAL_Delay(10);
|
||||
|
||||
/* 开启显示 */
|
||||
printf("DISPON...\r\n");
|
||||
st7735s_write_cmd(LCD_CMD_DISPON);
|
||||
HAL_Delay(100);
|
||||
printf("LCD init done\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:设置显示窗口
|
||||
* 入口参数:x1 - 起始列
|
||||
* y1 - 起始行
|
||||
* x2 - 结束列
|
||||
* y2 - 结束行
|
||||
* 返回值:无
|
||||
* 函数说明:设置后续写入操作的窗口区域
|
||||
*/
|
||||
void st7735s_set_window(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
|
||||
{
|
||||
st7735s_write_cmd(LCD_CMD_CASET);
|
||||
st7735s_write_data(0x00);
|
||||
st7735s_write_data((uint8_t)x1);
|
||||
st7735s_write_data(0x00);
|
||||
st7735s_write_data((uint8_t)x2);
|
||||
|
||||
st7735s_write_cmd(LCD_CMD_RASET);
|
||||
st7735s_write_data(0x00);
|
||||
st7735s_write_data((uint8_t)y1);
|
||||
st7735s_write_data(0x00);
|
||||
st7735s_write_data((uint8_t)y2);
|
||||
|
||||
st7735s_write_cmd(LCD_CMD_RAMWR);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:填充矩形区域
|
||||
* 入口参数:x1 - 起始列
|
||||
* y1 - 起始行
|
||||
* x2 - 结束列
|
||||
* y2 - 结束行
|
||||
* color - 填充颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:用指定颜色填充矩形区域
|
||||
*/
|
||||
void st7735s_fill_rect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
{
|
||||
uint32_t pixel_count;
|
||||
uint16_t i;
|
||||
uint16_t buf[64];
|
||||
|
||||
if (x1 > x2) {
|
||||
uint16_t t = x1;
|
||||
x1 = x2;
|
||||
x2 = t;
|
||||
}
|
||||
if (y1 > y2) {
|
||||
uint16_t t = y1;
|
||||
y1 = y2;
|
||||
y2 = t;
|
||||
}
|
||||
|
||||
pixel_count = (uint32_t)(x2 - x1 + 1) * (y2 - y1 + 1);
|
||||
|
||||
/* 预填充颜色缓冲区 */
|
||||
for (i = 0; i < 64; i++) {
|
||||
buf[i] = color;
|
||||
}
|
||||
|
||||
st7735s_set_window(x1, y1, x2, y2);
|
||||
|
||||
/* 分块发送 */
|
||||
while (pixel_count >= 64) {
|
||||
st7735s_write_colors(buf, 64);
|
||||
pixel_count -= 64;
|
||||
}
|
||||
if (pixel_count > 0) {
|
||||
st7735s_write_colors(buf, (uint16_t)pixel_count);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:全屏填充
|
||||
* 入口参数:color - 填充颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:用指定颜色填充整个屏幕
|
||||
*/
|
||||
void st7735s_fill_screen(uint16_t color)
|
||||
{
|
||||
printf("fill_screen 0x%04X\r\n", color);
|
||||
st7735s_fill_rect(0, 0, s_lcd_width - 1, s_lcd_height - 1, color);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:画点
|
||||
* 入口参数:x - 列坐标
|
||||
* y - 行坐标
|
||||
* color - 颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:在指定位置画一个点
|
||||
*/
|
||||
void st7735s_draw_pixel(uint16_t x, uint16_t y, uint16_t color)
|
||||
{
|
||||
if (x >= s_lcd_width || y >= s_lcd_height) {
|
||||
return;
|
||||
}
|
||||
st7735s_set_window(x, y, x, y);
|
||||
st7735s_write_data((uint8_t)(color >> 8));
|
||||
st7735s_write_data((uint8_t)color);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:画线
|
||||
* 入口参数:x1 - 起始列
|
||||
* y1 - 起始行
|
||||
* x2 - 结束列
|
||||
* y2 - 结束行
|
||||
* color - 颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:画一条直线(Bresenham算法)
|
||||
*/
|
||||
void st7735s_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
|
||||
{
|
||||
int16_t dx;
|
||||
int16_t dy;
|
||||
int16_t sx;
|
||||
int16_t sy;
|
||||
int16_t err;
|
||||
int16_t e2;
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
|
||||
if (x1 == x2) {
|
||||
/* 垂直线 */
|
||||
if (y1 > y2) {
|
||||
y = y1;
|
||||
y1 = y2;
|
||||
y2 = y;
|
||||
}
|
||||
st7735s_fill_rect(x1, y1, x1, y2, color);
|
||||
return;
|
||||
}
|
||||
|
||||
if (y1 == y2) {
|
||||
/* 水平线 */
|
||||
if (x1 > x2) {
|
||||
x = x1;
|
||||
x1 = x2;
|
||||
x2 = x;
|
||||
}
|
||||
st7735s_fill_rect(x1, y1, x2, y1, color);
|
||||
return;
|
||||
}
|
||||
|
||||
dx = (int16_t)x2 - (int16_t)x1;
|
||||
if (dx < 0) {
|
||||
dx = -dx;
|
||||
}
|
||||
sx = x1 < x2 ? 1 : -1;
|
||||
dy = (int16_t)y2 - (int16_t)y1;
|
||||
if (dy < 0) {
|
||||
dy = -dy;
|
||||
}
|
||||
sy = y1 < y2 ? 1 : -1;
|
||||
err = (dx > dy ? dx : -dy) / 2;
|
||||
|
||||
x = x1;
|
||||
y = y1;
|
||||
|
||||
while (1) {
|
||||
st7735s_draw_pixel(x, y, color);
|
||||
if (x == x2 && y == y2) {
|
||||
break;
|
||||
}
|
||||
e2 = err;
|
||||
if (e2 > -dx) {
|
||||
err -= dy;
|
||||
x += sx;
|
||||
}
|
||||
if (e2 < dy) {
|
||||
err += dx;
|
||||
y += sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:画矩形
|
||||
* 入口参数:x - 左上角列
|
||||
* y - 左上角行
|
||||
* width - 宽度
|
||||
* height - 高度
|
||||
* color - 颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:画一个空心矩形
|
||||
*/
|
||||
void st7735s_draw_rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)
|
||||
{
|
||||
st7735s_draw_line(x, y, x + width - 1, y, color);
|
||||
st7735s_draw_line(x, y + height - 1, x + width - 1, y + height - 1, color);
|
||||
st7735s_draw_line(x, y, x, y + height - 1, color);
|
||||
st7735s_draw_line(x + width - 1, y, x + width - 1, y + height - 1, color);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:画圆
|
||||
* 入口参数:x0 - 圆心列
|
||||
* y0 - 圆心行
|
||||
* radius - 半径
|
||||
* color - 颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:画一个空心圆(Bresenham算法)
|
||||
*/
|
||||
void st7735s_draw_circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color)
|
||||
{
|
||||
int16_t f = 1 - radius;
|
||||
int16_t ddf_x = 1;
|
||||
int16_t ddf_y = -2 * radius;
|
||||
int16_t x = 0;
|
||||
int16_t y = radius;
|
||||
|
||||
st7735s_draw_pixel(x0, y0 + radius, color);
|
||||
st7735s_draw_pixel(x0, y0 - radius, color);
|
||||
st7735s_draw_pixel(x0 + radius, y0, color);
|
||||
st7735s_draw_pixel(x0 - radius, y0, color);
|
||||
|
||||
while (x < y) {
|
||||
if (f >= 0) {
|
||||
y--;
|
||||
ddf_y += 2;
|
||||
f += ddf_y;
|
||||
}
|
||||
x++;
|
||||
ddf_x += 2;
|
||||
f += ddf_x;
|
||||
|
||||
st7735s_draw_pixel(x0 + x, y0 + y, color);
|
||||
st7735s_draw_pixel(x0 - x, y0 + y, color);
|
||||
st7735s_draw_pixel(x0 + x, y0 - y, color);
|
||||
st7735s_draw_pixel(x0 - x, y0 - y, color);
|
||||
st7735s_draw_pixel(x0 + y, y0 + x, color);
|
||||
st7735s_draw_pixel(x0 - y, y0 + x, color);
|
||||
st7735s_draw_pixel(x0 + y, y0 - x, color);
|
||||
st7735s_draw_pixel(x0 - y, y0 - x, color);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:显示字符
|
||||
* 入口参数:x - 列坐标
|
||||
* y - 行坐标
|
||||
* ch - 字符 (ASCII 32-126)
|
||||
* color - 字符颜色 (RGB565)
|
||||
* bg_color - 背景颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:在指定位置显示一个8x16 ASCII字符
|
||||
*/
|
||||
void st7735s_draw_char(uint16_t x, uint16_t y, char ch, uint16_t color, uint16_t bg_color)
|
||||
{
|
||||
uint16_t i;
|
||||
uint16_t j;
|
||||
uint8_t line;
|
||||
|
||||
if (ch < 32 || ch > 126) {
|
||||
ch = ' ';
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
line = LCD_F8x16[ch - 32][i];
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (line & 0x80) {
|
||||
st7735s_draw_pixel(x + j, y + i, color);
|
||||
} else {
|
||||
st7735s_draw_pixel(x + j, y + i, bg_color);
|
||||
}
|
||||
line <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:显示字符串
|
||||
* 入口参数:x - 列坐标
|
||||
* y - 行坐标
|
||||
* str - 字符串指针
|
||||
* color - 字符颜色 (RGB565)
|
||||
* bg_color - 背景颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:在指定位置显示字符串
|
||||
*/
|
||||
void st7735s_draw_string(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bg_color)
|
||||
{
|
||||
while (*str) {
|
||||
if (x + 8 > s_lcd_width) {
|
||||
x = 0;
|
||||
y += 16;
|
||||
}
|
||||
if (y + 16 > s_lcd_height) {
|
||||
break;
|
||||
}
|
||||
st7735s_draw_char(x, y, *str, color, bg_color);
|
||||
x += FONT_WIDTH_8;
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:设置屏幕方向
|
||||
* 入口参数:rotation - 方向 (0-3)
|
||||
* 返回值:无
|
||||
* 函数说明:0:竖屏 1:横屏 2:竖屏反转 3:横屏反转
|
||||
*/
|
||||
void st7735s_set_rotation(uint8_t rotation)
|
||||
{
|
||||
st7735s_write_cmd(LCD_CMD_MADCTL);
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
st7735s_write_data(0xC8);
|
||||
s_lcd_width = 128;
|
||||
s_lcd_height = 160;
|
||||
break;
|
||||
case 1:
|
||||
st7735s_write_data(0x78);
|
||||
s_lcd_width = 160;
|
||||
s_lcd_height = 128;
|
||||
break;
|
||||
case 2:
|
||||
st7735s_write_data(0x08);
|
||||
s_lcd_width = 128;
|
||||
s_lcd_height = 160;
|
||||
break;
|
||||
case 3:
|
||||
st7735s_write_data(0xA8);
|
||||
s_lcd_width = 160;
|
||||
s_lcd_height = 128;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:设置背光
|
||||
* 入口参数:state - 1:开 0:关
|
||||
* 返回值:无
|
||||
* 函数说明:控制LCD背光(如有硬件背光控制)
|
||||
*/
|
||||
void st7735s_backlight(uint8_t state)
|
||||
{
|
||||
(void)state;
|
||||
/* 当前硬件未连接背光控制引脚,预留接口 */
|
||||
}
|
||||
213
STM32F103C8T6/Drivers/BSP/LCD/st7735s.h
Normal file
213
STM32F103C8T6/Drivers/BSP/LCD/st7735s.h
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* 模块名称:ST7735S LCD驱动
|
||||
* 模块功能:提供128x160 RGB TFT屏幕的初始化、画点、画线、填充、显示字符串等功能
|
||||
* 适用平台:STM32F103C8T6 + SPI2
|
||||
* 作者:王建锋
|
||||
* 创建日期:2026-07-13
|
||||
* 修改记录:
|
||||
* 2026-07-13 王建锋 创建初始版本
|
||||
*/
|
||||
|
||||
#ifndef __ST7735S_H
|
||||
#define __ST7735S_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* 屏幕参数 */
|
||||
#define LCD_WIDTH 128 /* 屏幕宽度 */
|
||||
#define LCD_HEIGHT 160 /* 屏幕高度 */
|
||||
|
||||
/* 颜色定义 (RGB565) */
|
||||
#define COLOR_BLACK 0x0000
|
||||
#define COLOR_WHITE 0xFFFF
|
||||
#define COLOR_RED 0xF800
|
||||
#define COLOR_GREEN 0x07E0
|
||||
#define COLOR_BLUE 0x001F
|
||||
#define COLOR_YELLOW 0xFFE0
|
||||
#define COLOR_CYAN 0x07FF
|
||||
#define COLOR_MAGENTA 0xF81F
|
||||
#define COLOR_ORANGE 0xFD20
|
||||
#define COLOR_DARK_BLUE 0x0010
|
||||
#define COLOR_DARK_GREEN 0x0200
|
||||
#define COLOR_DARK_RED 0x8000
|
||||
|
||||
/* 颜色转换宏 */
|
||||
#define RGB565(r, g, b) ((uint16_t)(((r) & 0xF8) << 8 | ((g) & 0xFC) << 3 | ((b) >> 3)))
|
||||
|
||||
/* LCD控制引脚定义 - 根据CubeMX配置修改 */
|
||||
#define LCD_CS_PORT LCD_CS_GPIO_Port
|
||||
#define LCD_CS_PIN LCD_CS_Pin
|
||||
#define LCD_DC_PORT LCD_DC_GPIO_Port
|
||||
#define LCD_DC_PIN LCD_DC_Pin
|
||||
#define LCD_RST_PORT LCD_RST_GPIO_Port
|
||||
#define LCD_RST_PIN LCD_RST_Pin
|
||||
#define LCD_SCL_PORT GPIOB
|
||||
#define LCD_SCL_PIN GPIO_PIN_13
|
||||
#define LCD_SDA_PORT GPIOB
|
||||
#define LCD_SDA_PIN GPIO_PIN_15
|
||||
|
||||
/* LCD命令定义 */
|
||||
#define LCD_CMD_SWRESET 0x01 /* 软件复位 */
|
||||
#define LCD_CMD_SLPOUT 0x11 /* 退出睡眠 */
|
||||
#define LCD_CMD_DISPON 0x29 /* 显示开启 */
|
||||
#define LCD_CMD_DISPOFF 0x28 /* 显示关闭 */
|
||||
#define LCD_CMD_CASET 0x2A /* 列地址设置 */
|
||||
#define LCD_CMD_RASET 0x2B /* 行地址设置 */
|
||||
#define LCD_CMD_RAMWR 0x2C /* 写入显存 */
|
||||
#define LCD_CMD_MADCTL 0x36 /* 存储器访问控制 */
|
||||
#define LCD_CMD_COLMOD 0x3A /* 像素格式设置 */
|
||||
#define LCD_CMD_FRMCTR1 0xB1 /* 帧率控制1 */
|
||||
#define LCD_CMD_FRMCTR2 0xB2 /* 帧率控制2 */
|
||||
#define LCD_CMD_FRMCTR3 0xB3 /* 帧率控制3 */
|
||||
#define LCD_CMD_INVCTR 0xB4 /* 显示反转控制 */
|
||||
#define LCD_CMD_PWCTR1 0xC0 /* 功率控制1 */
|
||||
#define LCD_CMD_PWCTR2 0xC1 /* 功率控制2 */
|
||||
#define LCD_CMD_PWCTR3 0xC2 /* 功率控制3 */
|
||||
#define LCD_CMD_PWCTR4 0xC3 /* 功率控制4 */
|
||||
#define LCD_CMD_PWCTR5 0xC4 /* 功率控制5 */
|
||||
#define LCD_CMD_VMCTR1 0xC5 /* VCOM控制1 */
|
||||
#define LCD_CMD_GMCTRP1 0xE0 /* Gamma正向校正 */
|
||||
#define LCD_CMD_GMCTRN1 0xE1 /* Gamma反向校正 */
|
||||
|
||||
/* 字体定义 */
|
||||
#define FONT_WIDTH_8 8 /* 8x16字体宽度(含间距) */
|
||||
#define FONT_HEIGHT_16 16 /* 8x16字体高度 */
|
||||
|
||||
/*
|
||||
* 函数功能:LCD初始化
|
||||
* 入口参数:无
|
||||
* 返回值:无
|
||||
* 函数说明:初始化ST7735S屏幕,包括SPI、GPIO、显示参数配置
|
||||
*/
|
||||
void st7735s_init(void);
|
||||
|
||||
/*
|
||||
* 函数功能:设置显示窗口
|
||||
* 入口参数:x1 - 起始列
|
||||
* y1 - 起始行
|
||||
* x2 - 结束列
|
||||
* y2 - 结束行
|
||||
* 返回值:无
|
||||
* 函数说明:设置后续写入操作的窗口区域
|
||||
*/
|
||||
void st7735s_set_window(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
|
||||
/*
|
||||
* 函数功能:填充矩形区域
|
||||
* 入口参数:x1 - 起始列
|
||||
* y1 - 起始行
|
||||
* x2 - 结束列
|
||||
* y2 - 结束行
|
||||
* color - 填充颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:用指定颜色填充矩形区域
|
||||
*/
|
||||
void st7735s_fill_rect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||
|
||||
/*
|
||||
* 函数功能:全屏填充
|
||||
* 入口参数:color - 填充颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:用指定颜色填充整个屏幕
|
||||
*/
|
||||
void st7735s_fill_screen(uint16_t color);
|
||||
|
||||
/*
|
||||
* 函数功能:画点
|
||||
* 入口参数:x - 列坐标
|
||||
* y - 行坐标
|
||||
* color - 颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:在指定位置画一个点
|
||||
*/
|
||||
void st7735s_draw_pixel(uint16_t x, uint16_t y, uint16_t color);
|
||||
|
||||
/*
|
||||
* 函数功能:画线
|
||||
* 入口参数:x1 - 起始列
|
||||
* y1 - 起始行
|
||||
* x2 - 结束列
|
||||
* y2 - 结束行
|
||||
* color - 颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:画一条直线(Bresenham算法)
|
||||
*/
|
||||
void st7735s_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||
|
||||
/*
|
||||
* 函数功能:画矩形
|
||||
* 入口参数:x - 左上角列
|
||||
* y - 左上角行
|
||||
* width - 宽度
|
||||
* height - 高度
|
||||
* color - 颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:画一个空心矩形
|
||||
*/
|
||||
void st7735s_draw_rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
|
||||
|
||||
/*
|
||||
* 函数功能:画圆
|
||||
* 入口参数:x0 - 圆心列
|
||||
* y0 - 圆心行
|
||||
* radius - 半径
|
||||
* color - 颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:画一个空心圆(Bresenham算法)
|
||||
*/
|
||||
void st7735s_draw_circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color);
|
||||
|
||||
/*
|
||||
* 函数功能:显示字符
|
||||
* 入口参数:x - 列坐标
|
||||
* y - 行坐标
|
||||
* ch - 字符 (ASCII 32-126)
|
||||
* color - 字符颜色 (RGB565)
|
||||
* bg_color - 背景颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:在指定位置显示一个8x16 ASCII字符
|
||||
*/
|
||||
void st7735s_draw_char(uint16_t x, uint16_t y, char ch, uint16_t color, uint16_t bg_color);
|
||||
|
||||
/*
|
||||
* 函数功能:显示字符串
|
||||
* 入口参数:x - 列坐标
|
||||
* y - 行坐标
|
||||
* str - 字符串指针
|
||||
* color - 字符颜色 (RGB565)
|
||||
* bg_color - 背景颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:在指定位置显示字符串
|
||||
*/
|
||||
void st7735s_draw_string(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bg_color);
|
||||
|
||||
/*
|
||||
* 函数功能:设置屏幕方向
|
||||
* 入口参数:rotation - 方向 (0-3)
|
||||
* 返回值:无
|
||||
* 函数说明:设置屏幕显示方向
|
||||
* 0: 竖屏
|
||||
* 1: 横屏
|
||||
* 2: 竖屏反转
|
||||
* 3: 横屏反转
|
||||
*/
|
||||
void st7735s_set_rotation(uint8_t rotation);
|
||||
|
||||
/*
|
||||
* 函数功能:设置背光
|
||||
* 入口参数:state - 1:开 0:关
|
||||
* 返回值:无
|
||||
* 函数说明:控制LCD背光(如有硬件背光控制)
|
||||
*/
|
||||
void st7735s_backlight(uint8_t state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ST7735S_H */
|
||||
Reference in New Issue
Block a user