### 12864显示动画技术解析 #### 一、引言 12864液晶屏是一种常见的中型图形液晶显示屏,在嵌入式系统、工业控制、仪表仪器等领域有着广泛的应用。通过适当的编程技术,可以让12864液晶屏实现动态效果,如动画显示等功能。本文将详细解析如何利用12864液晶屏进行动画显示,并对给定代码片段进行深入解读。 #### 二、12864液晶屏基础知识 12864液晶屏采用ST7920或类似控制器,其分辨率为128x64像素。它支持图形显示模式,可以通过发送特定命令和数据到屏幕控制器来显示静态或动态图像。 #### 三、动画显示原理 动画显示的基本原理是利用人眼的视觉暂留效应。当一系列连续变化的画面在短时间内快速交替显示时,人眼会感觉到画面在动。为了实现这一效果,需要预先准备一系列帧图像,然后按照一定的频率依次显示这些图像。 #### 四、给定代码分析 给定的代码片段包含四个数组(`table1`、`table2`、`table3`、`table4`),每个数组都表示了一帧图像的数据。这些数组中的十六进制数代表了每个像素点的状态(亮或暗)。 - **table1**:表示第一帧图像的数据。 - **table2**:表示第二帧图像的数据。 - **table3**:表示第三帧图像的数据。 - **table4**:表示第四帧图像的数据。 每个数组由多个十六进制数组成,每个十六进制数对应着一行的像素状态。例如,在`table1`中,第一行的像素状态为`0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0xFF, 0xFF, 0xFF, 0xC0, 0x3F, 0xFF`。其中,`0xFF`表示这一行的所有像素都是关闭的(即黑色),而`0xC0`、`0x3F`等则表示该行有部分像素是开启的(即白色)。 #### 五、动画显示实现步骤 1. **定义图像帧**:根据动画内容的不同,预先设计好每一帧图像,并将其转换为数组形式存储起来。 2. **循环显示**:编写程序按顺序读取每一帧图像数据并显示到屏幕上。通常需要设定一个定时器来控制帧与帧之间的切换时间,以达到所需的动画播放速度。 3. **优化显示**:考虑到12864液晶屏的刷新速率有限,可以通过减少不必要的像素更新来提高显示效率。 #### 六、示例代码解析 给定的代码片段中定义了四个数组,分别表示四帧图像的数据。下面对其中一个数组(如`table1`)进行详细解析: ```c ucharcodetable1[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xFF,0xC0,0x3F,0xFF, 0xFF,0xE0,0x1F,0xFF,0xF8,0x00,0x00,0xFF,0xFB,0x0E,0x00,0x1F,0xF2,0x20,0x00,0x07, 0xF0,0x66,0x40,0x03,0xF0,0xE0,0x00,0x01,0xF8,0xE0,0x80,0x01,0xF9,0xFC,0x09,0x00, 0xF9,0xFC,0x18,0x00,0xF9,0xFC,0x18,0x00,0xF9,0xFC,0x09,0x01,0xF8,0xFE,0x80,0x81, 0xF8,0xFE,0x00,0x01,0xFA,0x7F,0x00,0x03,0xFA,0x1E,0x00,0x07,0xF8,0x00,0x00,0x1F, 0xF8,0x60,0x00,0xFF,0xFF,0xC0,0x3F,0xFF,0xFF,0xF1,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; ``` 这里以`table1`为例,可以看到每组十六进制数代表了一行的像素状态。例如,`0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xFF,0xC0,0x3F,0xFF`这一行表示了屏幕最上方的一行,其中前八个字节都是`0xFF`,意味着这一行的前128个像素都是关闭的;`0xC0`意味着第129和130个像素是打开的;之后的`0x3F`表示第131至136个像素是打开的;最后两个`0xFF`则表示剩下的像素都是关闭的。 #### 七、总结 通过对12864液晶屏显示动画的技术解析,我们了解了动画显示的基本原理及其在12864液晶屏上的实现方法。利用预先定义好的图像帧数组,并通过适当的程序控制其显示顺序和速度,就可以实现在12864液晶屏上的动画显示效果。此外,还可以通过优化显示策略来进一步提高显示质量和效率。
#include<intrins.h>
#include<stdio.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table1[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xFF,0xC0,0x3F,0xFF,
0xFF,0xE0,0x1F,0xFF,0xF8,0x00,0x00,0xFF,0xFB,0x0E,0x00,0x1F,0xF2,0x20,0x00,0x07,
0xF0,0x66,0x40,0x03,0xF0,0xE0,0x00,0x01,0xF8,0xE0,0x80,0x01,0xF9,0xFC,0x09,0x00,
0xF9,0xFC,0x18,0x00,0xF9,0xFC,0x18,0x00,0xF9,0xFC,0x09,0x01,0xF8,0xFE,0x80,0x81,
0xF8,0xFE,0x00,0x01,0xFA,0x7F,0x00,0x03,0xFA,0x1E,0x00,0x07,0xF8,0x00,0x00,0x1F,
0xF8,0x60,0x00,0xFF,0xFF,0xC0,0x3F,0xFF,0xFF,0xF1,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uchar code table2[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x7F,0xFF,0xFF,0xF0,0x3F,0xFF,0xFF,0xF8,0x1F,0xFF,
0xFC,0xF8,0x00,0xFF,0xF8,0x00,0x00,0x0F,0xFB,0x0E,0x40,0x07,0xF2,0x20,0x00,0x03,
0xF0,0x4C,0x88,0x01,0xF0,0xC0,0x08,0xC1,0xF9,0xC1,0x18,0x01,0xF9,0xE5,0x18,0x00,
0xF9,0xFD,0x1C,0x00,0xF9,0xFC,0x0C,0xE1,0xF9,0xFE,0x84,0x01,0xF8,0xFE,0x00,0x01,
0xF8,0x7F,0x00,0x03,0xFA,0x3F,0x80,0x07,0xF8,0x0E,0x00,0x1F,0xF8,0x00,0x01,0xFF,
0xFC,0x30,0x00,0xFF,0xFF,0xFF,0x00,0x7F,0xFF,0xFF,0xE0,0x7F,0xFF,0xFF,0xFF,0xFF};
uchar code table3[]={
0xFF,0xF8,0xFF,0xFF,0xFF,0xF0,0x3F,0xFF,0xFF,0xF0,0x1F,0xFF,0xFF,0xF8,0x1F,0xFF,
0xFC,0xF0,0x00,0x1F,0xF8,0x00,0x00,0x07,0xF9,0x00,0x40,0x03,0xFA,0x0C,0x80,0x01,
0xFA,0x40,0x08,0x41,0xF8,0x60,0x08,0x20,0xFC,0xFC,0x0C,0x00,0xFC,0xFE,0x0C,0x00,
0xFC,0xFE,0x04,0x10,0xFC,0xFE,0x04,0x00,0xFC,0x7F,0x00,0x01,0xF8,0x7F,0x00,0x01,
0xF8,0x3F,0x80,0x03,0xFB,0x1F,0xC0,0x07,0xFA,0x03,0x00,0x1F,0xF8,0x30,0x00,0x3F,
0xFF,0xFC,0x00,0x1F,0xFF,0xFF,0xE0,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uchar code table4[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x3F,0xFF,0xFF,0xF8,0x3F,0xFF,
0x87,0x00,0x1F,0xFF,0x20,0x00,0x00,0x3F,0x31,0xF1,0x00,0x0F,0x24,0x06,0x00,0x07,
0x89,0xCC,0x00,0x03,0x88,0x1C,0x21,0x01,0x99,0x98,0x22,0x41,0x9C,0x10,0x00,0x00,
0x0F,0xB0,0x61,0xE1,0x07,0xB8,0x00,0x83,0x23,0x90,0x00,0x03,0xA1,0xC0,0x00,0x07,
0x88,0x00,0x00,0x1F,0xFF,0x00,0x01,0xFF,0xFF,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uchar code table5[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x3F,0xFF,0xFF,0xF8,0x3F,0xFF,
0x87,0x00,0x1F,0xFF,0x20,0x00,0x00,0x3F,0x31,0xF1,0x00,0x0F,0x24,0x06,0x00,0x07,
0x89,0xCC,0x00,0x03,0x88,0x18,0x21,0x01,0x99,0x90,0x22,0x41,0x9C,0x14,0x60,0x00,
0x9F,0xB0,0xE0,0x00,0x9F,0x32,0xE0,0x00,0x1F,0x30,0xE0,0x40,0x0F,0x30,0x62,0x60,
0x0F,0xB0,0x61,0xE1,0x07,0xB8,0x00,0x03,0x23,0x90,0x00,0x03,0xA1,0xC0,0x00,0x07,
0x88,0x00,0x00,0x1F,0xFF,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uchar code table6[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x3F,0xFF,0xFF,0xF8,0x3F,0xFF,
0x87,0x00,0x1F,0xFF,0x20,0x00,0x00,0x3F,0x31,0xF1,0x00,0x0F,0x24,0x06,0x00,0x07,
0x89,0xCC,0x00,0x03,0x88,0x00,0x21,0x01,0x99,0x88,0x22,0x41,0x9C,0x08,0x60,0x00,
0x9F,0x88,0xE0,0x00,0x9F,0x0E,0xE0,0x00,0x1F,0x20,0xE0,0x40,0x0F,0x30,0x62,0x60,
0x0F,0xB0,0x61,0xE1,0x07,0xB8,0x00,0x83,0x23,0x90,0x00,0x03,0xA1,0xC0,0x00,0x07,
0x88,0x00,0x00,0x1F,0xFF,0x00,0x01,0xFF,0xFF,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
sbit lcd_en=P3^4;
sbit lcd_rs=P3^5;
sbit lcd_rw=P3^6;
sbit PSB = P3^7;
sbit dula=P2^6;
sbit wela=P2^7;
uchar d,Y;
void delay(uint z) //延时
{
剩余6页未读,继续阅读
- zi1shao7362015-04-10代码很不错 但是有的地方感觉复杂啦 不是那么清晰
- 晴空有阴2014-06-07有用的!!!!
- 钟离逸舜2013-08-28非常给力的代码,嘿嘿,正是我所需要的,谢谢楼主
- luofeideai2015-03-07之前写过这个!!但是有阴影,楼主的很有用,非常感谢
- 粉丝: 1
- 资源: 6
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助