12864.h

#include "main.h"                                             //不同的cubemx版本生成的不一样,自己看着调用
#include "stm32l0xx_hal.h"   
#define sck(x)  HAL_GPIO_WritePin(SCK_GPIO_Port,SCK_Pin,x)    //串行模式只需要配置3个io,需要自己初始化io
#define ds(x) HAL_GPIO_WritePin(DS_GPIO_Port,DS_Pin,x)
#define cs(x) HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,x)        
void lcm_init(void);                                                             //屏幕初始化
void displaybit(char x,char y,char data);                                        //打点函数x0-127 y0-63,data=1添加像素,data=0删除像素,data=2取反像素
void displayxypic(char x,char y,char h ,char l,const unsigned char *pic);        //显示图片 图片位置(左上角) 图片大小 图片数据
void printf_str(char x,char y ,char size,const unsigned char *data,char dismode);//任意位置显示字符串(非内部字库) 位置  size有0和1两种分别是6*8和8*16 字符串 显示模式和上面的打点一样

12864.c

#include "12864.h"    
unsigned int GRAM[8][64];       //显存,由于是单显存模式,效率有点低。。
const unsigned int xbit[]={     //用于计算int中的某一个
    0x8000,
    0x4000,
    0x2000,
    0x1000,
    0x800,
    0x400,
    0x200,
    0x100,
    0x80,
    0x40,
    0x20,
    0x10,
    0x8,
    0x4,
    0x2,
    0x1
};    
const unsigned char font[][6] = {
{0x00,0x00,0x00,0x00,0x00,0x00},// (0)
{0x00,0x00,0x00,0x4F,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,0x05,0x03,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,0x50,0x30,0x00,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,0x32,0x49,0x79,0x41,0x3E},//@(32)
{0x00,0x7E,0x11,0x11,0x11,0x7E},//A(33)
{0x00,0x7F,0x49,0x49,0x49,0x3E},//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,0x04,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,0x03,0x04,0x78,0x04,0x03},//Y(57)
{0x00,0x61,0x51,0x49,0x45,0x43},//Z(58)
{0x00,0x00,0x7F,0x41,0x41,0x00},//[(59)
{0x00,0x15,0x16,0x7C,0x16,0x15},//(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,0x0C,0x52,0x52,0x52,0x3E},//g(71)
{0x00,0x7F,0x08,0x04,0x04,0x78},//h(72)
{0x00,0x00,0x44,0x7D,0x40,0x00},//i(73)
{0x00,0x20,0x40,0x44,0x3D,0x00},//j(74)
{0x00,0x7F,0x10,0x28,0x44,0x00},//k(75)
{0x00,0x00,0x41,0x7F,0x40,0x00},//l(76)
{0x00,0x7E,0x02,0x0C,0x02,0x7C},//m(77)
{0x00,0x7E,0x04,0x02,0x02,0x7C},//n(78)
{0x00,0x38,0x44,0x44,0x44,0x38},//o(79)
{0x00,0x7C,0x14,0x14,0x14,0x08},//p(80)
{0x00,0x08,0x14,0x14,0x18,0x7C},//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,0x0C,0x50,0x50,0x50,0x3C},//y(89)
{0x00,0x44,0x64,0x54,0x4C,0x44},//z(90)
{0x00,0x00,0x08,0x36,0x41,0x00},//{(91)
{0x00,0x00,0x00,0x7F,0x00,0x00},//|(92)
{0x00,0x00,0x41,0x36,0x08,0x00},//}(93)
{0x00,0x08,0x04,0x08,0x10,0x08},//~(94)
{0x00,0x08,0x08,0x2A,0x1C,0x08},//?(127)
{0x00,0x08,0x1C,0x2A,0x08,0x08},//?(128)
{0x00,0x04,0x02,0x7F,0x02,0x04},//?(129)
{0x00,0x10,0x20,0x7F,0x20,0x10},//?(130)
{0x00,0x1C,0x2A,0x32,0x2A,0x1C},//??(131)
{0x00,0x1C,0x22,0x44,0x22,0x1C},//??(132)
{0x00,0x11,0x0a,0x04,0x0a,0x11},//><(133)
{0x00,0x07,0x05,0x07,0x00,0x00},//?(134)
};    
const unsigned char font_big[][16] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},// (0)
{0x00,0x00,0x38,0xFC,0xFC,0x38,0x00,0x00,0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00},//!(1)
{0x00,0x0E,0x1E,0x00,0x00,0x1E,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//"(2)
{0x20,0xF8,0xF8,0x20,0xF8,0xF8,0x20,0x00,0x02,0x0F,0x0F,0x02,0x0F,0x0F,0x02,0x00},//#(3)
{0x38,0x7C,0x44,0x47,0x47,0xCC,0x98,0x00,0x03,0x06,0x04,0x1C,0x1C,0x07,0x03,0x00},//$(4)
{0x30,0x30,0x00,0x80,0xC0,0x60,0x30,0x00,0x0C,0x06,0x03,0x01,0x00,0x0C,0x0C,0x00},//%(5)
{0x80,0xD8,0x7C,0xE4,0xBC,0xD8,0x40,0x00,0x07,0x0F,0x08,0x08,0x07,0x0F,0x08,0x00},//&(6)
{0x00,0x10,0x1E,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//'(7)
{0x00,0x00,0xF0,0xF8,0x0C,0x04,0x00,0x00,0x00,0x00,0x03,0x07,0x0C,0x08,0x00,0x00},//((8)
{0x00,0x00,0x04,0x0C,0xF8,0xF0,0x00,0x00,0x00,0x00,0x08,0x0C,0x07,0x03,0x00,0x00},//)(9)
{0x80,0xA0,0xE0,0xC0,0xC0,0xE0,0xA0,0x80,0x00,0x02,0x03,0x01,0x01,0x03,0x02,0x00},//*(10)
{0x00,0x80,0x80,0xE0,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00},//+(11)
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x1E,0x0E,0x00,0x00,0x00},//,(12)
{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//-(13)
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00},//.(14)
{0x00,0x00,0x00,0x80,0xC0,0x60,0x30,0x00,0x0C,0x06,0x03,0x01,0x00,0x00,0x00,0x00},///(15)
{0xF8,0xFC,0x04,0xC4,0x24,0xFC,0xF8,0x00,0x07,0x0F,0x09,0x08,0x08,0x0F,0x07,0x00},//0(16)
{0x00,0x10,0x18,0xFC,0xFC,0x00,0x00,0x00,0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00},//1(17)
{0x08,0x0C,0x84,0xC4,0x64,0x3C,0x18,0x00,0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0C,0x00},//2(18)
{0x08,0x0C,0x44,0x44,0x44,0xFC,0xB8,0x00,0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00},//3(19)
{0xC0,0xE0,0xB0,0x98,0xFC,0xFC,0x80,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00},//4(20)
{0x7C,0x7C,0x44,0x44,0xC4,0xC4,0x84,0x00,0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00},//5(21)
{0xF0,0xF8,0x4C,0x44,0x44,0xC4,0x80,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00},//6(22)
{0x0C,0x0C,0x04,0x84,0xC4,0x7C,0x3C,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00},//7(23)
{0xB8,0xFC,0x44,0x44,0x44,0xFC,0xB8,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00},//8(24)
{0x38,0x7C,0x44,0x44,0x44,0xFC,0xF8,0x00,0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00},//9(25)
{0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00,0x00},//:(26)
{0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x08,0x0E,0x06,0x00,0x00,0x00},//;(27)
{0x00,0x80,0xC0,0x60,0x30,0x18,0x08,0x00,0x00,0x00,0x01,0x03,0x06,0x0C,0x08,0x00},//<(28)
{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00},//=(29)
{0x00,0x08,0x18,0x30,0x60,0xC0,0x80,0x00,0x00,0x08,0x0C,0x06,0x03,0x01,0x00,0x00},//>(30)
{0x18,0x1C,0x04,0xC4,0xE4,0x3C,0x18,0x00,0x00,0x00,0x00,0x0D,0x0D,0x00,0x00,0x00},//?(31)
{0xF0,0xF8,0x08,0xC8,0x48,0xF8,0xF0,0x00,0x07,0x0F,0x08,0x0B,0x0B,0x0B,0x01,0x00},//@(32)
{0xE0,0xF0,0x98,0x8C,0x98,0xF0,0xE0,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00},//A(33)
{0x04,0xFC,0xFC,0x44,0x44,0xFC,0xB8,0x00,0x08,0x0F,0x0F,0x08,0x08,0x0F,0x07,0x00},//B(34)
{0xF0,0xF8,0x0C,0x04,0x04,0x0C,0x18,0x00,0x03,0x07,0x0C,0x08,0x08,0x0C,0x06,0x00},//C(35)
{0x04,0xFC,0xFC,0x04,0x0C,0xF8,0xF0,0x00,0x08,0x0F,0x0F,0x08,0x0C,0x07,0x03,0x00},//D(36)
{0x04,0xFC,0xFC,0x44,0xE4,0x0C,0x1C,0x00,0x08,0x0F,0x0F,0x08,0x08,0x0C,0x0E,0x00},//E(37)
{0x04,0xFC,0xFC,0x44,0xE4,0x0C,0x1C,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00},//F(38)
{0xF0,0xF8,0x0C,0x84,0x84,0x8C,0x98,0x00,0x03,0x07,0x0C,0x08,0x08,0x07,0x0F,0x00},//G(39) 
{0xFC,0xFC,0x40,0x40,0x40,0xFC,0xFC,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00},//H(40)
{0x00,0x00,0x04,0xFC,0xFC,0x04,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00},//I(41)
{0x00,0x00,0x00,0x04,0xFC,0xFC,0x04,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,0x00},//J(42)
{0x04,0xFC,0xFC,0xC0,0xF0,0x3C,0x0C,0x00,0x08,0x0F,0x0F,0x00,0x01,0x0F,0x0E,0x00},//K(43)
{0x04,0xFC,0xFC,0x04,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x08,0x0C,0x0E,0x00},//L(44)
{0xFC,0xFC,0x38,0x70,0x38,0xFC,0xFC,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00},//M(45)
{0xFC,0xFC,0x38,0x70,0xE0,0xFC,0xFC,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00},//N(46)
{0xF0,0xF8,0x0C,0x04,0x0C,0xF8,0xF0,0x00,0x03,0x07,0x0C,0x08,0x0C,0x07,0x03,0x00},//O(47)
{0x04,0xFC,0xFC,0x44,0x44,0x7C,0x38,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00},//P(48)
{0xF8,0xFC,0x04,0x04,0x04,0xFC,0xF8,0x00,0x07,0x0F,0x08,0x0E,0x3C,0x3F,0x27,0x00},//Q(49)
{0x04,0xFC,0xFC,0x44,0xC4,0xFC,0x38,0x00,0x08,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00},//R(50)
{0x18,0x3C,0x64,0x44,0xC4,0x9C,0x18,0x00,0x06,0x0E,0x08,0x08,0x08,0x0F,0x07,0x00},//S(51)
{0x00,0x1C,0x0C,0xFC,0xFC,0x0C,0x1C,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00},//T(52)
{0xFC,0xFC,0x00,0x00,0x00,0xFC,0xFC,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00},//U(53)
{0xFC,0xFC,0x00,0x00,0x00,0xFC,0xFC,0x00,0x01,0x03,0x06,0x0C,0x06,0x03,0x01,0x00},//V(54)
{0xFC,0xFC,0x00,0x80,0x00,0xFC,0xFC,0x00,0x03,0x0F,0x0E,0x03,0x0E,0x0F,0x03,0x00},//W(55)
{0x0C,0x3C,0xF0,0xC0,0xF0,0x3C,0x0C,0x00,0x0C,0x0F,0x03,0x00,0x03,0x0F,0x0C,0x00},//X(56)
{0x00,0x3C,0x7C,0xC0,0xC0,0x7C,0x3C,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00},//Y(57)
{0x1C,0x0C,0x84,0xC4,0x64,0x3C,0x1C,0x00,0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0E,0x00},//Z(58)
{0x00,0x00,0xFC,0xFC,0x04,0x04,0x00,0x00,0x00,0x00,0x0F,0x0F,0x08,0x08,0x00,0x00},//[(59)
{0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x00},//(60)
{0x00,0x00,0x04,0x04,0xFC,0xFC,0x00,0x00,0x00,0x00,0x08,0x08,0x0F,0x0F,0x00,0x00},//](61)
{0x08,0x0C,0x06,0x03,0x06,0x0C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//^(62)
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20},//_(63)
{0x00,0x10,0x1E,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//'(64)
{0x00,0xA0,0xA0,0xA0,0xE0,0xC0,0x00,0x00,0x07,0x0F,0x08,0x08,0x07,0x0F,0x08,0x00},//a(65)
{0x04,0xFC,0xFC,0x20,0x60,0xC0,0x80,0x00,0x08,0x0F,0x07,0x08,0x08,0x0F,0x07,0x00},//b(66)
{0xC0,0xE0,0x20,0x20,0x20,0x60,0x40,0x00,0x07,0x0F,0x08,0x08,0x08,0x0C,0x04,0x00},//c(67)
{0x80,0xC0,0x60,0x24,0xFC,0xFC,0x00,0x00,0x07,0x0F,0x08,0x08,0x07,0x0F,0x08,0x00},//d(68)
{0xC0,0xE0,0xA0,0xA0,0xA0,0xE0,0xC0,0x00,0x07,0x0F,0x08,0x08,0x08,0x0C,0x04,0x00},//e(69)
{0x40,0xF8,0xFC,0x44,0x0C,0x18,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00},//f(70)
{0xC0,0xE0,0x20,0x20,0xC0,0xE0,0x20,0x00,0x27,0x6F,0x48,0x48,0x7F,0x3F,0x00,0x00},//g(71)
{0x04,0xFC,0xFC,0x40,0x20,0xE0,0xC0,0x00,0x08,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00},//h(72)
{0x00,0x00,0x20,0xEC,0xEC,0x00,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00},//i(73)
{0x00,0x00,0x00,0x00,0x20,0xEC,0xEC,0x00,0x00,0x30,0x70,0x40,0x40,0x7F,0x3F,0x00},//j(74)
{0x04,0xFC,0xFC,0x80,0xC0,0x60,0x20,0x00,0x08,0x0F,0x0F,0x01,0x03,0x0E,0x0C,0x00},//k(75)
{0x00,0x00,0x04,0xFC,0xFC,0x00,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00},//l(76)
{0xE0,0xE0,0x60,0xC0,0x60,0xE0,0xC0,0x00,0x0F,0x0F,0x00,0x0F,0x00,0x0F,0x0F,0x00},//m(77)
{0x20,0xE0,0xC0,0x20,0x20,0xE0,0xC0,0x00,0x00,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00},//n(78)
{0xC0,0xE0,0x20,0x20,0x20,0xE0,0xC0,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00},//o(79)
{0x20,0xE0,0xC0,0x20,0x20,0xE0,0xC0,0x00,0x40,0x7F,0x7F,0x48,0x08,0x0F,0x07,0x00},//p(80)
{0xC0,0xE0,0x20,0x20,0xC0,0xE0,0x20,0x00,0x07,0x0F,0x08,0x48,0x7F,0x7F,0x40,0x00},//q(81)
{0x20,0xE0,0xC0,0x60,0x20,0x60,0xC0,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00},//r(82)
{0x40,0xE0,0xA0,0x20,0x20,0x60,0x40,0x00,0x04,0x0C,0x09,0x09,0x0B,0x0E,0x04,0x00},//s(83)
{0x20,0x20,0xF8,0xFC,0x20,0x20,0x00,0x00,0x00,0x00,0x07,0x0F,0x08,0x0C,0x04,0x00},//t(84)
{0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00,0x00,0x07,0x0F,0x08,0x08,0x07,0x0F,0x08,0x00},//u(85)
{0x00,0xE0,0xE0,0x00,0x00,0xE0,0xE0,0x00,0x00,0x03,0x07,0x0C,0x0C,0x07,0x03,0x00},//v(86)
{0xE0,0xE0,0x00,0x00,0x00,0xE0,0xE0,0x00,0x07,0x0F,0x0C,0x07,0x0C,0x0F,0x07,0x00},//w(87)
{0x20,0x60,0xC0,0x80,0xC0,0x60,0x20,0x00,0x08,0x0C,0x07,0x03,0x07,0x0C,0x08,0x00},//x(88)
{0xE0,0xE0,0x00,0x00,0x00,0xE0,0xE0,0x00,0x47,0x4F,0x48,0x48,0x68,0x3F,0x1F,0x00},//y(89)
{0x60,0x60,0x20,0xA0,0xE0,0x60,0x20,0x00,0x0C,0x0E,0x0B,0x09,0x08,0x0C,0x0C,0x00},//z(90)    
};     
void sendbyte(unsigned char bbyte) 
{
    unsigned char i;
    cs(1);
    for(i=0;i<8;i++)
    {
        if(bbyte&0x80)
        {
            ds(1);
        }else
        {
            ds(0);
        }    
        sck(1);        
        sck(0);
        bbyte<<=1; //laft
    }
    cs(0);    
}    
// start=0 mod start=1 data
void lcm_w_test(char start, unsigned char ddata) 
{
    unsigned char start_data,Hdata,Ldata;
    if(start==0) 
    start_data=0xf8;//to mod
    else 
    start_data=0xfa;//to data    
    Hdata=ddata&0xf0;
    Ldata=(ddata<<4)&0xf0;
    sendbyte(start_data);    
    sendbyte(Hdata); 
    sendbyte(Ldata);
}    
void displayint(char x,char y,int data)
{
//lcm_w_test(0,0x34);
lcm_w_test(0,0x36);      
    if(y>=32)
    {
        lcm_w_test(0,0x80+(y-32));
        lcm_w_test(0,0x80+x+8);
        lcm_w_test(1,data>>8);
        lcm_w_test(1,data);
    }else
    {
        lcm_w_test(0,0x80+y);
        lcm_w_test(0,0x80+x);
        lcm_w_test(1,data>>8);
        lcm_w_test(1,data);
    }
    GRAM[x][y]=data;    
}    
void displayclr()
{    
    char x, y;    
    for(y=0; y<64; y++)
    {
        for(x=0; x<8; x++)
        {
                        displayint(x,y,0);
        }
    }

}
void displaybit(char x,char y,char data)
{
    char xc,xb;
    xc=x/16;
    xb=x%16;
    if(data==0)
    {
    displayint(xc,y,(~xbit[xb])&GRAM[xc][y]);
    }
    if(data==1)
    {
    displayint(xc,y,xbit[xb]|GRAM[xc][y]);
    }
    if(data==2)
    {
        if(xbit[xb]&GRAM[xc][y])
        {
            displayint(xc,y,(~xbit[xb])&GRAM[xc][y]);
        }else
        {
            displayint(xc,y,xbit[xb]|GRAM[xc][y]);
        }
    }
}

void displayxypic(char x,char y,char h ,char l,const unsigned char *pic)
{
    int z=0;
    char a,xb=0,yb=0,data;


            while(!(yb==l))
            {
                    while(!(xb>=h))
                    {
                        data=pic[z];
                        for(a=0;a<8;a++)
                        {
                            if(data&0x80)
                            {
                                displaybit(xb+x,yb+y,1);
                            }
                                data=data<<1;
                                xb+=1;
                        }
                        z+=1;
                    }
                    xb=0;
                    yb+=1;
            }

}

void displayfont(char x,char y ,char size,const unsigned char *data,char dismode)
{
    char xb,yb,cont,z=0;
    if(size==0)
    {
        for(xb=0;xb<6;xb++)
        {
            cont=data[xb];
            for(yb=0;yb<8;yb++)
            {
                if(cont&0x01)
                {
                    if(dismode==2)
                    {
                    displaybit(xb+x,yb+y,2);
                    }else
                    {
                    displaybit(xb+x,yb+y,1);
                    }
                }else
                {
                    if(dismode==1)
                    {
                    displaybit(xb+x,yb+y,0);
                    }

                }
                cont>>=1;
            }
        }
    }
    if(size==1)
    {
        for(xb=0;xb<8;xb++)
        {
            cont=data[z];
            for(yb=0;yb<8;yb++)
            {
                if(cont&0x01)
                {
                    if(dismode==2)
                    {
                    displaybit(xb+x,yb+y,2);
                    }else
                    {
                    displaybit(xb+x,yb+y,1);
                    }
                }else
                {
                    if(dismode==1)
                    {
                    displaybit(xb+x,yb+y,0);
                    }

                }
                cont>>=1;

            }
            z+=1;
        }
        for(xb=0;xb<8;xb++)
        {
            cont=data[z];
            for(yb=0;yb<8;yb++)
            {
                if(cont&0x01)
                {
                    if(dismode==2)
                    {
                    displaybit(xb+x,yb+y+8,2);
                    }else
                    {
                    displaybit(xb+x,yb+y+8,1);
                    }
                }else
                {
                    if(dismode==1)
                    {
                    displaybit(xb+x,yb+y+8,0);
                    }

                }
                cont>>=1;

            }
            z+=1;
        }
        z=0;
    }
    if(size==2)
    {
        for(xb=0;xb<12;xb++)
        {
            cont=data[z];
            for(yb=0;yb<8;yb++)
            {
                if(cont&0x01)
                {
                    if(dismode==2)
                    {
                    displaybit(xb+x,yb+y,2);
                    }else
                    {
                    displaybit(xb+x,yb+y,1);
                    }
                }else
                {
                    if(dismode==1)
                    {
                    displaybit(xb+x,yb+y,0);
                    }

                }
                cont>>=1;

            }
            z+=1;
        }
        for(xb=0;xb<12;xb++)
        {
            cont=data[z];
            for(yb=0;yb<8;yb++)
            {
                if(cont&0x01)
                {
                    if(dismode==2)
                    {
                    displaybit(xb+x,yb+y+8,2);
                    }else
                    {
                    displaybit(xb+x,yb+y+8,1);
                    }
                }else
                {
                    if(dismode==1)
                    {
                    displaybit(xb+x,yb+y+8,0);
                    }

                }
                cont>>=1;

            }
            z+=1;
        }
        z=0;
    }
}
    
void printf_str(char x,char y ,char size,const unsigned char *data,char dismode)
{
    char xx,yy,fo;
    xx=x;
    yy=y;

    while(*data != '')
    {
        if(size==0)
        {
            fo=*data++;
            fo-=32;
            displayfont(xx,yy,size,font[fo],dismode);
            xx+=6;

        }
        if(size==1)
        {
            fo=*data++;
            fo-=32;
            displayfont(xx,yy,size,font_big[fo],dismode);
            xx+=8;

        }
    }
}

void lcm_init(void)
{
    HAL_Delay(200); 
    lcm_w_test(0,0x30);
    lcm_w_test(0,0x0c);
    lcm_w_test(0,0x01);
    HAL_Delay(200);
    displayclr();
}
最后修改:2020 年 06 月 28 日 03 : 52 PM
声明:无闻风博客|版权所有,违者必究|如未注明,均为原创| 转载:转载请注明原文链接