使用51單片機(jī)驅(qū)動(dòng)YM12232B型液晶顯示屏
本實(shí)例中將使用51單片機(jī)控制YM12232B LCD分別在主窗口和副窗口中顯示”科“和”學(xué)“字。
本文引用地址:http://m.butianyuan.cn/article/201611/318172.htmYM12232B 一共有18個(gè)引腳,各個(gè)引腳的作用如下圖所示:
YM12232B 的顯示屏格式如下所示,它分主窗口(左邊窗口)和副窗口(右邊窗口),每個(gè)窗口分為4頁(yè),每一頁(yè)有64列。每次掃描一頁(yè)時(shí)只需要將addr設(shè)置到0,然后輸入64次數(shù)據(jù)就可以了(每輸入一次,地址自動(dòng)加1,直到64為止),并且掃描下一頁(yè)時(shí)不要忘了將addr重新設(shè)置為0,否則它會(huì)一直是64,導(dǎo)致掃描出錯(cuò)。
本次實(shí)例的原理圖如下:
本次實(shí)例的單片機(jī)代碼(keil)如下:
#include#include #define uchar unsigned char#define uint unsigned int#define A0 P2_0#define E1 P2_1#define E2 P2_2#define DATA P1sbit P2_0=P2^0;sbit P2_1=P2^1;sbit P2_2=P2^2;/*---------存放科字的數(shù)組-----------*/uchar code ke[]={0x00,0x60,0x30,0x1C,0xFE,0x03,0x00,0x00,0x90,0xA2,0xAC,0xA8,0xFF,0x80,0x80,0x80,0x21,0x11,0x09,0x07,0xFF,0x03,0x05,0x09,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00};/*----------存放學(xué)字的數(shù)組----------*/uchar code xue[]={0x30,0x73,0x16,0x14,0x50,0x51,0x52,0x56,0x50,0xD4,0xD6,0x13,0x13,0x72,0x30,0x00,0x00,0x04,0x04,0x04,0x04,0x44,0xC6,0xFF,0x05,0x05,0x04,0x04,0x04,0x04,0x04,0x00};/*---------------------------------------------------------調(diào)用方式:void OutMI(uchar i)函數(shù)說(shuō)明:發(fā)指令i到主窗口(左半面)。-----------------------------------------------------------*/void OutMI(uchar i){ E1=1;_nop_();_nop_();A0=0;_nop_();_nop_(); DATA=i;_nop_();_nop_();E1=0;_nop_();_nop_();}/*-------------------------------------------------------------------------------- 調(diào)用方式:void OutMD(uchar i) 函數(shù)說(shuō)明:發(fā)數(shù)據(jù)i到主窗口。 ---------------------------------------------------------------------------------*/void OutMD(uchar i){ E1=1;_nop_();_nop_(); A0=1;_nop_();_nop_(); DATA=i;_nop_();_nop_(); E1=0;_nop_();_nop_(); }/*-------------------------------------------------------------------------------- 調(diào)用方式:void OutSI(uchar i) 函數(shù)說(shuō)明:發(fā)指令i到從窗口(右半面)---------------------------------------------------------------------------------*/ void OutSI(uchar i){ A0=0;_nop_();_nop_(); E2=1;_nop_();_nop_(); DATA=i;_nop_();_nop_(); E2=0;_nop_();_nop_(); }/*-------------------------------------------------------------------------------- 調(diào)用方式:void OutSD(uchar i) 函數(shù)說(shuō)明:發(fā)數(shù)據(jù)i到從窗口。 ---------------------------------------------------------------------------------*/ void OutSD(uchar i) { A0=1;_nop_();_nop_(); E2=1;_nop_();_nop_(); DATA=i;_nop_();_nop_(); E2=0;_nop_();_nop_(); }/*-------------------------------------------------------------------------------- 調(diào)用方式:void LcdIni(void) 函數(shù)說(shuō)明:12232點(diǎn)陣液晶初始化,開(kāi)機(jī)后僅調(diào)用一次。 ---------------------------------------------------------------------------------*/ void LcdIni(void){ OutMI(0XE2);OutSI(0XE2);//復(fù)位 OutMI(0XAE);OutSI(0XAE);//POWER SAVE OutMI(0XA4);OutSI(0XA4);//動(dòng)態(tài)驅(qū)動(dòng) OutMI(0XA9);OutSI(0XA9);//1/32占空比 OutMI(0XA0);OutSI(0XA0);//時(shí)鐘線輸出 OutMI(0XEE);OutSI(0XEE);//寫(xiě)模式 OutMI(0X00);OutMI(0XC0); OutSI(0X00);OutSI(0XC0); OutMI(0XAF);OutSI(0XAF); }/*-------------------------------------------------------------------------------- 調(diào)用方式:void SetPage(uchar page_s,uchar page_m) 函數(shù)說(shuō)明:同時(shí)設(shè)置主從顯示頁(yè)為0-3頁(yè)。(內(nèi)函數(shù),私有,用戶不直接調(diào)用) ---------------------------------------------------------------------------------*/ void SetPage(uchar page_s,uchar page_m) { OutMI(0xB8|page_m);OutSI(0xB8|page_s); }/*-------------------------------------------------------------------------------- 調(diào)用方式:void SetAddress(uchar address_s,uchar address_m) 函數(shù)說(shuō)明:同時(shí)設(shè)置主從列地址為0-63。(內(nèi)函數(shù),私有,用戶不直接調(diào)用) ---------------------------------------------------------------------------------*/ void SetAddress(uchar address_s,uchar address_m) { OutMI(address_m&0x7F);OutSI(address_s&0x7F); }/*-------------------------------------------------------------------------------- 調(diào)用方式:void PutChar0(uchar ch) 函數(shù)說(shuō)明:在左頁(yè)當(dāng)前地址畫(huà)一個(gè)字節(jié)8個(gè)點(diǎn)。(內(nèi)函數(shù),私有,用戶不直接調(diào)用) ---------------------------------------------------------------------------------*/ void PutChar0(uchar ch) {OutSD(ch); } /*-------------------------------------------------------------------------------- 調(diào)用方式:void PutChar1(uchar ch) 函數(shù)說(shuō)明:在右頁(yè)當(dāng)前地址畫(huà)一個(gè)字節(jié)8個(gè)點(diǎn)。 ---------------------------------------------------------------------------------*/ void PutChar1(uchar ch) { OutMD(ch); }/*-------------------------------------------------------------------------------- 調(diào)用方式:void clrscr(void) 函數(shù)說(shuō)明:清屏 ---------------------------------------------------------------------------------*/ void clrscr(void) { uchar i; uchar page; for (page=0;page<4;page++) { SetPage(page,page); SetAddress(0,0); for (i=0;i<61;i++){PutChar0(0);PutChar1(0);} } }/*------------------長(zhǎng)延時(shí)函數(shù)-------------------*/void delay(int i){int xx=0;int yy=0;for(xx=0;xx
運(yùn)行效果圖:
注:本實(shí)例中生成漢字點(diǎn)陣需要使用如下軟件:
http://download.csdn.net/detail/zgrjkflmkyc/5821757
評(píng)論