首 页文档资料下载资料维修视频包年699元
请登录  |  免费注册
当前位置:精通维修下载 > 文档资料 > 家电技术 > 单元电路介绍 > 其它电路
12864显示屏4*4键盘实验
来源:本站整理  作者:佚名  2011-02-05 21:45:30



12864显示屏4*4键盘实验输出结果:获得键值通过发光二极管显示            
#include <reg52.h>

unsigned char code IC_DAT[];

sbit RS=P3^6;     //RS="H",表示DB7--DB0为显示数据,
                  //RS="L",表示DB7--DB0为显示指令数据

sbit WRD = P2^5;  //R/W="H",E="H",数据被读到DB7--DB0
                   //R/W="L",E="H→L", DB7--DB0的数据被写到IR或DR

sbit E = P2^6;    //使能信号

sbit PSB = P2^3;  //H:并口方式 L:串口方式


void    TransferData(char data1,bit DI); //传送数据或者地址命令(data),
                                         //当DI=0是,传送命令,当DI=1,传送数据.
void    display(void);
void    display_grapic(void);

void    delay1(unsigned int t);
void    delay(unsigned int m);
void    delayms(unsigned int n);

void    DisplayLine(unsigned char line1,unsigned char line2);
void    DisplayGraphic(unsigned char code *adder);

void    LCD_mesg(unsigned char code *adder1);
Key_return(char keyvalue);
keysCAN();
/***************屏幕显示结果*********************/
unsigned char code IC_DAT[]={
"天华杯老师培训班"
"******    ******"
"    按键键值    "
"地点:35号楼 505"
};
unsigned char data1[]={"0123456789ABCDEF "};
/***************LCD字库初始化程序*********************/
void initinal(void)         
          {
           delay(40);               //大于40MS的延时程序
           PSB=1;                   //设置为8BIT并口工作模式
           delay(1);                //延时
          // RES=0;                 //复位
          // delay(1);              //延时
          // RES=1;                 //复位置高
           delay(10);
           TransferData(0x30,0);  //Extended Function Set :8BIT设置,RE=0: basic instruction set, G=0 :graphic display OFF
           delay(100);            //大于100uS的延时程序
           TransferData(0x30,0);  //Function Set
           delay(37);             ////大于37uS的延时程序
           TransferData(0x08,0);  //Display on Control
           delay(100);            //大于100uS的延时程序
           TransferData(0x10,0);  //Cursor Display Control光标设置
           delay(100);            //大于100uS的延时程序
           TransferData(0x0C,0);  //Display Control,D=1,显示开
           delay(100);            //大于100uS的延时程序
           TransferData(0x01,0);  //Display Clear    清屏
           delay(10);             //大于10mS的延时程序
           TransferData(0x06,0);  //Enry Mode Set,光标从右向左加1位移动
           delay(100);            //大于100uS的延时程序
          }


//*************显示函数******************************

void lcd_mesg(unsigned char code *adder1)
{
    unsigned char i;
        TransferData(0x80,0);    //Set Graphic Display RAM Address 传地址指令
        delay(100);
    for(i=0;i<32;i++)
        {
              TransferData(*adder1,1);
               adder1++;
        }

        TransferData(0x90,0);    //Set Graphic Display RAM Address
        delay(100);

    for(i=0;i<32;i++)
        {
              TransferData(*adder1,1);
               adder1++;
        }
}
//*************位置显示函数******************************
void lcd_wxs1(unsigned int adder2)
{
        TransferData(0x8C,0);    //Set Graphic Display RAM Address 传地址指令
        delay(100);    
          TransferData(adder2,1);
        TransferData(data1[16],1);
}
/***************键盘扫描子程序*************/
keyscan()  
{    
    char sCCode,recode,tcode,i,keyvalue,temp;
    P1=0xf0;  //发全“0”行扫描,列线输入
    if((P1&0xf0)!=0xf0) //有键按下
        { 
            delay1(10);   //延时去抖动
            tcode=0x01;
           if((P1&0xf0)!=0xf0)
                {
                    for(i=0;i<4;i++)
                      {
                        sccode=~tcode;  //扫描初始值
                       P1=sccode;     //输出行扫描码
                       if((P1&0XF0)!=0XF0)  //本行有键按下
                            {
                              recode=P1&0xf0;
                              //recode=recode>>4;
                              recode=recode+0x0f;
                              temp=((~sccode)+(~recode));
                              keyvalue=Key_return(temp);  //返回特征码
                              return keyvalue;
                            }
                         else
                        tcode=tcode<<1;  //行扫描码左移一位
                         }
                }

            }
    else
    return keyvalue;  //无键按下,返回0
}

/***************查键值子程序*************/
Key_return(char keyvalue)
{
    unsigned int Key_num;
  //keyword=keyvalue;
     switch(keyvalue)
           {
           case(0x11):
                      {
                      Key_num=0x00;
                      }break;
           case(0x12):
                      {
                      Key_num=0x04;
                      }break;
           case(0x14):
                      {
                      Key_num=0x08;
                      }break;
           case(0x18):
                      {
                      Key_num=0x0c;
                      }break;
           case(0x21):
                      {
                      Key_num=0x01;
                      }break;
           case(0x22):
                      {
                      Key_num=0x05;
                      }break;
           case(0x24):
                      {
                      Key_num=0x09;
                      }break;
           case(0x28):
                      {
                      Key_num=0x0d;
                      }break;
           case(0x41):
                      {
                      Key_num=0x02;
                      }break;
           case(0x42):
                      {
                      Key_num=0x06;
                      }break;
           case(0x44):
                      {
                      Key_num=0x0a;
                      }break;
           case(0x48):
                      {
                      Key_num=0x0e;
                      }break;
           case(0x81):
                      {
                      Key_num=0x03;
                      }break;
           case(0x82):
                       {
                       Key_num=0x07;
                       }break;
           case(0x84):
                       {
                       Key_num=0x0b;
                       }break;
           case(0x88):
                      {
                      Key_num=0x0f;
                      }break;
           default:break;
           }
           return Key_num;
}

//********写命令/数据*******************************

void    TransferData(char data1,bit DI)  //传送数据或者命令,当DI=0是,传送命令,
          {                                 //当DI=1,传送数据.
            WRD=0;    //R/W="H",E="H",数据被读到DB7--DB0,R/W="L",E="H→L", DB7--DB0的数据被写到IR或DR
            RS=DI;    //RS="H",表示DB7--DB0为显示数据, RS="L",表示DB7--DB0为显示指令数据
            delay(1);
            P0=data1;
            E=1;
            delay(1);
            E=0;
           }
//************延 时*******************************************
void  delayms(unsigned int n)            //延时10×n毫秒程序
                   {
                      unsigned int i,j;
                      for(i=0;i<n;i++)
                         for(j=0;j<2000;j++);
                   }

void  delay(unsigned int m)              //延时程序
                   {
                      unsigned int i,j;
                      for(i=0;i<m;i++)
                         for(j=0;j<10;j++);
                   }

void delay1(unsigned int t)
{
unsigned int i;
for(i=0;i<t;i++)
//for(j=0;j<10;j++)
;
}
//************主函数**************************************
void main(void)
     {
     unsigned int e; 
     initinal(); //调用LCD字库初始化程序 
     delay(10);            //大于100uS的延时程序
     lcd_mesg(IC_DAT);      //显示中文汉字1    
         while(1)
        {
          e=keyscan();   //键盘扫描值
          lcd_wxs1(data1[e]);
        }
      }

//************结 束******************************************

 

关键词:

·上一文章:红外遥控解码程序
·下一文章:KS0108 12864显示屏程序

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分)
Copyright © 2007-2017 down.gzweix.Com. All Rights Reserved .
页面执行时间:328,222.70000 毫秒