模块介绍
液晶显示模块是 128×64 点阵的汉字图形型液晶显示模块,可显示汉字及图形,
内置 8192 个中文汉字(16X16 点阵)、128 个字符(8X16 点阵)及 64X256 点阵显示 RAM(GDRAM)。
可与 CPU 直接接口,提供两种界面来连接微处理机:8位并行及串行两种连接方式。
具有多种功能:光标显示、画面移位、睡眠模式等。
此实例采用串行方式
并行方式请查看: 6. 51单片机使用LCD12864液晶屏(8位并行)
文档链接
引脚定义
串行时序
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <8052.h> #include "delay.h"
#define CS P0_0 #define SID P0_1 #define SCLK P0_2
void lcd12864_write(unsigned char data) { unsigned char i; for(i=0; i<8; i++) { SCLK = 0; SID = data & 0x80; data <<= 1; SCLK = 1; } }
void lcd12864_write_command(unsigned char command) { lcd12864_write(0xF8); lcd12864_write(command & 0xF0); lcd12864_write((command << 4) & 0xF0); delay_50us(4); }
void lcd12864_write_data(unsigned char data) { lcd12864_write(0xFA); lcd12864_write(data & 0xF0); lcd12864_write((data << 4) & 0xF0); delay_50us(4); }
void lcd12864_initialization() { CS = 1; delay(100); lcd12864_write_command(0x30); delay_50us(4); lcd12864_write_command(0x30); delay_50us(4); lcd12864_write_command(0x0f); delay_50us(4); lcd12864_write_command(0x01); delay(15); lcd12864_write_command(0x06); CS = 0; }
void display_chinese_characters() { unsigned char table[] = { 0xC4, 0xFA, 0xBA, 0xC3, 0xA3, 0xA1 }; unsigned char i; CS = 1; lcd12864_write_command(0x90); for(i=0; i<sizeof(table); i++) { lcd12864_write_data(table[i]); } CS = 0; }
void display_ascii() { unsigned char i; unsigned char table[] = "hello world!"; CS = 1; lcd12864_write_command(0x80); for(i=0; i<sizeof(table); i++) { lcd12864_write_data(table[i]); } lcd12864_write_command(0x88); for(i=0; i<sizeof(table); i++) { lcd12864_write_data(table[i]); } CS = 0; }
void setup() { lcd12864_initialization(); display_ascii(); display_chinese_characters(); }
void loop() {
}
void main() { setup(); while(1) loop(); }
|