单片机的输出办法除了二极管、数码管外,还有一中重要的办法:液晶显现。鉴于液晶显现的用处越来越广泛,在学习了LED显现后,又学习了怎么使用液晶显现模块驱动LCD显现的办法。在了解了点阵式和图方式LCD的显现办法,又了解了16*16字模的编写办法上学习了根据GXM12864的液晶显现办法。
首要器材:
1、AT89C52作为液晶显现的操控芯片。
2、选用内含KS0108B/HD61202操控器的图形液晶显现模块CXM12864,完成128点*64点巨细的平板显现,能够满意一般的显现要求。
3、双电压输出升压芯片MAX1677专用LCD电源芯片。
实验电路图:
实验程序代码:
//lcd_show.h程序
#ifndef_LCD_SHOW_H//避免lcd_show.h被重复引证
#define_LCD_SHOW_H
#include <at89c51.h>
#include
unsigned char code QING[32]={
/*请*/
0x20,0x22,0xEC,0x00,0x20,0x22,0xAA,0xAA,
0xAA,0xBF,0xAA,0xAA,0xEB,0xA2,0x20,0x00,
0x00,0x00,0x7F,0x20,0x10,0x00,0xFF,0x0A,
0x0A,0x0A,0x4A,0x8A,0x7F,0x00,0x00,0x00
};
unsigned char code CHA[32]={
/*插*/
0x10,0x10,0x10,0xFF,0x90,0x24,0x24,0xA4,
0x24,0xFC,0x22,0x23,0x22,0xB0,0x20,0x00,
0x02,0x42,0x81,0x7F,0x00,0xFF,0x49,0x48,
0x40,0x7F,0x40,0x49,0x49,0xFF,0x01,0x00
};
unsigned char code KA[32]={
/*卡*/
0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x44,
0x44,0x44,0x46,0x44,0x40,0x60,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,
0x02,0x04,0x0C,0x18,0x00,0x00,0x00,0x00
};
#define LCD XBYTE[0xffff] /* LCD端口*/
#endif
//lcd_show.c程序完成显现“请插卡”
#include “lcd_show.h”
#define uint unsigned int
#define uchar unsigned char
#define CSA P2^1
#define CSB P2^0
#define E P2^3
#define RW P2^5
#define DI P2^6
sbit busy_bit=ACC^7;//lcd state byte bit 7
/*下面是对液晶屏gxm12864d操作的函数, 128×64点阵,汉字显现,CSA,CSB用来进行左右显现区的挑选。*/
/*发指令i到主窗口*/
void lcd_mwc(uchar i)
{
CSA=1;
CSB=0;
RW=1;
DI=0;
do {ACC=LCD;}
while (busy_bit) ;//wait for lcd not busy
RW=0;
LCD=i;
}
/*写数据i到主窗口*/
void lcd_mwd(uchar i)
{
CSA=1;
CSB=0;
RW=1;
DI=0;
do {ACC=LCD;} while (busy_bit);//wait for lcd not busy
RW=0;
DI=1;
LCD=i;
}
/*清屏*/
void lcd_clear(void)
{
uchar i;
uchar page;
for (page=0xb8;page<0xc0;page++)
{
lcd_mwc(page);/*设置显现页面*/
lcd_mwc(0x40);/*设置列地址*/
for (i=0;i<64;i++)
{
lcd_mwd(0);
}
}
}
//初始化lcd
void lcd_init(void)
{
lcd_mwc(0xc0);
lcd_mwc(0x3f);
}
//dispm_hz_up() display up half of a hanzi in left area
void dispm_hz_up(uchar code * hz)
{
uchar i;
for (i=0;i<16;i++) lcd_mwd(*(hz+i));
}
//dispm_hz_down() display down half of a hanzi in left area
void dispm_hz_down(uchar code * hz)
{
uchar i;
for (i=16;i<32;i++) lcd_mwd(*(hz+i));
}
void main(void)
{
E=1;
lcd_clear();
lcd_init();
lcd_mwc(0xb8);
lcd_mwc(0x40);
dispm_hz_up(&QING);
dispm_hz_up(&CHA);
dispm_hz_up(&KA);
lcd_mwc(0xb9);
lcd_mwc(0x40);
dispm_hz_down(&QING);
dispm_hz_down(&CHA);
dispm_hz_down(&KA);//display “请插卡”
}