STM8控制LCD12864液晶屏实验

发布者:yanfeng00最新更新时间:2021-02-07 来源: eefocus关键字:STM8控制  LCD12864 手机看文章 扫描二维码
随时随地手机看文章

第一部分 并口传输显示中英文

主要是以下几个函数:

首先:写一个LCD_write函数来给LCD发送数据.根据时序图,发送数据是RW要置0,E要产生下降沿,RS置1为数据,RS置0为命令,由于是并口传输PSB置1.

其次:能够给LCD发命令后,我们就要使用LCD_init函数发送初始化命令。初始化命令至少包括:1、设置显示,2、功能设定,3、初始化清屏3个部分。

写命令时注意每个命令都有自己的运行时间,记得保证足够延时。

第三:写一个LCD_display函数可以分行分列显示内容。


void LCD_write(u8 data,u8 cmd_flag);

void LCD_init(void);

void LCD_display(u8 row,u8 col,u8 *string);


一、并口方式理论及资料

1.先上时序图:

这里要注意的是 PWeh 要大于450ns 以STM8S208MB内部16M RC振荡器计算,每次执行时间为: 1s/(16M/8分频) =500ns 所以必须延时保证E引脚上升区域大于450ns。

同理 tdsw也需要延时。

2.指令表

ST7920指令集分为2种,第一种:10种基础指令集RE=0,第二种:6种高级指令集RE=0

第一部分是显示中英文,所以只需用到基础指令集RE=0

3.引脚图和硬件电路

4.为什么每行可以写八个汉字或16个英文/数字?

因为每个汉字需要占2个字节。

此外还要留意,第一行和第三行的内存地址是连在一起的,不控制光标的话,写完第一行就会换行到第三行。(光标写完是自动加一的)

5.程序代码


//------------------------------header------------------------------------------

#include "iostm8s208mb.h"

//------------------------------common datatype---------------------------------

typedef unsigned char uint8_t;

typedef unsigned short uint16_t;

typedef unsigned long uint32_t;

#define u8 uint8_t

#define u16 uint16_t

#define u32 uint32_t

//------------------------------macros------------------------------------------

#define LCDRS PF_ODR_ODR0

#define LCDRW PF_ODR_ODR3

#define LCDEN PF_ODR_ODR4

#define LCDPSB PF_ODR_ODR5

#define LCDDATA PB_ODR

//------------------------------function declare--------------------------------

void delay(u8 count);

void GPIO_init(void);

void LCD_write(u8 data,u8 cmd_flag);

void LCD_init(void);

void LCD_display(u8 row,u8 col,u8 *string);

//------------------------------global------------------------------------------

//------------------------------main--------------------------------------------

void main( void )

{

  GPIO_init();

  LCD_init();

  LCD_display(1,0,"熊爸的学习时间");

  LCD_display(2,0,"================");

  LCD_display(3,0,"使用LCD12864显示");

  LCD_display(4,0,"屏来并口显示数据");

  

}

//------------------------------functions---------------------------------------

void delay(u8 count)

{

  u8 i,j;

  while (count--)

  {

    for(i=0;i<50;i++)

      for(j=0;j<20;j++);

  }

}

void GPIO_init(void)

{

  //lcd DB0~DB7

  PB_DDR |=0XFF;

  PB_CR1 |=0XFF;

  PB_CR2 &=0X00;

  PB_ODR &=0X00;


  //LCD RS RW EN PSB

  PF_DDR |=0X39;

  PF_CR1 |=0X39;

  PF_CR2 &=0XC6;

  PF_ODR &=0XC6;


  LCDPSB=1;

  LCDRW=0;

}

void LCD_write(u8 data,u8 cmd_flag)

{

  LCDRS=cmd_flag;

  LCDEN=0;

  delay(1);

  LCDEN=1;

  LCDDATA=data;

  delay(1);       //delay保证E的周期

  LCDEN=0;

  delay(1);

}

void LCD_init(void)

{

  LCD_write(0X0C,0);

  delay(1);

  LCD_write(0X30,0);

  delay(1);

  LCD_write(0X01,0);

  delay(1);

}

void LCD_display(u8 row,u8 col,u8 *string)

{

  switch (row)

  {

    case 1:row=0X80;break;

    case 2:row=0X90;break;

    case 3:row=0X88;break;

    case 4:row=0X98;break;

    default:row=0X80;

  }

  LCD_write(row+col,0);

  while (*string != '')

  {

    LCD_write(*string,1);

    string++;

  }  

}

5.实验效果


第二部分 并行显示图片

1、指令集

使用绘图功能需要打开扩展指令集

2、绘画步骤

1.使用扩展指令集并关闭绘图显示功能 0X34
2.设置垂直地址
3.设置水平地址
4.写D15~D8位
5.写D7~D0位
6.打开绘图显示功能 0X36
7.返回基本指令集

垂直地址:表示方法 第几行+偏移量 例如: 0x80+j

水平地址:第一行0X80 第二行0X90 第三行0X88 第四行0X98

这部分处理函数如下:


void LCD_pic(u8 *pic)

{

  u8 i,j,k;

  LCD_write(0X34,0);delay(10);

  for ( i = 0; i <2; i++)

  {

    for ( j = 0; j <32; j++)

    {

      LCD_write(0X80+j,0);

      LCD_write(0X80+8*i,0);

      for ( k = 0; k <16; k++)

      {

        LCD_write(*pic++,1);

      }

    }

  }

  LCD_write(0X36,0);delay(10);

  LCD_write(0X30,0);delay(10);

}

3、再来看GDRAM

其实12864 只用了GDRAM的一半

Y坐标取值范围:0X80+0-31

X坐标取值范围:0X80或者0X88

//------------------------------header------------------------------------------

#include "iostm8s208mb.h"

//------------------------------common datatype---------------------------------

typedef unsigned char uint8_t;

typedef unsigned short uint16_t;

typedef unsigned long uint32_t;

#define u8 uint8_t

#define u16 uint16_t

#define u32 uint32_t

//------------------------------macros------------------------------------------

#define LCDRS PF_ODR_ODR0

#define LCDRW PF_ODR_ODR3

#define LCDEN PF_ODR_ODR4

#define LCDPSB PF_ODR_ODR5

#define LCDDATA PB_ODR

//------------------------------function declare--------------------------------

void delay(u8 count);

void GPIO_init(void);

void LCD_write(u8 data,u8 cmd_flag);

void LCD_init(void);

void LCD_pic(u8 *pic);

//------------- -----------------global------------------------------------------

u8 dis[]={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,

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,

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,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x1F,0xE0,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,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x03,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x0F,0xFC,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x3F,0xF8,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0xFF,0xC3,0x0F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x01,0xFF,0xC7,0x8F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x07,0xFE,0x3F,0xF1,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x07,0xFC,0x3F,0xF0,0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CC,0xCC,0x60,0x0C,

0x01,0x8F,0x0F,0xC3,0xE6,0x00,0x7C,0x39,0xCE,0x6C,0xFC,0x0C,0xCC,0xCC,0x70,0x1C,

0x00,0x8F,0x03,0x03,0xE4,0x00,0xE0,0x0C,0x84,0x7C,0xCC,0xF8,0x80,0x04,0x3F,0xF8,

0x06,0x0F,0x00,0x03,0xE1,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x07,0x0F,0x00,0x03,0xC3,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x07,0xE3,0x00,0x03,0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x07,0xF1,0x00,0x02,0x3F,0x81,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,

0x07,0xFE,0x00,0x01,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x07,0xFF,0x00,0x03,0xFF,0x81,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,

0x01,0xFF,0xC0,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x7F,0xE0,0x1F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x1F,0xF8,0x7F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x0F,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x01,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0xFF,0xFC,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,0x00,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x07,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x01,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,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,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};

//------------------------------main--------------------------------------------

void main( void )

{

  CLK_CKDIVR=0X00;

  delay(100);

  GPIO_init();

  LCD_init();

[1] [2] [3]
关键字:STM8控制  LCD12864 引用地址:STM8控制LCD12864液晶屏实验

上一篇:STM8内部存储器结构及编程
下一篇:基于IAR的STM8工程的创建

推荐阅读最新更新时间:2024-11-13 13:01

AT89S52单片机+LCD12864贪吃蛇小游戏(独立按键)
单片机源程序如下: //12864并行接口参考程序,控制器st7920 #include reg52.h #include Lcd12864.h #include Key.h #define uchar unsigned char #define uint unsigned int static unsigned long Seed = 1; #define A 48271L #define M 2147483647L #define Q (M / A) #define R (M % A) /************************************ 伪随机数发生器 *******************
[单片机]
单片机_LCD12864显示自己制作的图片(时钟为例)
显示屏上显示自己想要的背景图,然后再在背景图上增加相应的功能,应用ps可以很方便的修改图片为自己想要的。 准备软件: phtotshop cs3 自用的一款,小巧非专业实用的ps软件,下载地址如下, 链接:https://pan.baidu.com/s/1R2ydl_TXEP7pWUv8VFlMbA 提取码:a1rz 字模提取软件 链接:https://pan.baidu.com/s/1aHq8Noin0VTgdnHIhhSGfQ 提取码:uiqg 1.用ps(Photoshop)新建一个 注意宽度和高度要和12864的一样,选择位图,为一位。 2,为了方便调整图片,我们选择图像模式为灰度,(
[单片机]
单片机_<font color='red'>LCD12864</font>显示自己制作的图片(时钟为例)
单片机实验板2011_V1.1-LCD12864液晶显示
/***********************************************************/ /*模块名 :LCD12864控制显示 */ /*创建人 :ClimberWin 日期:2011-03-12 */ /***********************************************************/ #include reg51.h #define uchar unsigned char #define uint unsigned int #define ulong unsigned long sbit LCD
[单片机]
单片机<font color='red'>实验</font>板2011_V1.1-<font color='red'>LCD12864</font>液晶显示
PIC单片机驱动LCD12864液晶显示闪动字体程序
/********************************************************************** *** 功能:12864LCD显示 显示闪动字体,各位同学可以自己修改。 *** 实验内容:0x81 0x90 0x88 0x98 分别是LCD四行的行首地址,我们操作LCD现实的字符就是分别放在这里面的 *** 开发板连接方法: 接上有字库LCD12864 注意调节对比度,LCD12864工作电流较大,请用外接电源供电。 *************************************************************************************
[单片机]
小广播
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件
更多往期活动

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved