【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)

目录

  • 硬知识
    • LCD12864简介
      • 主控芯片ST7920的功能是:
      • 驱动芯片ST7921的功能是:
    • 引脚功能
    • 时序
      • 并行通信
      • 串行通信
    • 指令
    • 存储结构
    • 操作
    • 取模软件的配置
  • 示例程序
    • st7920.c
    • st7920.h
    • 测试程序
      • 显示图片
        • 图片1
          • 实验现象
        • 图片2
          • 实验现象
      • 显示字符
        • 英文
          • 实验现象
        • 中文
          • 实验现象
  • Proteus的仿真

普中51-单核-A2
STC89C52
Windows 10 20H2
Proteus 8 Frofessional v8.9 SP2
Keil uVision V5.29.0.0
PK51 Prof.Developers Kit Version:9.60.0.0


       移植自发布一个ST7920的LCD12864 Proteus仿真模型,支持串口和4bit模式通讯 —— cdhigh
       参考资料:《LCD12864液晶显示模块数据手册(带字库)》

硬知识

LCD12864简介

       LCD12864液晶屏,背面3个COB牛屎堆,一个主控芯片ST7920,另外两个是移位芯片ST7921.

主控芯片ST7920的功能是:

  1. 与我们的单片机并行通信。
  2. 字库ROM、CGROM,DDRAM等。
  3. 行扫描COM0 ~ COM31…
  4. 列扫描SEG0 ~ SEG63…
  5. 串行方式发送数据到两片ST7921驱动芯片。

驱动芯片ST7921的功能是:

  1. 接收来自ST7920的串行信号,转化成并口驱动电压。
  2. 根据信号要求,两片芯片分别驱动SEG64~ SEG159,SEG160~ SEG255

       LCD12864它本质上是256x32点的矩阵屏,32行扫描是COM0-COM31,列字节是SEG0-SEG255总共32字节,每个字节8bit,总共256位。.
       原本左右拼接的256x32点,变成了上下拼接的128x64点。如下图所示:
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第1张图片

引脚功能

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第2张图片

时序

并行通信

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第3张图片

串行通信

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第4张图片

指令

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第5张图片
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第6张图片
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第7张图片

存储结构

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第8张图片
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第9张图片
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第10张图片

操作

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第11张图片

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第12张图片

uint8_t code LCD12864_Write_CGRAM[]=
{
     
0x60,0x00,0x91,0xF4,0x96,0x0C,0x6C,0x04,
0x08,0x04,0x18,0x00,0x18,0x00,0x18,0x00,
0x18,0x00,0x18,0x00,0x18,0x00,0x08,0x00,
0x0C,0x04,0x06,0x08,0x01,0xF0,0x00,0x00
};//温度符号的 32 个字节字模

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第13张图片

取模软件的配置

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第14张图片

示例程序

VSS		——	GND
VDD		——	VCC(5V or 3.3V)
V0			亮度调节 
CS(RS)	——	接VCC,持续高电平,一直选通。
MOSI(R/W)——	接MOSI
SCLK(E)	——	接SCLK
PSB		——	接GND  串行模式
BLA		——	VCC(5V or 3.3V)
BLK		——	接GND			
剩余引脚不接,留空

       stdint.h见【51单片机快速入门指南】1:基础知识和工程创建
       软件SPI程序见【51单片机快速入门指南】5:软件SPI
       SPI选择模式3。
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第15张图片
根据电路修改Software_SPI.h
在这里插入图片描述
模式选择在st7920.h
在这里插入图片描述

st7920.c

//ST7920 LCD 驱动
#include "st7920.h"
#include "./Software_SPI/Software_SPI.h"

void delay_ms(int i);

void st7920_delay()
{
     

}

void LCD12864_CS_H()	//若SPI总线上只有屏幕,则可接VCC
{
     
	LCD12864_CS = 1;
}

void LCD12864_CS_L()
{
     
	LCD12864_CS = 0;
}

void LCD12864_PSB_L()	//接GND或给低电平以实现SPI通讯
{
     
	LCD12864_PSB = 0;
}

void LCD12864_RS_H()
{
     
	RS_Pin = 1;
}

void LCD12864_RS_L()
{
     
	RS_Pin = 0;
}

void LCD12864_WR_H()
{
     
	WR_Pin = 1;
}

void LCD12864_WR_L()
{
     
	WR_Pin = 0;
}

void LCD12864_EN_H()
{
     
	EN_Pin = 1;
}

void LCD12864_EN_L()
{
     
	EN_Pin = 0;
}

uint8_t LCD12864_Port_Read()
{
     
	return LCD12864_Port;
}

//并口模式下写八位
void LCD12864_Port_Write_8B(uint8_t Data)
{
     
	LCD12864_Port = Data;
}

//4位模式下写半个字节(高4位)
void LCD12864_Port_Write_4B(uint8_t Data)
{
     
	LCD12864_Port &= 0x0F;
	LCD12864_Port |= Data;
}

//初始化
void LCD_init(void)
{
     
#if LCD_INTERFACE == MODE_SPI
	LCD12864_PSB_L();
#endif
    delay_ms(50);
    LCD_write_command(0x33);
    delay_ms(1);
    LCD_write_command(0x32);
    delay_ms(1);
#if LCD_INTERFACE == MODE_4BIT
    LCD_write_command(0x28);
    delay_ms(1);
    LCD_write_command(0x28);
    delay_ms(1);
#endif
    LCD_write_command(0x08);  //显示关
    delay_ms(1);             //大于100uS的延时程序
    LCD_write_command(0x10);  //光标设置
    delay_ms(1);             //大于100uS的延时程序
    LCD_write_command(0x0C);  //显示开
    delay_ms(1);             //大于100uS的延时程序
    LCD_write_command(0x01);  //Display Clear
    delay_ms(10);            //大于10mS的延时程序
    LCD_write_command(0x06);  //光标从右向左加1位移动
    delay_ms(10);            //大于10mS的延时程序
}

//写命令
void LCD_write_command(unsigned char command)
{
     
#if LCD_INTERFACE == MODE_SPI
    LCD2_spi_write_byte(0xf8);
	st7920_delay();
    LCD2_spi_write_byte_standard(command);
#else
    LCD12864_RS_L();   //RS=0
    LCD_write_byte(command);
    delay_ms(1);
#endif
}

//写数据
void LCD_write_data(unsigned char Data)
{
     
#if LCD_INTERFACE == MODE_SPI
    LCD2_spi_write_byte(0xfa);
	st7920_delay();
    LCD2_spi_write_byte_standard(Data);
#else
    LCD12864_RS_H();    //RS=1
    LCD_write_byte(Data);
#endif
}

//并口模式写一个字节到控制器
void LCD_write_byte(unsigned char Data)
{
     
#if LCD_INTERFACE == MODE_4BIT
    LCD_write_half_byte(Data);
    Data <<= 4;
    LCD_write_half_byte(Data);
#else
	LCD12864_Port_Write_8B(Data);
    LCD12864_WR_L();
    LCD12864_EN_H();     //EN端产生一个由低电平变高电平,写LCD
    st7920_delay();
    LCD12864_EN_L();      //EN端产生一个由高电平变低电平,写LCD
    st7920_delay();
    LCD12864_WR_H();
#endif
}

//4位模式下写半个字节(高4位)
void LCD_write_half_byte(unsigned char half_byte)
{
     
	LCD12864_Port_Write_4B(half_byte);
    LCD12864_WR_L();
    LCD12864_EN_H();         //EN端产生一个由低电平变高电平,写LCD
    st7920_delay();
    LCD12864_EN_L();          //EN端产生一个由高电平变低电平,写LCD
    st7920_delay(); 
    LCD12864_WR_H();
}

//串行模式下写一个字节
void LCD2_spi_write_byte(unsigned char Data)
{
     
	LCD12864_CS_H();
	SOFT_SPI_RW_MODE3(Data);
	LCD12864_CS_L();
}

//标准处理,一个字节要拆成两个字节发送
void LCD2_spi_write_byte_standard(unsigned char Data)
{
     
    LCD2_spi_write_byte(Data & 0xf0);
    LCD2_spi_write_byte((Data << 4) & 0xf0);
}

//并口模式下读数据
unsigned char LCD_read_data(void)
{
     
    unsigned char Data;

    LCD12864_RS_H();
    Data = LCD_read_byte();

#if LCD_INTERFACE == MODE_4BIT
    Data = (Data & 0xf0) | ((LCD_read_byte() >> 4) & 0x0f);
#endif
    return Data;
}

//并口模式下读状态
unsigned char LCD_read_status(void)
{
     
    unsigned char Data;
    LCD12864_RS_L();
    Data = LCD_read_byte();
#if LCD_INTERFACE == MODE_4BIT
    Data = (Data & 0xf0) | ((LCD_read_byte() >> 4) & 0x0f);
#endif
    return Data;
}

//并口模式下读一个字节,如果是4bit模式,则只有高4位是有效的
unsigned char LCD_read_byte(void)
{
     
    unsigned char Data;
    LCD12864_WR_H();
    
    LCD12864_EN_L();         //EN端产生上升沿,ST7920开始输出数据
    st7920_delay();
    LCD12864_EN_H();
    st7920_delay();

    Data = LCD12864_Port_Read();
    LCD12864_EN_L();
    return Data;
}

//设置字符模式的地址
//第一行首地址:0x80
//第二行首地址:0x80+0x10 (0x90)
//第三行首地址:0x80+0x08 (0x88)
//第四行首地址:0x80+0x10+0x08 (0x98)
void LCD_set_text_address(unsigned int rowCol)
{
     
    unsigned char start = 0x80;
    unsigned char row = (rowCol >> 8) & 0xff;
    unsigned char col = rowCol & 0xff;

    if (row == 1) {
     
        start = 0x90;
    }
    if (row == 2) {
     
        start = 0x88;
    }
    if (row == 3) {
     
        start = 0x98;
    }
    LCD_write_command(start + col);
}

//将字符模式的行列号转换为内部的XY坐标,返回的高字节为X,低字节为Y
//row (HIGH_BYTE(rowCol)): 行号,0-3
//col (LOW_BYTE(rowCol)): 列号,0-7
unsigned int LCD_rowCol_to_inter_Xy(unsigned int rowCol)
{
     
    unsigned char row = (rowCol >> 8) & 0x03;
    unsigned char col = rowCol & 0x07;
    unsigned char x = col + 8 * (unsigned char)(row / 2);
    unsigned char y = (row * 16) & 0x1f;
    return (x << 8) | y;
}

//设置绘图模式的地址
//x: 0-127 (注意x必须为16的整数倍)
//y:0-63
void LCD_set_graphic_address(unsigned char x, unsigned char y)
{
     
    unsigned char xWord, downPage, yInter;

    x &= 0x7f;
    y &= 0x3f;
    xWord = x / 16;           //内部X地址,一个地址管16位
    downPage = y / 32;        //0:上半屏 1:下半屏
    yInter = y & 0x1f;        //内部Y坐标
    
    LCD_write_command(0x80 + yInter); //先设置Y地址
    LCD_write_command(0x80 + xWord + 8 * downPage);
}

//显示清屏函数
void LCD_clear(void)
{
     
    unsigned char x, y;
    LCD_write_command(0x08);  //避免清屏过程中闪烁,先关显示
    st7920_delay();
    LCD_write_command(0x01);  //清DDRAM

    //清GDRAM,12864仅用了一半的GDRAM,清一半即可
    //如果没有使用到绘图GDRAM,也可以不清GDRAM,省点时间和代码空间
    LCD_startGraphic();
    for (y = 0; y < 32; y++)
    {
     
        LCD_write_command(0x80 + y); //y
        LCD_write_command(0x80 + 0); //x
        for (x = 0; x < 16; x++)
        {
     
            LCD_write_data(0x00);
            LCD_write_data(0x00);
        }
    }
    LCD_endGraphic();

    LCD_write_command(0x0C);  //显示开
    delay_ms(10);
}

//开启扩展命令的绘图指令
void LCD_startGraphic(void)
{
     
#if LCD_INTERFACE == MODE_4BIT
    LCD_write_command(0x24);          //扩展指令集
    LCD_write_command(0x26);          //绘图命令开启
#else
    LCD_write_command(0x34);          //扩展指令集
    LCD_write_command(0x36);          //绘图命令开启
#endif
}

//结束扩展命令的绘图指令(可选)
void LCD_endGraphic(void)
{
     
#if LCD_INTERFACE == MODE_4BIT
    LCD_write_command(0x26); //绘图命令关闭
    LCD_write_command(0x20); //回到基本指令
#else
    LCD_write_command(0x36); //绘图命令关闭
    LCD_write_command(0x30); //回到基本指令
#endif
}

//反白或取消反白对应16X16区域,一般用于菜单选择
//row (HIGH_BYTE(rowCol)): 行号,0-3
//col (LOW_BYTE(rowCol)): 列号,0-7
//charNum: 要反白的字符数量,注意不要超过行末
//ST7920内置的反白作用不大,它只能整行反白,而且反白第一行,第三行也会一起反白
//所以此函数使用另外的方法实现:绘图区对应的位全部写0xff,异或后即可反白
void LCD_Inverse_16X16(unsigned int rowCol, unsigned char charNum, unsigned char reverse)
{
     
    unsigned char i, ch;
    unsigned int xy = LCD_rowCol_to_inter_Xy(rowCol);
    unsigned char x = (xy >> 8) & 0xff;
    unsigned char y = xy & 0x3f;

    LCD_startGraphic();
    for (i = 0; i < 16; i++) //把对应字符的GDRAM全部写成0xff,异或后就是反白
    {
     
        LCD_write_command(0x80 + y + i);   //先写垂直地址y
        LCD_write_command(0x80 + x);       //x
        for (ch = 0; ch < charNum; ch++)
        {
     
            LCD_write_data(reverse ? 0xff : 0x00);
            LCD_write_data(reverse ? 0xff : 0x00);
        }
    }
    LCD_endGraphic();
}

//显示一个字符,12864可以显示4行,每行8个汉字或每行16个字母
//col: 列号,0-15
//row: 行号,0-3
//字符编码:小于0x80的为ASCII,否则为汉字,汉字编码高字节在左边
void LCD_write_char(unsigned int rowCol, unsigned int Code)
{
     
    unsigned char high = (Code >> 8) & 0xff;
    unsigned char low = Code & 0xff;
    LCD_set_text_address(rowCol);
    if (Code > 0x80)
    {
     
        LCD_write_data(high);
    }
    LCD_write_data(low);
}

//显示一个字符串,注意不要超过一行的长度(8个汉字或16个字母)
//rowCol: 左8位为行(0-3),右8位为列(0-15)
void LCD_write_string(unsigned int rowCol, const char * p)
{
     
    LCD_set_text_address(rowCol);
    while (*p != 0)
    {
     
        LCD_write_data(*p);
        p++;
    }
}

void LCD_Draw_Bmp(unsigned char *pImage, unsigned char col, unsigned char row, unsigned char x0, unsigned char y0)
{
     
    unsigned char i, y;

    LCD_startGraphic();
    
    for (y = y0; y < row + y0; y++)
    {
     
        LCD_set_graphic_address(x0, y);
        for (i = 0; i < col/8; i++)
        {
     
            LCD_write_data(*pImage);
            pImage++;
        }
    }
    
    LCD_endGraphic();
}

//只有并行接口能读ST7920,如果串行接口需要打点,则需要开辟RAM缓冲区
#if LCD_INTERFACE != MODE_SPI
//在对应X/Y位置显示一个点
void LCD_write_dot(unsigned char x, unsigned char y)
{
     
    unsigned char xBit, high, low;

    xBit = x & 0x0f;
    LCD_startGraphic();
    LCD_set_graphic_address(x, y);
    LCD_read_data();    //根据手册,设置完地址后的第一次读操作返回的数据无效

    high = LCD_read_data();
    low = LCD_read_data();

    //回写
    LCD_set_graphic_address(x, y);
    if (xBit < 8)   //低8位
    {
     
        LCD_write_data(high | (0x01 << (7 - xBit)));
        LCD_write_data(low);
    }
    else
    {
     
        LCD_write_data(high);
        LCD_write_data(low | (0x01 << (15 - xBit)));
    }
    LCD_endGraphic();
}
#endif

st7920.h

//ST7920 LCD 驱动
//Author: cdhigh <2021-09-22>
//ST7920的绘图结构:左上角为坐标原点,写入的字节表示从某个坐标开始的8个横向像素,
//每行 128/8=16 个字节,每个字节左边为最低位,右边为最高位,纵向64行。
//DDRAM地址
//0x80  0x81  0x82  0x83  0x84  0x85  0x86  0x87    //第一行汉字位置
//0x90  0x91  0x92  0x93  0x94  0x95  0x96  0x97    //第二行汉字位置
//0x88  0x89  0x8a  0x8b  0x8c  0x8d  0x8e  0x8f     //第三行汉字位置
//0x98  0x99  0x9a  0x9b  0x9c  0x9d  0x9e  0x9f     //第四行汉字位置
#ifndef __ST7290_H_
#define __ST7290_H_

#include 

#define LCD12864_Port P0

sbit LCD12864_CS  = P2^6;
sbit LCD12864_PSB = P3^2;
sbit RS_Pin = P2 ^ 6;			//寄存器选择位,RS位
sbit WR_Pin = P2 ^ 5;			//读写选择位,RW
sbit EN_Pin = P2 ^ 7;			//使能信号位,E位

#define MODE_8BIT       8  //8bit并行模式 
#define MODE_4BIT       4  //4bit并行模式
#define MODE_SPI     	1  //串行-PSB接地

//定义使用的接口模式,MODE_8BIT, MODE_4BIT, MODE_SPI
#define LCD_INTERFACE   MODE_SPI

void LCD_clear(void);
void LCD_init(void);
void LCD_write_command(unsigned char command);
void LCD_write_data(unsigned char Data);
void LCD_write_byte(unsigned char byte);
void LCD_write_half_byte(unsigned char half_byte);
void LCD2_spi_write_byte(unsigned char Data);
void LCD2_spi_write_byte_standard(unsigned char Data);
unsigned char LCD_read_data(void);
unsigned char LCD_read_status(void);
unsigned char LCD_read_byte(void);
void LCD_startGraphic(void);
void LCD_endGraphic(void);
void LCD_Inverse_16X16(unsigned int rowCol, unsigned char charNum, unsigned char reverse);
unsigned int LCD_rowCol_to_inter_Xy(unsigned int rowCol);
void LCD_set_text_address(unsigned int rowCol);
void LCD_set_graphic_address(unsigned char x, unsigned char y);
void LCD_write_char(unsigned int rowCol, unsigned int Code);
void LCD_write_string(unsigned int rowCol, const char * p);
void LCD_Draw_Bmp(unsigned char *pImage, unsigned char col, unsigned char row, unsigned char x0, unsigned char y0);

#if LCD_INTERFACE != MODE_SPI
void LCD_write_dot(unsigned char x, unsigned char y);
#endif

#define BYTE_BIT(bitno) (1 << (bitno))
#define TEST_BIT(value, bitno) ((1 << (bitno)) & (value))
#define SET_BIT(value, bitno)  ((value) |= (1 << (bitno)))
#define CLR_BIT(value, bitno)  ((value) &= ~(1 << (bitno)))

//两个字节凑成行列整型
//为了更好的区分使用X/Y和ROW/COL,使用ROW/COL的都是一个整型参数,X/Y为两个字节参数
#define ROW_COL(r, c) (((r) << 8) | (c & 0xff))

#endif

测试程序

显示图片

图片1

#include 
#include "intrins.h"
#include "stdint.h"
#include "st7920.h"

void Delay1ms()		//@11.0592MHz
{
     
	unsigned char i, j;

	_nop_();
	i = 2;
	j = 199;
	do
	{
     
		while (--j);
	} while (--i);
}


void delay_ms(int i)
{
     
	while(i--)
		Delay1ms();
}

code uint8_t LCD12864_Pic[] =
{
     
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x0D,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x04,0x78,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x03,0xB0,0x00,0x02,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x07,0x60,0x00,0x02,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x1E,0x40,0x00,0x01,0x07,0x80,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x3C,0x40,0x00,0x01,0x05,0xC0,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x34,0x80,0x00,0x00,0x82,0xC0,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x64,0x80,0x00,0x00,0x82,0x40,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x60,0x80,0x00,0x00,0x02,0x60,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x61,0x81,0x80,0x00,0x41,0x60,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x61,0x03,0xE0,0x00,0x01,0x20,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x61,0x07,0xF0,0x00,0x21,0x20,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x61,0x0C,0x3C,0x00,0x20,0xB0,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x61,0x11,0xDE,0x00,0x10,0xB0,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x21,0x12,0x1F,0x00,0x10,0x90,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x25,0x24,0xC3,0x80,0x08,0x10,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x35,0x29,0x01,0xC0,0x08,0x50,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x35,0x28,0x00,0xE0,0x04,0x58,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x15,0x3F,0xFF,0xF0,0x04,0x08,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x19,0xF8,0x00,0x3C,0x02,0x2C,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x1C,0x02,0x2C,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x0E,0x01,0x16,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x07,0x01,0x97,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x00,0x03,0x80,0x8B,0x82,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x00,0x01,0xC0,0x41,0xFE,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0xC0,0x32,0xFE,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x60,0x1D,0xFC,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x34,0x00,0x00,0x00,0x30,0x07,0xDC,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x10,0x00,0x38,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x08,0x00,0x70,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x60,0x80,0x00,0x00,0x0C,0x00,0xE0,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x60,0xC0,0x00,0x00,0x06,0x03,0xC0,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x60,0x7C,0x00,0x00,0x7F,0xFF,0x80,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x61,0xE4,0x00,0x00,0xC8,0x7C,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x60,0xEC,0x00,0x00,0xCE,0x18,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x60,0xFC,0x00,0x00,0xFE,0x1C,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x03,0xE0,0x7C,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x07,0x60,0x38,0x00,0x00,0x78,0x1B,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x06,0x60,0x58,0x00,0x00,0x48,0x19,0x80,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x06,0x60,0x00,0x00,0x00,0x00,0x19,0x80,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x06,0x60,0x00,0x00,0x00,0x00,0x19,0x80,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x06,0x20,0x1F,0xFF,0xFF,0xE0,0x19,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x06,0x20,0x10,0x41,0x04,0x20,0x13,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x03,0x30,0x1C,0x41,0x04,0x60,0x33,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x03,0xF0,0x0C,0x41,0x02,0x40,0x3E,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x01,0xF0,0x0C,0x01,0x02,0xC0,0x3C,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x30,0x06,0x81,0x03,0x80,0x60,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x18,0x03,0x81,0x03,0x00,0x60,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x1C,0x01,0xE1,0x0E,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x7F,0xF8,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x80,0x03,0x80,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x07,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

void main(void)
{
     
	LCD_init();
	LCD_clear();
	LCD_Draw_Bmp(LCD12864_Pic, 128, 64, 0, 0);
	while(1)
	{
     	

	}
}


实验现象

       图片打印较慢,请耐心等待。
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第16张图片

图片2

//liberty.bmp
//48x64
code unsigned char bmpData[] = 
{
     
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,
	0x00,0x00,0x00,0x01,0x20,0x00,0x00,0x00,0x00,0x03,0xE0,0x00,0x00,0x00,0x00,0x03,
	0xF0,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,
	0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x01,0xE1,0x80,0x00,0x00,0x00,0x01,0xF1,0x84,
	0x00,0x00,0x00,0x01,0xF9,0x9C,0x00,0x00,0x00,0x00,0xFF,0xB8,0x00,0x00,0x00,0x00,
	0xBF,0xFF,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0xDF,0xFC,0x00,0x00,
	0x00,0x00,0xDF,0xFF,0x80,0x00,0x00,0x00,0xDC,0x7F,0x00,0x00,0x00,0x00,0xDE,0xFC,
	0x00,0x00,0x00,0x00,0xDC,0xF0,0x00,0x00,0x00,0x01,0xFF,0x70,0x00,0x00,0x00,0x01,
	0xE7,0xD8,0x00,0x00,0x00,0x01,0xB3,0xD8,0x00,0x00,0x00,0x00,0xE1,0xF0,0x00,0x00,
	0x00,0x00,0xC1,0xF8,0x00,0x00,0x00,0x00,0x47,0xB8,0x00,0x00,0x00,0x00,0x4F,0xBC,
	0x00,0x00,0x00,0x00,0x4B,0x1D,0xC0,0x00,0x00,0x00,0x7A,0x7F,0xE0,0x00,0x00,0x00,
	0x36,0x6E,0x70,0x00,0x00,0x00,0x6C,0x6C,0xE0,0x00,0x00,0x00,0x6C,0x4C,0xE0,0x00,
	0x00,0x00,0xD8,0xCC,0xC0,0x00,0x00,0x00,0xD8,0xC5,0xC0,0x00,0x00,0x00,0x70,0xC7,
	0xC0,0x00,0x00,0x00,0x3C,0xC7,0x80,0x00,0x00,0x00,0x38,0xC7,0x80,0x00,0x00,0x00,
	0x78,0xC7,0x00,0x00,0x00,0x00,0x70,0xC6,0x00,0x00,0x00,0x00,0x70,0xC6,0x00,0x00,
	0x00,0x00,0x70,0xC6,0x00,0x00,0x00,0x00,0x30,0xC2,0x00,0x00,0x00,0x00,0x20,0xC2,
	0x00,0x00,0x00,0x00,0x60,0xC2,0x00,0x00,0x00,0x00,0x60,0xC6,0x00,0x00,0x00,0x00,
	0x60,0xFE,0x00,0x00,0x00,0x00,0x60,0xFE,0x00,0x00,0x00,0x00,0x60,0x7E,0x00,0x00,
	0x00,0x00,0x60,0x7E,0x00,0x00,0x00,0x00,0x60,0xFE,0x00,0x00,0x00,0x00,0x63,0xFE,
	0x00,0x00,0x00,0x00,0x67,0x7E,0x00,0x00,0x00,0x00,0x7F,0xFE,0x00,0x00,0x00,0x00,
	0x7F,0xFE,0x00,0x00,0x00,0x00,0x7F,0xDF,0x00,0x00,0x00,0x00,0x5F,0xDF,0x00,0x00,
	0x00,0x01,0xFF,0xFF,0x00,0x00,0x00,0x01,0x80,0x01,0x00,0x00,0x00,0x07,0xFF,0xFF,
	0xC0,0x00,0x00,0x06,0xFF,0xFE,0xE0,0x00,0x00,0x04,0x00,0x00,0x60,0x00,0x00,0x07,
	0xFF,0xFF,0xE0,0x00,0x00,0x07,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

void main(void)
{
     
	LCD_init();
	LCD_clear();
	LCD_Draw_Bmp(bmpData, 48, 64, 32, 0);
	while(1)
	{
     	

	}
}
实验现象

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第17张图片

显示字符

英文

void main(void)
{
     
	LCD_init();
	LCD_clear();
    LCD_write_string(0x0000, "0123456789abcdef");
	LCD_write_string(0x0100, "~`!@#$%^&*()_-+=");
	LCD_write_string(0x0200, "ABCDEFGHIJKLMNOP");
	LCD_write_string(0x0300, "QRSTUVWXYZ");
	while(1)
	{
     	

	}
}
实验现象

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第18张图片

中文

void main(void)
{
     
	LCD_init();
	LCD_clear();
    LCD_write_string(0x0000, "祥瑞不在凤凰麒麟");
	LCD_write_string(0x0100, "太平须得边将忠臣");
	LCD_write_string(0x0200, "仁得百僚师长肝胆");
	LCD_write_string(0x0300, "不用三\xfd军罗绮金银");
	while(1)
	{
     	

	}
}
实验现象

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第19张图片

Proteus的仿真

       需添加LCD12864的模型:发布一个ST7920的LCD12864 Proteus仿真模型,支持串口和4bit模式通讯 —— cdhigh
       下载后将LIBRARY、MODELS文件夹与Proteus安装目录下DATA文件夹内的同名文件夹合并
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第20张图片
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第21张图片
【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第22张图片

【51单片机快速入门指南】6.2:SPI 、八线、四线控制 LCD12864 屏幕及Proteus的仿真(支持中文汉字)_第23张图片

你可能感兴趣的:(51单片机,Proteus,电赛,51单片机,嵌入式硬件,单片机,LCD12864,SPI)