技术资料>51单片机

LCD12232液晶的模块化程序(51单片机)

发布时间:2018-03-26   浏览量:

 

 

/*******************************************************************

         lcd12232.h头文件

*******************************************************************/

#ifndef _LCD12232_H_
#define _LCD12232_H_
extern void lcd12232_busy(); //忙标志函数
extern void lcd12232_init(); //初始化函数
extern void lcd12232_clear();//清屏函数
extern void lcd12232_hanzi(unsigned char m,unsigned char n,unsigned char p,unsigned char y);//第一个参数代表的是共显示几个字(空格也算一个汉字),第二个参数是从第几个字开始显示,第三个参数是选屏,第四个是页地址
                   //选屏函数,2为两屏,1为左屏,0为右屏
                   //页地址设置的参数值应该为0、1、2三个数中的一个,因为液晶一共分为四页
//extern void lcd12232_zifu(unsigned char m,unsigned char n,unsigned char y,unsigned char d);//第一个参数代表的是第几个字,第二个参数是选屏,第三个参数是页地址,第四个参数是列地址
#endif 

/*******************************************************************

         lcd12232.c文件

*******************************************************************/

#include
#define uchar unsigned char
#define uint  unsigned char
#define port P0
sbit e1=P2^1;
sbit e2=P2^2;
sbit a0=P2^0;
sbit rw=P2^3;
uchar code ziku[]=
{

 0x00,0x00,0x00,0xC0,0x70,0x20,0x00,0xFF,0x00,0x10,0x20,0xC0,0x80,0x00,0x00,0x00,//小
 0x04,0x02,0x01,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x07,0x02,0x00,

 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"空" 什么也不显示,需要的时候把它放在任意位置来当空格使用
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

 0x00,0x04,0x84,0x44,0x3C,0x44,0x85,0x06,0x04,0xC4,0x3C,0x44,0x84,0x04,0x00,0x00,//卒
 0x04,0x05,0x04,0x04,0x04,0x04,0x05,0xFE,0x05,0x04,0x04,0x04,0x05,0x04,0x04,0x00,

 0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00,//设
 0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00,

 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"空"
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

 0x20,0x21,0x2E,0xE4,0x00,0x00,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x00,//计
 0x00,0x00,0x00,0x7F,0x20,0x10,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,

 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!
 0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//,
 0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  

 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//。
 0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

 0x80,0x84,0x44,0x44,0x24,0x14,0x04,0xFF,0x04,0x14,0x24,0x24,0x46,0xC4,0x40,0x00,//"李"
 0x00,0x08,0x08,0x08,0x09,0x49,0x89,0x7D,0x0D,0x0B,0x09,0x08,0x0C,0x08,0x00,0x00,

 0x10,0x10,0x10,0xFF,0x90,0x50,0xFE,0x92,0x92,0x92,0x92,0x92,0x9A,0xD3,0x82,0x00,//"振"  
 0x02,0x42,0x81,0x7F,0x40,0x30,0x0F,0x00,0xFF,0x40,0x07,0x18,0x28,0x64,0x22,0x00,

 0x80,0x40,0x20,0xF8,0x07,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x68,0x4C,0x08,0x00,//"伟"
 0x00,0x00,0x00,0xFF,0x02,0x02,0x02,0x02,0x02,0xFF,0x02,0x12,0x22,0x1F,0x02,0x00
};
void delay(uchar z)    //延时函数
{
     int x;
     for(x=z;x>0;x--);
}
void lcd12232_cs(uchar cs) //选屏函数,2为两屏,1为左屏,0为右屏
{
   switch(cs)
   {
    case 0:e1=1,e2=0;break;
    case 1:e1=0;e2=1;break;
    case 2:e1=0;e2=0;break;
    case 3:e1=1;e2=1;break;  
   }
}
void lcd12232_write_com(uchar com,uchar n)//写命令函数
{
 lcd12232_cs(3);
 a0=0;
 rw=0;
 port=com;
 //delay(1);
 lcd12232_cs(n);
 delay(1);
}
void lcd12232_write_dat(uchar dat,uchar n)//写数据函数
{
a0=1;
rw=0;
lcd12232_cs(3);
port=dat;
lcd12232_cs(n);
}
uchar lcd12232_read()   //读状态函数
{
 uchar dat;
 //e1=0;e2=0;
 lcd12232_cs(2);
 a0=0;
 rw=1;
 port=0xff;
 delay(1);
 //e1=1;e2=1;
 lcd12232_cs(3);
 dat=port;
 delay(1);
 //e1=0;e2=0;
 lcd12232_cs(2);
 return dat;
}
void lcd12232_busy()
{
 uchar i;
 i=lcd12232_read();
 while(i&0x80==0x80);
}
void lcd12232_clear()    //清屏函数
{
 uchar i;
 lcd12232_write_com(0xb8,2);
 lcd12232_write_com(0x00,2);
 for(i=0;i<255;i++)
 lcd12232_write_dat(0x00,2);
}
void lcd12232_init() //第一个参数为指令,第二个参数为选屏,2为两屏,1为左屏,0为右屏
{
 lcd12232_write_com(0xe2,2);//复位
 lcd12232_write_com(0xaf,2);//总显示开
 lcd12232_write_com(0xc0,2);//从第一行开始显示数据
 lcd12232_write_com(0xb8,2);//设置显示页地址为第一页
 lcd12232_write_com(0x00,2);//设置显示列地址为第一列
 lcd12232_write_com(0xa1,2);//设置正向显示,a0为逆向显示
 lcd12232_write_com(0xa9,2);// 1/32占空比
 lcd12232_write_com(0xa4,2);//动态驱动
 lcd12232_write_com(0xee,2);
 lcd12232_clear();     //清屏
}
void lcd12232_hanzi(uchar m,uchar n,uchar p,uchar y)   //汉字显示函数,第一个参数代表的是显示m个字,第二个参数是从第n个字开始显示,第三个参数是选屏,第四个是页地址
{
 uchar i,a;
 lcd12232_write_com(0x00,2);
 lcd12232_write_com(0xb8+y,2);
 for(a=0;a  {
  for(i=0;i<16;i++)
  {
   lcd12232_write_dat(ziku[i+a*32+(n-1)*32],p);
  }
 }

 lcd12232_write_com(0x00,2);
 lcd12232_write_com(0xb9+y,2);
 for(a=0;a  {
  for(i=0;i<16;i++)
  {
   lcd12232_write_dat(ziku[i+a*32+16+(n-1)*32],p);
  }
 }
}
/*void lcd12232_zifu(uchar m,uchar n,uchar y,uchar d)  //第一个参数代表的是第几个字,第二个参数是选屏,第三个参数是页地址,第四个参数是列地址
{
 uchar i;
 lcd12232_write_com(0xb8+y,2);
 lcd12232_write_com(0x00+d,2);
 for(i=0;i<16;i++)
 {
 lcd12232_write_dat(ziku[m*32+i],n);
 }
 lcd12232_write_com(0xb9+y,2);
 lcd12232_write_com(0x00+d,2);
 for(i=0;i<16;i++)
 {
 lcd12232_write_dat(ziku[m*32+i+16],n);
 }
} */

/*******************************************************************

           main.c主文件

*******************************************************************/

#include
#include"lcd12232.h"
void main()
{     
lcd12232_init(); //初始化
lcd12232_clear();//清屏
lcd12232_busy();//忙检测
lcd12232_hanzi(3,1,1,1);//第一个参数代表的是共显示几个字(空格也算一个汉字),第二个参数是从第几个字开始显示,第三个参数是选屏,第四个参数是页地址
lcd12232_busy();
lcd12232_hanzi(4,4,0,1);

//lcd12232_zifu(0,1,0,0);//第一个参数代表的是第几个字,第二个参数是选屏,第三个参数是页地址,第四个参数是列地址
while(1);
}