#include "reg52.h" #include "absacc.h" #include "intrins.h" #include "math.h" #include "stdio.h" #define uchar unsigned char #define uint unsigned int sbit A0=P2^5; sbit RW=P2^6; sbit E1=P2^4; sbit E2=P2^7; /* sbit A0 = 0xb3; sbit E2 = 0xb4; sbit E1 = 0xb5; sbit RW=P1^6; */ //sfr DATA = 0x80;//数据 #define DATA P0 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 OutMI(uchar i) 函数说明:发指令i到主窗口。(内函数,私有,用户不直接调用) ------------------------------------------------------------------------------*/ void OutMI(uchar i) { E1=1; A0=0; RW=0; DATA=i; E1=0; } /*------------------------------------------------------------------------------ -- 调用方式:void OutMD(uchar i) 函数说明:发数据i到主窗口。(内函数,私有,用户不直接调用) -------------------------------------------------------------------------------- -*/ void OutMD(uchar i) { E1=1; A0=1; RW=0; DATA=i; E1=0; } /* 读主窗口状态*/ /* uchar lcd_MRE(void) { uchar i; E1=1; A0=0; RW=1; i=DATA; E1=0; return(i); } */ /* 读主窗口数据*/ /* uchar lcd_MRD(void) { uchar i; E1=1; A0=1; RW=1; i=DATA; E1=0; return(i); } */ /*------------------------------------------------------------------------------ -- 调用方式:void OutSI(uchar i) 函数说明:发指令i到从窗口。(内函数,私有,用户不直接调用) -------------------------------------------------------------------------------- -*/ void OutSI(uchar i) { E2=1; A0=0; RW=0; DATA=i; E2=0; }
/*------------------------------------------------------------------------------ -- 调用方式:void OutSD(uchar i) 函数说明:发数据i到从窗口。(内函数,私有,用户不直接调用) -------------------------------------------------------------------------------- -*/ void OutSD(uchar i) {
E2=1; A0=1; RW=0; DATA=i; E2=0; } /* 读从窗口状态*/ /* uchar lcd_SRE(void) { uchar i; E2=1; A0=0; RW=1; i=DATA; E2=0; return(i); } */ /* 读从窗口数据*/ /* uchar lcd_SRD(void) { uchar i; E2=1; A0=1; RW=1; i=DATA; E2=0; return(i); } */ /*------------------------------------------------------------------------------ -- 调用方式:void LcdIni(void) 函数说明:12232点阵液晶初始化,开机后仅调用一次。 -------------------------------------------------------------------------------- -*/ void LcdIni(void) { OutMI(0XE2);OutSI(0XE2);//复位 OutMI(0XAE);OutSI(0XAE);//POWER SAVE OutMI(0XA4);OutSI(0XA4);//动态驱动 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); }
/*------------------------------------------------------------------------------ -- 调用方式:void SetPage(uchar page0,uchar page1) 函数说明:同时设置主从显示页为0-3页。(内函数,私有,用户不直接调用) -------------------------------------------------------------------------------- -*/ void SetPage(uchar page0,uchar page1) { OutMI(0xB8|page1);OutSI(0xB8|page0); } /*------------------------------------------------------------------------------ -- 调用方式:void SetAddress(uchar address0,uchar address1) 函数说明:同时设置主从列地址为0-121。(内函数,私有,用户不直接调用) -------------------------------------------------------------------------------- -*/ void SetAddress(uchar address0,uchar address1) { OutMI(address1&0x7F);OutSI(address0&0x7F); }
/*------------------------------------------------------------------------------ -- 调用方式:void PutChar0(uchar ch) 函数说明:在左页当前地址画一个字节8个点。(内函数,私有,用户不直接调用) -------------------------------------------------------------------------------- -*/ void PutCharL(uchar ch) { OutSD(ch); } /*------------------------------------------------------------------------------ -- 调用方式:void PutChar1(uchar ch) 函数说明:在右页当前地址画一个字节8个点。(内函数,私有,用户不直接调用) -------------------------------------------------------------------------------- -*/ void PutCharR(uchar ch) { OutMD(ch); }
/*------------------------------------------------------------------------------ -- 调用方式:void DrawBmp(uchar x,bit layer,uchar width,uchar *bmp) 函数说明:画一个图,横坐标是x,layer表示上下层,width是图形的宽,高都是16,bmp是 图形指针 使用zimo21软件,采用纵向取模得到bmp数据。 -------------------------------------------------------------------------------- -*/ void DrawBmp(uchar x0,bit layer,uchar width,uchar *bmp) { uchar x,address,i=0; uchar page=2; bit window=0; if (layer) page=0;
for (x=x0;x<x0+width;x++) { if (x>60) { window=1; address=x%61; } else address=x; SetPage(0xB8|page,0xB8|page); SetAddress(address&0x7F,address&0x7F);
if (window) OutSI(bmp); else OutMD(bmp); SetPage(0xB8|(page+1),0xB8|(page+1)); SetAddress(address&0x7F,address&0x7F);
if (window) OutSI(bmp[i+width]); else OutMD(bmp[i+width]);
i++; } } /* --------------------------------------------------------------------------------
调用方式:void DrawBmp(bit layer,uchar width,uchar *bmp) 函数说明:画一个图,layer表示上下层,width是图形的宽,高都是16,bmp是 图形指针 使用zimo3软件,纵向取模,字节倒序/240字节 -------------------------------------------------------------------------------- -*/ /* 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); else PutCharL(bmp); 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); else PutCharL(bmp); SetPage(3,3); SetAddress(address,address); if(window==1)PutCharR(bmp[i+width]); else PutCharL(bmp[i+width]); } i++; } } */ /*------------------------------------------------------------------------------ -- 调用方式:void clrscr(void) 函数说明:清屏 -------------------------------------------------------------------------------- -*/ 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++){PutCharL(0);PutCharR(0);} } }
//延时 void delay(unsigned int i) { unsigned char k=200; while(i>0) { i--; } while(k>1)k--; } 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)PutCharL(bmp); else PutCharR(bmp); SetPage(1,1); SetAddress(address,address); if(window==1)PutCharL(bmp[i+width]); else PutCharR(bmp[i+width]); SetPage(2,2); SetAddress(address,address); if(window==1)PutCharL(bmp[i+width+width]); else PutCharR(bmp[i+width+width]); SetPage(3,3); SetAddress(address,address); if(window==1)PutCharL(bmp[i+width+width+width]); else PutCharR(bmp[i+width+width+width]); i++; x_add++; } } 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++; } } void delay1s(unsigned char i) { while(i>1) { i--; delay(65530); } } 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() { uint j; 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); //** 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); } } |