| 122*32液晶顯示程序,顯示圖形及漢字 |
| 作者:佚名 來源:不詳 錄入:Admin 更新時間:2008-7-27 16:06:26 點擊數(shù):2 |
【字體:
】 |
/*============================================================ 功能:使用12232液晶顯示圖片演示 作者: Mingtree ycxms88@163.com http://www.mcu123.com ============================================================== 硬件:TG12232B (122*32)模擬口線接線方式 連接線圖: --------------------------------------------------| |DB0-----P0.0 | DB4-----P0.4 | RW-------P1.1 | A0--------P1.0 | |DB1-----P0.1 | DB5-----P0.5 | RS-------P2.1 | V0接1K電阻到GND | |DB2-----P0.2 | DB6-----P0.6 | E1-------P1.3 | |DB3-----P0.3 | DB7-----P0.7 | E2-------P1.2 | ---------------------------------------------------
本程序源碼只供學(xué)習(xí)參考,如有需要請聯(lián)系作者。
[注:AT89x52使用22.1184M或11.0592M晶振,實測使用22.1184M或11.0592都可以] 編譯平臺:Keil uV2 7.08
//可能看起來有點亂,不過效果還是不錯的,顯示圖形總的來說比顯示漢字要簡單,當(dāng)然顯示漢字也不難。 希望此程序能給你一些幫助。 有什么問題可以發(fā)email 給我或到我的論壇發(fā)問. http://www.mcu123.com/bbs =============================================================*/
#i nclude <AT89X52.H>
#define uchar unsigned char #define uint unsigned int
#define E1 P1_3 //塊1 左邊 #define E2 P1_2 //塊2 右邊 #define RW P1_1 #define A0 P1_0 //A0為1時是數(shù)據(jù),0時為指令數(shù)據(jù) #define DATA P0 //數(shù)據(jù)
extern unsigned char code Bmpt1[]; extern unsigned char code Bmpt2[]; extern unsigned char code Bmpt3[]; extern unsigned char code Bmpt4[]; extern unsigned char code Bmpt5[]; extern unsigned char code Bmpt6[]; extern unsigned char code Bmpt7[]; extern unsigned char code Bmptc[]; extern unsigned char code bmp001[]; extern unsigned char code Bmp08[]; extern unsigned char code Bmp07[]; extern unsigned char code Bmp06[]; extern unsigned char code Bmp05[]; extern unsigned char code Bmp04[]; extern unsigned char code Bmp03[]; extern unsigned char code Bmp02[]; extern unsigned char code Bmp01[]; extern unsigned char code Bmp012[]; extern unsigned char code Bmp003[]; extern unsigned char code Bmp002[];
//延時 void delay(unsigned int i) { unsigned char k=200; while(i>0) { i--; } while(k>1)k--; }
//左頁 //發(fā)送數(shù)據(jù) void OUTMD(unsigned char i) { A0=1; //寫數(shù)據(jù) //delay(5); E1=1; //delay(10); DATA=i; //delay(5); E1=0;
} //左頁 //發(fā)送命令 void OUTMI(unsigned char i) { A0=0; //寫指令 //delay(5); E1=1; //delay(10); DATA=i; //delay(5); E1=0;
} //右頁 //發(fā)送數(shù)據(jù) void OUTSD(unsigned char i) { A0=1; //寫數(shù)據(jù) //delay(5); E2=1; //delay(10); DATA=i; //delay(5); E2=0;
} //右頁 //發(fā)送命令 void OUTSI(unsigned char i) { A0=0; //寫指令 //delay(5); E2=1; //delay(10); DATA=i; //delay(5); E2=0;
}
//初始化 void lcdini(void) { RW=0; OUTMI(0XE2); OUTSI(0XE2);//復(fù)位 OUTMI(0XAE); OUTSI(0XAE);//POWER SAVE OUTMI(0XA4); OUTSI(0XA4);//動態(tài)驅(qū)動 OUTMI(0XA9); OUTSI(0XA9);//1/32占空比 OUTMI(0XA0); OUTSI(0XA0);//時鐘線輸出 OUTMI(0XEE); OUTSI(0XEE);//寫模式
OUTMI(0X00); OUTMI(0XC0); OUTSI(0X00); OUTSI(0XC0);
OUTMI(0XAF); OUTSI(0XAF);
} /* 函數(shù)說明:同時設(shè)置主從顯示頁為0-3頁。(內(nèi)函數(shù),私有,用戶不直接調(diào)用) ------------------------------------------------------------------------ */ void SetPage(uchar page0,uchar page1) { OUTMI(0xB8|page1);OUTSI(0xB8|page0); }
/* -------------------------------------------------------------------------------- 函數(shù)說明:同時設(shè)置主從列地址為0-121。(內(nèi)函數(shù),私有,用戶不直接調(diào)用) -------------------------------------------------------------------------------- */ void SetAddress(uchar address0,uchar address1) { OUTMI(address1);OUTSI(address0); }
/* --------------------------------------------------------------------------------
調(diào)用方式:void PutChar0(uchar ch) 函數(shù)說明:在右頁當(dāng)前地址畫一個字節(jié)8個點。(內(nèi)函數(shù),私有,用戶不直接調(diào)用) -------------------------------------------------------------------------------- -*/ void PutCharR(uchar ch) { OUTSD(ch); }
/* --------------------------------------------------------------------------------
調(diào)用方式:void PutChar1(uchar ch) 函數(shù)說明:在左頁當(dāng)前地址畫一個字節(jié)8個點。(內(nèi)函數(shù),私有,用戶不直接調(diào)用) -------------------------------------------------------------------------------- -*/ void PutCharL(uchar ch) { OUTMD(ch); }
/* --------------------------------------------------------------------------------
調(diào)用方式:void DrawBmp(bit layer,uchar width,uchar *bmp) 函數(shù)說明:畫一個圖,layer表示上下層,width是圖形的寬,高都是16,bmp是 圖形指針 使用zimo3軟件,縱向取模,字節(jié)倒序/240字節(jié) -------------------------------------------------------------------------------- -*/ void DrawBmp(bit layer,uchar width,uchar *bmp) { uchar x,address,i=0; //address表示顯存的物理地址 uchar page=0; //page表示上下兩頁 bit window=0; //window表示左右兩頁 //putcharR //右邊 //putcharL //左邊
for (x=width;x>1;x--) { if (i>60) {window=1;address=i%61;} else address=i;
if(layer==0) //顯示一行八個字 { SetPage(0,0); SetAddress(address,address); if(window==1)PutCharR(bmp[i]); else PutCharL(bmp[i]); SetPage(1,1); SetAddress(address,address); if(window==1)PutCharR(bmp[i+width]); else PutCharL(bmp[i+width]); } else { //顯示第二行八個漢字 SetPage(2,2); SetAddress(address,address); if(window==1)PutCharR(bmp[i]); else PutCharL(bmp[i]); SetPage(3,3); SetAddress(address,address); if(window==1)PutCharR(bmp[i+width]); else PutCharL(bmp[i+width]); } i++;
} }
/* --------------------------------------------------------------------------------
調(diào)用方式:void clrscr(void) 函數(shù)說明:清屏 -------------------------------------------------------------------------------- -*/ 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++){PutCharR(0);PutCharL(0);} } }
//----------------------------------------------------------- //圖片顯示 //采用字模2生成或字模3生成的都可以. //----------------------------------------------------------- void DrawBmp1(uint x_add, uchar width,uchar *bmp) { uchar x,address,i=0; //address表示顯存的物理地址 uchar page=0; //page表示上下兩頁 bit window=0; //window表示左右兩頁 //putcharR //右邊 //putcharL //左邊 for (x=width;x>1;x--) { if (x_add>60) {window=1;address=x_add%61;} else address=x_add;
SetPage(0,0); SetAddress(address,address); if(window==1)PutCharR(bmp[i]); else PutCharL(bmp[i]); SetPage(1,1); SetAddress(address,address); if(window==1)PutCharR(bmp[i+width]); else PutCharL(bmp[i+width]);
SetPage(2,2); SetAddress(address,address); if(window==1)PutCharR(bmp[i+width+width]); else PutCharL(bmp[i+width+width]); SetPage(3,3); SetAddress(address,address); if(window==1)PutCharR(bmp[i+width+width+width]); else PutCharL(bmp[i+width+width+width]); i++; x_add++;
} }
//--------------------------------------------------------------- //--------------------------------------------------------------- //采用zimo2 顯示漢字,以漢字的顯示方式 //void Draw_word(uchar d_where,uint x_add,bit layer,uchar width) //d_where表示在碼表中第幾個漢字,x_add橫坐標位置,layer顯示的層, width顯示的寬度。 //---------------------------------------------------------------
void Draw_word(uchar d_where,uint x_add,bit layer,uchar width) { uchar x,i=0,address; //address表示顯存的物理地址 uchar page=0; //page表示上下兩頁 bit window=0; //window表示左右兩頁 //putcharR //右邊 //putcharL //左邊 d_where=d_where*32;
for (x=width;x>1;x--) { if (x_add>60) {window=1;address=x_add%61;} else address=x_add;
if(layer==0) //顯示一行八個字 {
SetPage(0,0); SetAddress(address,address); if(window==1)PutCharR(bmp001[d_where]);//右邊 else PutCharL(bmp001[d_where]);//左邊 SetPage(1,1); SetAddress(address,address); if(window==1)PutCharR(bmp001[d_where+width]); else PutCharL(bmp001[d_where+width]);
} else { //顯示第二行八個漢字 SetPage(2,2); SetAddress(address,address); if(window==1)PutCharR(bmp001[d_where]);//右邊 else PutCharL(bmp001[d_where]);//左邊 SetPage(3,3); SetAddress(address,address); if(window==1)PutCharR(bmp001[d_where+width]); else PutCharL(bmp001[d_where+width]);
} x_add++; d_where++; } } /* //------------------------------------------------------------------ //字模2顯示一個漢字 //縱向取模,字節(jié)倒序 void disp_one(bit top_low,bit widows,uchar address,uchar width,uchar*bmp) { if(top_low==0) { SetPage(0,0); SetAddress(address,address); if(window==1)PutCharR(bmp001[next][i]); else PutCharL(bmp001[next][i]); SetPage(1,1); SetAddress(address,address); if(window==1)PutCharR(bmp001[next][i+width]); else PutCharL(bmp001[next][i+width]); } else { SetPage(0,0); SetAddress(address,address); if(window==1)PutCharR(bmp001[next][i]); else PutCharL(bmp001[next][i]); SetPage(1,1); SetAddress(address,address); if(window==1)PutCharR(bmp001[next][i+width]); else PutCharL(bmp001[next][i+width]); } } */
//液晶顯示規(guī)則 // M(左) S(右) // page page // 0 | 0 // 1 | 1 // 2 | 2 // 3 | 3
void delay1s(unsigned char i) { while(i>1) { i--;
delay(65530); } }
//顯示動態(tài)的等待圖標 void wait1(unsigned char i) { for(;i>1;i--) {delay1s(2); clrscr(); // DrawBmp1(0,60,Bmptc); // DrawBmp1(76,19,Bmpt1); // delay1s(2); clrscr(); // DrawBmp1(0,60,Bmptc); // DrawBmp1(76,19,Bmpt2); // delay1s(2); clrscr(); // DrawBmp1(0,60,Bmptc); // DrawBmp1(76,19,Bmpt3); // delay1s(2); clrscr(); // DrawBmp1(0,60,Bmptc); // DrawBmp1(76,19,Bmpt4); // delay1s(2); clrscr(); // DrawBmp1(0,60,Bmptc); // DrawBmp1(76,19,Bmpt5); // delay1s(2); clrscr(); // DrawBmp1(0,60,Bmptc); // DrawBmp1(76,19,Bmpt6); // delay1s(2); clrscr(); // DrawBmp1(0,60,Bmptc); // DrawBmp1(76,19,Bmpt7); // }
}
//演示程序 void main() {
lcdini(); //reset clrscr(); //clr
Draw_word(0,0,0,16); // Draw_word(1,16,0,16); // Draw_word(2,32,0,16); // Draw_word(3,48,0,16); // Draw_word(0,64,0,16); // Draw_word(1,80,0,16); // Draw_word(2,96,0,16); //
DrawBmp(1,120,Bmp002); // clrscr(); // delay1s(3); DrawBmp1(0,122,Bmp012); //LOGO while(1) { delay1s(3);
clrscr(); // DrawBmp1(10,101,Bmp07); //
delay1s(8); clrscr(); // wait1(3); DrawBmp1(0,122,Bmp04); // delay1s(8); clrscr(); // wait1(3); DrawBmp1(0,122,Bmp03); //超前科技 delay1s(8); clrscr(); // wait1(3); clrscr(); // DrawBmp1(10,101,Bmp05); // delay1s(8); clrscr(); // wait1(3); clrscr(); // DrawBmp1(10,101,Bmp06); // delay1s(8); clrscr(); // wait1(3); clrscr(); // DrawBmp1(10,101,Bmp08); // delay1s(8); clrscr(); // wait1(3); clrscr(); // DrawBmp1(0,122,Bmp01); //這仿真器真不錯,用過都說好. wait1(8); } |
|
|
發(fā)表評論 告訴好友 打印此文 收藏此頁 關(guān)閉窗口 返回頂部 |
|
|