header
×
单片机 > 单片机程序设计 > 详情

PIC16F74的12864点阵液晶驱动(不带字库)

发布时间:2020-05-16 发布时间:
|
驱动程序如下:

此程序用于12864不带字库点阵液晶屏使用
*/
#include

#define DATA      PORTB      //RB端口为8位数据端口
#define Busy      RB7        //RB7为忙标志位,数据的高位
#define RS        RC1        //控制引脚说明
#define RW        RC2
#define E         RC3
#define CS1       RD2
#define CS2       RD3
//---------------数据定义----------------
//12867为纵向8点下高位
//每一页的排列是纵向8位下高位,从左到右依次为64列
//下面是16*16的点阵字符代码
unsigned char const table[]={0x90,0x8c,0x84,0x84,0x84,0x84,0xf5,0x86,
                             0x84,0x84,0x84,0x84,0x84,0xd4,0x8c,0x00,
                             0x00,0x00,0x80,0x84,0x46,0x49,0x28,0x10,
                             0x10,0x28,0x47,0xc0,0x00,0x00,0x00,0x00};  //汉字安的代码
unsigned char const table1[]={0x08,0x08,0x88,0x88,0x88,0x88,0x88,0xff,
                              0x88,0x88,0x88,0xc8,0x88,0x0c,0x08,0x00,
                              0x00,0x00,0x00,0xfc,0x44,0x44,0x44,0x44,
                              0x44,0x44,0x44,0xff,0x04,0x00,0x00,0x00}; //吉字的点阵码
unsigned char const table2[]={0x10,0x10,0x10,0xd0,0xff,0x90,0x10,0x00,
                              0x10,0xd0,0xff,0x90,0x10,0x18,0x10,0x00,
                              0x08,0x04,0x03,0x00,0xff,0x00,0x09,0x04,
                              0x03,0x00,0xff,0x00,0x03,0x06,0x02,0x00}; //林字的点阵码
unsigned char const table3[]={0x00,0x00,0x00,0xfe,0x82,0x82,0x82,0x82,
                              0x82,0x82,0x82,0xff,0x02,0x00,0x00,0x00,
                              0x00,0x00,0x00,0x7f,0x20,0x20,0x20,0x20,
                              0x20,0x20,0x20,0x7f,0x00,0x00,0x00,0x00}; //日字的点阵码
unsigned char const table4[]={0x40,0x44,0x54,0x65,0xc6,0x64,0xd6,0x44,
                              0x40,0xfc,0x00,0x00,0xc3,0x62,0x40,0x00,
                              0x20,0x11,0x49,0x81,0x7f,0x01,0x05,0x29,
                              0x18,0x07,0x00,0x00,0xff,0x00,0x00,0x00}; //新字的点阵码  
unsigned char const table5[]={0x08,0x08,0x88,0x88,0x88,0x88,0x88,0xff,0x88,0x88,0x88,0xc8,0x88,0x0c,0x08,0x00,
                              0x10,0x10,0x10,0xd0,0xff,0x90,0x10,0x00,0x10,0xd0,0xff,0x90,0x10,0x18,0x10,0x00,
                              0x00,0x00,0x00,0xfe,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xff,0x02,0x00,0x00,0x00,
                              0x40,0x44,0x54,0x65,0xc6,0x64,0xd6,0x44,0x40,0xfc,0x44,0x42,0xc3,0x62,0x40,0x00,
                              0x00,0x00,0x00,0xfc,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xff,0x04,0x00,0x00,0x00,
                              0x08,0x04,0x03,0x00,0xff,0x00,0x09,0x04,0x03,0x00,0xff,0x00,0x03,0x06,0x02,0x00,
                              0x00,0x00,0x00,0x7f,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7f,0x00,0x00,0x00,0x00,
                              0x20,0x11,0x49,0x81,0x7f,0x01,0x05,0x29,0x18,0x07,0x00,0x00,0xff,0x00,0x00,0x00};  //吉林日新
                              
                              
//---------------函数定义----------------
void picint(void);
void Leftwcom(unsigned char com);               //左半屏写指令代码子程序
void Leftwdata(unsigned char ldata);            //左半屏写显示数据子程序 
void Rightwcom(unsigned char rcom);             //右半屏写指令代码子程序
void Rightwdata(unsigned char rdata);           //右半屏写显示数据子程序 
void clear(void);                               //清屏函数
//***************************************
//初始化函数
//***************************************
void picint()
{
  INTCON=0;
  ADCON1=0x07;                                  //AD口为通用IO口
  TRISB=0;                                      //RB端口为输出端口
  PSPMODE=0;                                    //配置D口为通用IO口
  
  TRISC1=0;                                     //输出引脚,控制引脚
  TRISC2=0;
  TRISC3=0;
  TRISD3=0;
  TRISD2=0;
}
//***************************************
//延时函数
//***************************************
void delay(unsigned int asd)
{
  unsigned int i;
  for(i=0;i   {}
}
//***************************************
//左半屏写指令代码子函数
//***************************************
void Leftwcom(unsigned char com)
{
  PORTB=0xff;
  TRISB=0xff;        //设置为输入引脚
  E=1;
  CS1=1;
  CS2=1;
  RS=0;
  RW=1;
  while(1)
  {
    E=1;
    if(RB7==0) break;
    E=0;
  }
  RW=0;
  TRISB=0;
  PORTB=com;
  E=1;                   //送命令
  E=0;
}
//***************************************
//左半屏写显示数据子函数
//***************************************
void Leftwdata(unsigned char ldata)
{
  PORTB=0xff;
  TRISB=0xff;            //设置为输入
  CS1=1;
  CS2=1;
  RS=0;
  RW=1;
  while(1)
  {
    E=1;
    if(RB7==0) break;
    E=0;
  }
  RS=1;
  RW=0;
  TRISB=0;
  PORTB=ldata;
  E=1;
  E=0;

//***************************************
//右半屏写指令代码
//***************************************
void Rightwcom(unsigned char rcom)
{
  PORTB=0xff;
  TRISB=0xff;        //设置为输入引脚
  E=1;
  CS1=1;
  CS2=1;
  RS=0;
  RW=1;
  while(1)
  {
    E=1;
    if(RB7==0) break;
    E=0;
  }
  RW=0;
  TRISB=0;
  PORTB=rcom;
  E=1;               //送命令
  E=0;
}
//***************************************
//右半屏写数据代码
//***************************************
void Rightwdata(unsigned char rdata)
{
  PORTB=0xff;
  TRISB=0xff;     //设置为输入
  CS1=1;
  CS2=1;
  RS=0;
  RW=1;
  while(1)
  {
    E=1;
    if(RB7==0) break;
    E=0;
  }
  RS=1;
  RW=0;
  TRISB=0;
  PORTB=rdata;
  E=1;
  E=0;

//***************************************
//清屏函数
//***************************************
void clear()
{
  unsigned char i ,y;
  for(i=0;i<3;i++)
  {
    Leftwcom(i|0xb8);
    Rightwcom(i|0xb8);
    for(y=0;y<64;y++)
    {
      Leftwdata(0x00);
      Rightwdata(0x00);
    }
  } 
}
//***************************************
//主函数 
//***************************************
void main()
{
  unsigned char i=0;      //查表计数器
  unsigned char z;        //循环计数器
  unsigned char y=0;
  unsigned char e=0x40;
  picint();
  clear();
  while(1)
{
  Leftwcom(0xc0);         //写命令,设置显示其实行为第一行
  Leftwcom(0x3f);         //开显示设置
  Leftwcom(0xb8);         //设置第一页
  Leftwcom(0x40);         //设置显示为第一列
  for(i=0;i<64;i++)
  {
   Leftwdata(table5[i]);
  }
  Leftwcom(0xb9);         //设置第一页
  Leftwcom(0x40);         //设置显示为第一列
  for(i=64;i<128;i++)
  {
    Leftwdata(table5[i]);
  }
  Rightwcom(0xc0);         //写命令,设置显示其实行为第一行
  Rightwcom(0x3f);         //开显示设置
  Rightwcom(0xb8);         //设置第一页
  Rightwcom(0x40);         //设置显示为第一列
  for(i=0;i<64;i++)
  {
   Rightwdata(table5[i]);
  }
  Rightwcom(0xb9);         //设置第一页
  Rightwcom(0x40);         //设置显示为第一列
  for(i=64;i<128;i++)
  {
    Rightwdata(table5[i]);
  }
}
}



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
Keil(C51)介绍.下载.安装与注册
footer