液晶型号:JLX12864G-290-PN不带字库
芯片型号:STM32F030F4
SPI连接方式:IO口模拟
STM32CubeMX 中引脚设置
JLX12864G_290_PN.h文件
#ifndef __JLX12864G_290_PN_H__
#define __JLX12864G_290_PN_H__
/* 包含头文件 ----------------------------------------------------------------*/
#include "stm32f0xx_hal.h"
/* 类型定义 --------------------------------------------------------------*/
/* 宏定义 --------------------------------------------------------------------*/
//#define uchar unsigned char
//#define uint unsigned int
//#define ulong unsigned long
#define CS_H HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET) // 输出高电平
#define CS_L HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET) // 输出低电平
#define RST_H HAL_GPIO_WritePin(RST_GPIO_Port,RST_Pin,GPIO_PIN_SET) // 输出高电平
#define RST_L HAL_GPIO_WritePin(RST_GPIO_Port,RST_Pin,GPIO_PIN_RESET) // 输出低电平
#define RS_H HAL_GPIO_WritePin(RS_GPIO_Port,RS_Pin,GPIO_PIN_SET) // 输出高电平
#define RS_L HAL_GPIO_WritePin(RS_GPIO_Port,RS_Pin,GPIO_PIN_RESET) // 输出低电平
#define SDA_H HAL_GPIO_WritePin(SDA_GPIO_Port,SDA_Pin,GPIO_PIN_SET) // 输出高电平
#define SDA_L HAL_GPIO_WritePin(SDA_GPIO_Port,SDA_Pin,GPIO_PIN_RESET) // 输出低电平
#define SCK_H HAL_GPIO_WritePin(SCK_GPIO_Port,SCK_Pin,GPIO_PIN_SET) // 输出高电平
#define SCK_L HAL_GPIO_WritePin(SCK_GPIO_Port,SCK_Pin,GPIO_PIN_RESET) // 输出低电平
/* 扩展变量 ------------------------------------------------------------------*/
/* 函数声明 ------------------------------------------------------------------*/
//void delay(int i);
void delay_us(uint8_t i);
void transfer_command(uint8_t data1);
void transfer_data(uint8_t data1);
void initial_lcd(void);
void lcd_address(uint8_t page,uint8_t column);
void clear_screen(void);
void full_display(uint8_t data_left,uint8_t data_right);
void display_graphic_32x32(uint8_t page,uint8_t column,uint8_t *dp);
void display_graphic_16x16(uint8_t page,uint8_t column,uint8_t reverse,uint8_t *dp);
void display_graphic_8x16(uint8_t page,uint8_t column,uint8_t *dp);
void display_string_8x16(uint16_t page,uint16_t column,uint8_t *text);
void display_string_5x7(uint16_t page,uint16_t column,uint8_t *text);
void disp_grap(uint8_t page,uint8_t column,uint8_t *dp);
#endif // __JLX12864G_290_PN_H__
JLX12864G_290_PN.C文件
#include "JLX12864G_290_PN/JLX12864G_290_PN.H"
uint8_t ascii_table_8x16[95][16];
uint8_t ascii_table_5x7[95][5];
uint8_t cheng1[]={
/*-- 文字: 成 --*/
/*-- 宋体 23; 此字体下对应的点阵为:宽 x 高=31x31 --*/
/*-- 高度不是 8 的倍数,现调整为:宽度 x 高度=32x32 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,
0xFC,0xFC,0x88,0x00,0x00,0x1C,0x78,0xF0,0xE0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFF,0x83,0x83,0x83,0x83,0x83,0x83,0xC3,0xC3,0x03,0x1F,
0xFF,0xFF,0x83,0x03,0x03,0x03,0xC3,0xF3,0xF3,0x63,0x03,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0xFC,0xFF,0x3F,0x00,0x80,0x00,0x00,0x80,0xFF,0xFF,0x03,0x00,0x00,0x03,
0x9F,0xFF,0xF8,0xF8,0xBE,0x1F,0x07,0x01,0x00,0x00,0xE0,0x20,0x00,0x00,0x20,0x38,
0x1F,0x07,0x01,0x00,0x00,0x01,0x01,0x07,0x07,0x23,0x31,0x18,0x0C,0x0E,0x07,0x03,
0x01,0x01,0x01,0x03,0x07,0x0F,0x0E,0x1C,0x1F,0x3F,0x30,0x00,0x00,0x00,0x00,0x00};
uint8_t gong1[]={
/*-- 文字: 功 --*/
/*-- 宋体 23; 此字体下对应的点阵为:宽 x 高=31x31 --*/
/*-- 高度不是 8 的倍数,现调整为:宽度 x 高度=32x32 --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0xC0,0xC0,0x00,
0x00,0x00,0x00,0xFE,0xFC,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x0C,0x04,0x04,
0x04,0x84,0xFF,0xFF,0x04,0x04,0x04,0x04,0x04,0xFE,0xFE,0x04,0x00,0x00,0x00,0x00,
0xC0,0xC0,0xC0,0xC0,0xE0,0x60,0x7F,0x3F,0x30,0x30,0x10,0x18,0x18,0x88,0xC0,0xF8,
0x7F,0x1F,0x01,0x00,0x00,0x00,0x00,0xF8,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x01,
0x01,0x00,0x00,0x00,0x00,0x20,0x20,0x30,0x18,0x0C,0x0C,0x07,0x03,0x01,0x00,0x04,
0x04,0x0C,0x0C,0x1C,0x38,0x3C,0x1F,0x0F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
///*延时*/
//void delay(int i)
//{
// int j,k;
// for(j=0;j // for(k=0;k<110;k++);
//}
/*延时*/
void delay_us(uint8_t i)
{
int j,k;
for(j=0;j for(k=0;k<1;k++);
}
//void waitkey()
//{
// repeat:
// if(key==1)
// goto repeat;
// else
// HAL_Delay(1000);
//// delay(1000);
//}
/*写指令到 LCD 模块*/
void transfer_command(uint8_t data1)
{
char i;
CS_L;
RS_L;
for(i=0;i<8;i++)
{
SCK_L;
delay_us(2);
if(data1&0x80)
SDA_H;
else
SDA_L;
SCK_H;
delay_us(2);
data1=data1<<=1;
}
CS_H;
}
/*写数据到 LCD 模块*/
void transfer_data(uint8_t data1)
{
char i;
CS_L;
RS_H;
for(i=0;i<8;i++)
{
SCK_L;
delay_us(1);
if(data1&0x80)
SDA_H;
else
SDA_L;
SCK_H;
delay_us(1);
data1=data1<<=1;
}
CS_H;
}
/*LCD 模块初始化*/
void initial_lcd(void)
{
// CS_L;
RST_L; /*低电平复位*/
HAL_Delay(100);
RST_H; /*复位完毕*/
HAL_Delay(100);
transfer_command(0xe2); /*软复位*/
HAL_Delay(5);
transfer_command(0x2c); /*升压步聚 1*/
HAL_Delay(5);
transfer_command(0x2e); /*升压步聚 2*/
HAL_Delay(5);
transfer_command(0x2f); /*升压步聚 3*/
HAL_Delay(5);
transfer_command(0x24); /*粗调对比度,可设置范围 0x20~0x27*/
transfer_command(0x81); /*微调对比度*/
transfer_command(0x2a); /*0x1a,微调对比度的值,可设置范围 0x00~0x3f*/
transfer_command(0xa2); /*1/9 偏压比(bias)*/
transfer_command(0xc8); /*行扫描顺序:从上到下*/
transfer_command(0xa0); /*列扫描顺序:从左到右*/
transfer_command(0x40); /*起始行:第一行开始*/
transfer_command(0xaf); /*开显示*/
// CS_H;
}
void lcd_address(uint8_t page,uint8_t column)
{
column=column-1; //我们平常所说的第 1 列,在 LCD 驱动 IC 里是第 0 列。所以在这里减去 1.
page=page-1;
transfer_command(0xb0+page); //设置页地址。每页是 8 行。一个画面的 64 行被分成 8 个页。我们平常所说的第 1 页,在 LCD驱动 IC 里是第 0 页,所以在这里减去 1*/
transfer_command(((column>>4)&0x0f)+0x10); //设置列地址的高 4 位
transfer_command(column&0x0f); //设置列地址的低 4 位
}
/*全屏清屏*/
void clear_screen(void)
{
unsigned char i,j;
for(i=0;i<9;i++)
{
lcd_address(1+i,1);
for(j=0;j<132;j++)
{
transfer_data(0x00);
}
}
}
//==================display a piture of 128*64 dots================
void full_display(uint8_t data_left,uint8_t data_right)
{
int i,j;
for(i=0;i<8;i++)
{
CS_L;
lcd_address(i+1,1);
for(j=0;j<64;j++)
{
transfer_data(data_left);
transfer_data(data_right);
}
}
}
/*显示 32x32 点阵图像、汉字、生僻字或 32x32 点阵的其他图标*/
void display_graphic_32x32(uint8_t page,uint8_t column,uint8_t *dp)
{
uint8_t i,j;
for(j=0;j<4;j++)
{
lcd_address(page+j,column);
for (i=0;i<31;i++)
{
transfer_data(*dp); /*写数据到 LCD,每写完一个 8 位的数据后列地址自动加 1*/
dp++;
}
}
}
/*显示 16x16 点阵图像、汉字、生僻字或 16x16 点阵的其他图标*/
void display_graphic_16x16(uint8_t page,uint8_t column,uint8_t reverse,uint8_t *dp)
{
uint8_t i,j;
for(j=0;j<2;j++)
{
lcd_address(page+j,column);
for (i=0;i<16;i++)
{
if(reverse==1)
{
transfer_data(*dp); /*写数据到 LCD,每写完一个 8 位的数据后列地址自动加 1*/
}
else
transfer_data(~*dp);
dp++;
}
}
}
/*显示 8x16 点阵图像、ASCII, 或 8x16 点阵的自造字符、其他图标*/
void display_graphic_8x16(uint8_t page,uint8_t column,uint8_t *dp)
{
uint8_t i,j;
for(j=0;j<2;j++)
{
lcd_address(page+j,column);
for (i=0;i<8;i++)
{
transfer_data(*dp); /*写数据到 LCD,每写完一个 8 位的数据后列地址自动加 1*/
dp++;
}
}
}
void display_string_8x16(uint16_t page,uint16_t column,uint8_t *text)
{
uint16_t i=0,j,k,n;
while(text[i]>0x00)
{
if((text[i]>=0x20)&&(text[i]<=0x7e))
{
j=text[i]-0x20;
for(n=0;n<2;n++)
{
lcd_address(page+n,column);
for(k=0;k<8;k++)
{
transfer_data(ascii_table_8x16[j][k+8*n]);/*显示 5x7 的 ASCII 字到 LCD 上,y 为页地址,x 为列地址,最后为数据*/
}
}
i++;
column+=8;
}
else
i++;
}
}
void display_string_5x7(uint16_t page,uint16_t column,uint8_t *text)
{
uint16_t i=0,j,k;
while(text[i]>0x00)
{
if((text[i]>=0x20)&&(text[i]<0x7e))
{
j=text[i]-0x20;
lcd_address(page,column);
for(k=0;k<5;k++)
{
transfer_data(ascii_table_5x7[j][k]);/*显示 5x7 的 ASCII 字到 LCD 上,y 为页地址,x 为列地址,最后为数据*/
}
i++;
column+=6;
}
else
i++;
}
}
//==================display a piture of 128*64 dots================
void disp_grap(uint8_t page,uint8_t column,uint8_t *dp)
{
int i,j;
for(i=0;i<8;i++)
{
lcd_address(page+i,column);
for(j=0;j<128;j++)
{
transfer_data(*dp);
dp++;
}
}
}
main.c中写入如下代码:
效果: