资源描述:
《矩阵键盘lcd显示.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/************键盘部分**********************/#include#include"keyscan.h"voidkey_init(void){KEY_DIR=0x0f;//将P1.0~1.3设置为输出(行),将P1.4~1.7设置为输入(列)}ucharkey_scan(void){uchartmp1,row,key_val,tmp2;ucharkey;tmp1=0x01;KEY_HANG=0xf0;//将行全部拉低,好去判断下面是否有键按下if((KEY_LIE&0xf0)!=0xf0)//
2、判断是否有键按下{delay5ms();//延时5毫秒for(row=0;row<4;row++)//一行一行的扫描{KEY_HANG=~tmp1;//tmp2=KEY_LIE&0xf0;if((KEY_LIE&0xf0)!=0xf0){tmp2=(KEY_LIE&0xf0);key=(KEY_HANG&0x0f)
3、tmp2;break;}elsetmp1<<=1;}while((KEY_LIE&0xf0)!=0xf0);//等待按键释放switch(key)//获取键值{case0xee:key_val='1';break;case0xde:key
4、_val='2';break;case0xbe:key_val='3';break;case0x7e:key_val='A';break;case0xed:key_val='4';break;case0xdd:key_val='5';break;case0xbd:key_val='6';break;case0x7d:key_val='B';break;case0xeb:key_val='7';break;case0xdb:key_val='8';break;case0xbb:key_val='9';break;case0x7b:key_val='C'
5、;break;case0xe7:key_val='*';break;case0xd7:key_val='0';break;case0xb7:key_val='.';break;case0x77:key_val='D';break;default:key_val='#';}}returnkey_val;}/*delay5msforkeydejitter*/voiddelay5ms(void){uinti=2000;while(i--);}/****************LCD部分**************************/#include<
6、msp430x14x.h>#include"cry1602.h"//typedefunsignedcharuchar;//typedefunsignedintuint;#defineucharunsignedchar#defineuintunsignedint/*******************************************显示坐标行列********************************************/voidLocateXY(ucharx,uchary){uchartemp;temp=x&0x0f;y&=
7、0x01;if(y)temp
8、=0x40;//如果在第2行temp
9、=0x80;LcdWriteCommand(temp,1);}/*******************************************显示单字符********************************************/voidDisp1Char(ucharx,uchary,uchardata){LocateXY(x,y);LcdWriteData(data);}/*******************************************LC
10、D初始化********************************************/voidLcdReset(void){CtrlDir
11、=0x38;//控制线端口设为输出状态DataDir=0xFF;//数据端口设为输出状态LcdWriteCommand(0x38,0);//规定的复位操作Delay5ms();LcdWriteCommand(0x38,0);Delay5ms();LcdWriteCommand(0x38,0);Delay5ms();LcdWriteCommand(0x38,1);//显示模式设置LcdWriteComm
12、and(0x08,1);//显示关闭LcdWriteCommand(0x01,1);//显示清屏LcdWri