--  122*32液晶显示程序,显示图形及汉字.

/*============================================================
功能:使用12232液晶显示图片演示
==============================================================
硬件:TG12232B 122*32)模拟口线接线方式
连接线图:
--------------------------------------------------|
|DB0-----P0.0 | DB4-----P0.4 | RW-------P1.1 | A0--------P1.0 |
|DB1-----P0.1 | DB5-----P0.5 | RS-------P2.1 | V01K电阻到GND |
|DB2-----P0.2 | DB6-----P0.6 | E1-------P1.3 |
|DB3-----P0.3 | DB7-----P0.7 | E2-------P1.2 | 
---------------------------------------------------
本程序源码只供学习参考,如有需要请联系作者。
[:AT89x52使用22.1184M11.0592M晶振,实测使用22.1184M11.0592都可以]
编译平台:Keil uV2 7.08
//可能看起来有点乱,不过效果还是不错的,显示图形总的来说比显示汉字要简单,当然显示汉字也不难。
希望此程序能给你一些帮助。
=============================================================*/
#include <AT89X52.H>
#define uchar unsigned char
#define uint unsigned int
#define E1 P1_3  //左边
#define E2 P1_2  //右边
#define RW P1_1
#define A0 P1_0  //A01时是数据,0时为指令数据
#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[];
values是什么意思英语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--;
}
/
/左页
//发送数据
void OUTMD(unsigned char i)
{
A0=1; //写数据
//delay(5);
E1=1;
//delay(10);
DATA=i;
//delay(5);
E1=0;

}
//左页
//发送命令
void OUTMI(unsigned char i)
{
A0=0; //写指令
//delay(5);
E1=1;
//delay(10);
DATA=i;
//delay(5);
E1=0;

}
//右页
//发送数据
void OUTSD(unsigned char i)
{
A0=1; //写数据
//delay(5);
E2=1;
//delay(10);
DATA=i;
//delay(5);
E2=0;
}
//右页
//发送命令
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);//复位
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);


}
/*
函数说明:同时设置主从显示页为03页。(内函数,私有,用户不直接调用)
------------------------------------------------------------------------
*/
void SetPage(uchar page0,uchar page1)
{
OUTMI(0xB8|page1);OUTSI(0xB8|page0);
}
/*
--------------------------------------------------------------------------------
函数说明:同时设置主从列地址为0121。(内函数,私有,用户不直接调用)
--------------------------------------------------------------------------------
*/
void SetAddress(uchar address0,uchar address1)
{
OUTMI(address1);OUTSI(address0);
}
/*
--------------------------------------------------------------------------------
调用方式:void PutChar0(uchar ch)
函数说明:在右页当前地址画一个字节8个点。(内函数,私有,用户不直接调用)
--------------------------------------------------------------------------------
-*/
void PutCharR(uchar ch)
{
OUTSD(ch);
}
/*
-
-------------------------------------------------------------------------------
调用方式:void PutChar1(uchar ch)
函数说明:在左页当前地址画一个字节8个点。(内函数,私有,用户不直接调用)
--------------------------------------------------------------------------------
-*/
void PutCharL(uchar ch)
{
OUTMD(ch);
}
/*
--------------------------------------------------------------------------------
调用方式:void DrawBmp(bit layer,uchar width,uchar *bmp)
函数说明:画一个图,layer表示上下层,width是图形的宽,高都是16bmp
图形指针
          使用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)
函数说明:清屏
putchar函数--------------------------------------------------------------------------------
-*/
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);
visible什么意思中文翻译else PutCharL(bmp);
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显示一个汉字
//纵向取模,字节倒序
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]);
else PutCharL(bmp001[next]);
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]);
else PutCharL(bmp001[next]);
SetPage(1,1);
SetAddress(address,address);
if(window==1)PutCharR(bmp001[next][i+width]);
else PutCharL(bmp001[next][i+width]);
}
}
*/
//液晶显示规则
// M()  S()
// page  page
// 0 | 0
// 1 | 1
// 2 | 2
示波器直方图怎么看// 3 | 3
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()                                                                                                                         
从java转abap后悔了{               
                                                                                                   
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); //

c程序设计谭浩强pdf百度网盘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);
}                                                       
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。