單片機實現(xiàn)液晶顯示
主要器件:
1、AT89C52作為液晶顯示的控制芯片。
2、選用內(nèi)含KS0108B/HD61202控制器的圖形液晶顯示模塊CXM12864,實現(xiàn)128點*64點大小的平板顯示,可以滿足一般的顯示要求。
3、雙電壓輸出升壓芯片MAX1677專用LCD電源芯片。
試驗電路圖:
試驗程序代碼:
//lcd_show.h程序
#ifndef_LCD_SHOW_H//防止lcd_show.h被重復(fù)引用
#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程序?qū)崿F(xiàn)顯示“請插卡”
#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操作的函數(shù), 128x64點陣,漢字顯示,CSA,CSB用來進行左右顯示區(qū)的選擇。*/
/*發(fā)命令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;
}
/*寫數(shù)據(jù)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);/*設(shè)置顯示頁面*/
lcd_mwc(0x40);/*設(shè)置列地址*/
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 "請插卡"
}
評論