三.软件设计
/*****************************************************************
*程序名称:带汉字库的12864液晶显示模块驱动
*程序功能:显示字符 、汉字和图片
*开发工具:WSF-51DB开发板
* MCU型号:AT89S52-24PU
*时钟频率:12MHZ
*程序作者:吴师傅
*版权说明:吴师傅版权所有。转载请注明来源和作者
*****************************************************************/
#include<reg52.h>
sbit E=P3^4;//脉冲使能
sbit RW=P3^3;//读写选择
sbit RS=P3^2;//数据命令选择
sbit rst=P1^0;//12864复位
unsigned char code pictrue2[192]={//图片:机器猫48*32
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X7F,0X80,0X00,0X00,0X00,0X1F,0XFF,
0XFE,0X00,0X00,0X00,0X7F,0X1F,0XFF,0X80,0X00,0X01,0XFC,0X0C,0X3F,0XE0,0X00,0X07,
0XF8,0X48,0X1F,0XF8,0X00,0X0F,0X98,0XD1,0X8F,0XFC,0X00,0X1C,0X4C,0XF3,0X9F,0XFE,
0X00,0X1A,0X33,0X39,0XB3,0XFE,0X00,0X33,0XE3,0XFC,0X40,0XFE,0X00,0X31,0X81,0XE1,
0X9E,0X7F,0X00,0X10,0XC1,0X03,0XC0,0X3E,0X00,0X18,0X01,0X03,0X70,0X9E,0X00,0X1F,
0X03,0X03,0X83,0X9E,0X00,0X09,0XE2,0X00,0X3E,0X1C,0X00,0X04,0X3F,0X80,0XFF,0X3C,
0X00,0X07,0X01,0XFF,0XC0,0X70,0X00,0X0F,0XC0,0X00,0X00,0XE0,0X00,0X1F,0XF8,0X00,
0X03,0X80,0X0F,0X0C,0X3F,0XE0,0X1E,0X00,0X39,0XED,0X3B,0XFF,0XFF,0X00,0X20,0X7A,
0XFE,0X07,0XFF,0X80,0X60,0X1C,0X1C,0X07,0XFF,0X80,0X60,0X0F,0X03,0XF7,0XFF,0X80,
0X20,0X0F,0XDE,0X3F,0XFF,0X80,0X30,0X0F,0XF0,0X0F,0XFF,0XA0,0X1C,0X0F,0XE0,0X07,
0XF8,0X30,0X0F,0XFF,0XE0,0X03,0XC8,0X60,0X01,0XE0,0X20,0X03,0X87,0XC0,0X00,0X00,
0X30,0X07,0X00,0X00,0X00,0X00,0X0C,0X0C,0X00,0X00,0X00,0X00,0X07,0XF0,0X00,0X00,
};
// 延时ms函数:
void Delayms(unsigned int t)
{
unsigned int i,j;
for(i=t;i>0;i--)
for(j=0;j<120;j++);
}
// 12864检查状态函数:
void Check12864State(void)
{
P2=0xff;
E=0;//读状态前三控制线的状态
RS=0;
RW=1;
E=1;//拉高,读状态
while((P2&0x80)==0x80);//等待空闲
E=0;//写命令后三控制线的状态
RS=1;
RW=0;
}
// 12864写命令函数:
void Write12864Command( unsigned char com)
{
Check12864State();//检查状态
P2=com;//赋值
E=0;//写命令前三控制线的状态
RS=0;
RW=0;
E=1;//拉高,写命令
E=0;//写命令后三控制线的状态
RS=1;
RW=1;
} |