#include<reg51h>
#include<intrinsh>
#define uchar unsigned char
#define uint unsigned int//矩阵键盘按键特征码表
uchar code KeyCodeTable[]={0x11,0x12,0x14,0x18,0x21,0x22,0x24,0x28,0x41,0x42,0x44,0x48,0x81,0x82,0x84,0x88};//延时
void DelayMS(uint x) // 延时
{
uchar i;
while(x--)
for(i=0;i<120;i++);
}
uchar Keys_Scan() //键盘扫描
{
uchar sCode,kCode,i,k; //低4位置0,放入4行
P1=0xf0;
if((P1&0xf0)!=0xf0) //若高4位出现0,则有键按下
{
DelayMS(2);
if((P1&0xf0)!=0xf0)
{
sCode=0xfe; //行扫描码初值
for(k=0;k<4;k++) //对4行分别进行扫描
{
P1=sCode;
if((P1&0xf0)!=0xf0)
{
kCode=~P1;
for(i=0;i<16;i++) //查表得到按键序号并返回
if(kCode==KeyCodeTable[i])
return(i);
}
else sCode=_crol_(sCode,1);
}
}
}
return(-1);
}
void main() //主程序
{
uchar i,P2_LED,P1_LED;
uchar KeyNo=-1; //按键序号,-1表示无按键
while(1)
{
KeyNo=Keys_Scan(); //扫描键盘获取按键序号KeyNo
if(KeyNo!=-1)
{
P2_LED=0xff;
P1_LED=0xff;
for(i=0;i<=KeyNo;i++) //键值越大,点亮的LED越多
{
if(i<8) P1_LED>>=1;
else P2_LED>>=1;
}
P3=P1_LED; //点亮条形LED
P2=P2_LED;
}
}
}
#include "msp430x44xh "
#define key_press 0x2
//---------------------------------------------------------
static unsigned char flag; //flag register
static unsigned char key_buff; //key vaule buffer
static unsigned char sec;
static unsigned char min; //minuter buffer
static unsigned char hour; //hour buffer
const unsigned char lcd_table[12]={
0x7b, //"0"//
0x12, //"1"//
0x4f, //"2"//
0x1f, //"3"// //lcd display table
0x36, //"4"//
0x3d, //"5"//
0x7d, //"6"//
0x13, //"7"//
0x7f, //"8"//
0x3f, //"9"//
0x6d, //"e"//
0x65, //"f"//
};
const unsigned char key_table[12]={
0x0b, //(key_vaule) 00(key_num)
0x09, //9 01
0x08, //8 02
0x07, //7 03
0x00, //0 04
0x06, //6 05 //key vaule table
0x05, //5 06
0x04, //4 07
0, //# 08
0x03, //3 09
0x02, //2 0a
0x01, //1 0b
};
void rtc(void);
void display_rtc(void);
void display_dec(int i,int j);
void lcd_display (void);
void scan_key_deal(void);
//--------------------------------------------------
//-----------main PROGRAM-----------------------------
//--------------------------------------------------
void main(void)
{
int i;
WDTCTL = WDTPW + WDTHOLD;
BTCTL=BTSSEL+BT_ADLY_250+BTFRFQ1; //BT 025 S interrupt
IE2|=BTIE;
P5SEL=0xfc; //enable lcd display
LCDCTL=LCDON+LCD4MUX+LCDP2;
for (i=0; i<8; ++i) // clear lcd
LCDMEM[i] = 0x00;
_EINT();
//mainloop//
for(;;)
{
_BIS_SR(LPM3_bits); //in LPM3
_NOP();
}
}
// Basic Timer interrupt service routine
interrupt[BASICTIMER_VECTOR] void basic_timer(void)
{
rtc(); //RTC modulate
scan_key_deal(); //scan the queue key
if(flag) //if key press,show the key value
{
flag=flag<0x6fflag+1:0;
lcd_display();
}
else
display_rtc();
}
//--------------------------------------------------------
//---------RTC PROGRAM------------------------------------
//--------------------------------------------------------
void rtc (void)
{
if (++sec < 240)
return;
sec = 0;
if (++min < 60)
return;
min = 0;
if (++hour < 24)
return;
hour = 0;
}
//---------------------------------------------------------
//---------RTC DISPLAY PROGRAM-----------------------------
//---------------------------------------------------------
void display_rtc(void)
{ int i;
i=sec;
i=i>>2;
display_dec(0,i);
i=min;
display_dec(2,i);
i=hour;
display_dec(4,i);
LCDMEM[6]=0x00;
}
//---------------------------------------------------------
//-------- RTC LCD DISPLAY PROGRAM-------------------------
//---------------------------------------------------------
void display_dec(int i,int j)
{
LCDMEM[i]=lcd_table[j%10]+0x80;
LCDMEM[i+1]=lcd_table[j/10];
}
//---------------------------------------------------------
//-------- KEY DISPLAY PROGRAM-----------------------------
//---------------------------------------------------------
void lcd_display (void)
{
int i;
for (i=0;i<7;i++)
LCDMEM[i]=lcd_table[key_buff&0x0f];
}
//---------------------------------------------------------
//------- SCAN KEY PROGRAM---------------------------------
//---------------------------------------------------------
void scan_key_deal(void)
{
unsigned char counter;
unsigned char buffer;
unsigned char com_byte;
unsigned char key_num;
P1DIR=0x0f;
com_byte=0xff;
P1OUT&=~0x08;
P1OUT&=~0x04;
P1OUT&=~0x02;
buffer=P1IN;
if(0xf0!=(buffer&0xf0)) //judge if the key was press
{
P1OUT|=0x08;
P1OUT|=0x04;
P1OUT|=0x02;
com_byte=0xff;
key_num=0x00;
com_byte=0x02;
for(counter=0x03;counter>0;counter--) //get the key num
{
P1OUT&=~com_byte; //scan the row
if(!(P1IN&BIT4))
break;
key_num++;
if(!(P1IN&BIT5))
break;
key_num++;
if(!(P1IN&BIT6))
break;
key_num++;
if(!(P1IN&BIT7))
break;
key_num++;
com_byte=com_byte<<1;
}
flag|=key_press;
buffer=P1IN;
buffer=P1IN;
key_buff=key_table[key_num]; //get the key value
return;
}
// flag&=~key_press;
}
万能键盘驱动程序是一款市场上大多数USB接口键盘驱动程序的整合安装包,只要安装了这一款软件,基本不需要再单独安装其他键盘驱动即可使用。万能键盘驱动程序对硬件的支持和匹配都很出色,PC下载网提供问你键盘驱动程序的下载服务,需要的朋友快来下载吧。

万能键盘驱动程序安装步骤
1、从PC下载网下载万能键盘驱动程序软件包

2、用WinRAR压缩包解压缩后,双击打开安装程序,点击“next”

3、进入安装程序,点击“next”

4、认真阅读协议后,点击“yes”

5、点击“Browse”选择软件安装位置,然后点击“next”

6、等待安装

7、安装完成后,选择是否需要立即重启电脑,然后点击“Finish”

万能键盘驱动程序安装须知
Windows XP *** 作系统可继续提供即插即用支持特性,从而,允许用户将那些来自无线鼠标与键盘制造厂商的USB无线收发器插接至计算机设备,并以此创造出极其优异的用户体验。在只需实现基本功能特性的前提下,您甚至不必安装由制造商提供的专用软件。
而高级用户则可选择安装由制造商提供的专用软件,以便对用户编程特性加以充分利用。Windows XP *** 作系统可针对兼容型人机界面设备(HID)配置情况执行自动侦测,并通过状态气球将新增即插即用设备可供 *** 作使用的消息告知当前用户。
(请注意,如果您正在使用随某些无线设备一并提供的PS2连接器,那么,上述功能便无法实现,其原因主要在于,PS2连接方式有可能尚不具备HID兼容特性。)
设备管理器会在提示用户插接适用于某一无线设备的USB收发器之前,将已由系统检测到的硬件设备列示出来。请注意,只有标准键盘和PS2鼠标被列示出来,而并不存在任何HID设备。
万能键盘驱动使用方法
1、进入设备管理器中查看键盘驱动是否正常,鼠标右键桌面“计算机”图标,在菜单中选择“管理”选项,然后在计算机管理左侧列表中选择“设备管理器”选项;

2、在设备管理器右侧列表中找到“键盘”选项,展开发现“PS/2标准键盘”旁出现**感叹号,表示键盘驱动程序出现问题;

3、使用快捷键“Win+R”打开运行窗口并输入“regedit”命令按确定调出注册表编辑器,然后在注册表左侧依次展开:HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlClass{4D36E96B-E325-11CE-BFC1-08002BE10318。

4、在右侧窗口中找到“UpperFilters”选项并将其删除然后在“设备管理器”里卸载“键盘”设备,然后重新“扫描检测硬件改动”,接着会找到键盘硬件但是旁边还是有感叹号不用着急,查看下设备状态变成了“代码10:该设备无法启动”,如若不是重启电脑再次查看。
接着还是在注册表刚刚的位置新建我们刚刚删除的项新建添加多字符串值“UpperFilters”项,修改内容为“kbdclass”选项,重启设备就会发现可以使用键盘了,

5、如果用户在修改注册表 *** 作中无法使用键盘输入时,可以临时打开“屏幕键盘”功能,在“开始”菜单中打开控制面板,然后选择“轻松访问”选项,在打开“启动屏幕键盘”即可临时使用键盘。

万能键盘驱动程序相关问题
笔记本外接键盘即插即用的驱动被禁用了怎么办
右键--计算机--管理--设备管理器 看到**感叹号的 右键属性 更新下驱动 或换个接扣重插一下即可解决问题。
键盘突然不能用了,设备管理器有个**的感吧号该如何处理?
SP26478exe这个万能键盘驱动实际上是HP发布的一个驱动,后来试了几个键盘反正我们办公室的都试过了,都能驱动,所以我称他为万能键盘驱动。
键盘驱动被我卸载了,怎么样从装上去
如果是USB的,可以支持热插拔,如果是PS2接口,就是圆头,那么关机后在插拔启动计算机,就可以了。 键盘鼠标一般是不用驱动的,会自动检测,如果你是带功能的键盘,有很多快捷键的那种,一键上网 音量 什么的,找到驱动盘,重新安装一下就可以了。
万能键盘驱动程序注意事项
1、下载最新版本的万能键盘驱动
2、删除当前多媒体键盘驱动程序
3、安装最新版本的万能键盘驱动
万能键盘驱动程序使用须知
该惠普键盘驱动适用于任何键盘,只要系统由于键盘驱动丢失而不能使用键盘的、设备管理器中键盘项目有感叹号的,都能使用,保证解决!
万能键盘驱动程序更新日志:
1修复部分bug
2优化了部分功能
第一次认真回答,不采纳没有小鸡鸡。。。。。。。。。。
#include <reg52H>
#include<intrinsh>
#define uint unsigned int
#define uchar unsigned char
//心形显示
//unsigned char code tabP0[]={0x30,0x48,0x44,0x22,0x44,0x48,0x30,0x00};
//unsigned char code tabP2[]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE};
//圆形显示
unsigned char code tabP0[]={0x00,0x3c,0x42,0x42,0x42,0x42,0x3c,0x00};
unsigned char code tabP2[]={0x7F,0xBF,0x0DF,0x0EF,0x0F7,0x0FB,0x0FD,0x0FE};
//菱形显示
//unsigned char code tabP0[]={0x00,0x08,0x14,0x22,0x41,0x22,0x14,0x08};
//unsigned char code tabP2[]={0x7F,0xBF,0x0DF,0x0EF,0x0F7,0x0FB,0x0FD,0x0FE};
//叉形显示
//unsigned char code tabP0[]={0x00,0x41,0x22,0x14,0x08,0x14,0x22,0x41};
//unsigned char code tabP2[]={0x7F,0xBF,0x0DF,0x0EF,0x0F7,0x0FB,0x0FD,0x0FE};
//中字显示
//unsigned char code tabP0[]={0x00,0x1e,0x12,0x12,0x7f,0x12,0x12,0x1e};
//unsigned char code tabP2[]={0x7F,0xBF,0x0DF,0x0EF,0x0F7,0x0FB,0x0FD,0x0FE};
/
名称 : Delay_1ms()
功能 : 延时子程序,延时时间为 1ms x
输入 : x (延时一毫秒的个数)
输出 : 无
/
void Delay_1ms(uchar i)//1ms延时
{
uchar x,j;
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
/
名称 : Main()
功能 : 主函数
输入 : 无
输出 : 无
/
void main()
{
int i;
while(1)
{
for(i=0;i<8;i++)
{
P0=0;
P2=tabP2[i];
P0=tabP0[i];
Delay_1ms(2);
}
}
}
Virtual-Key Codes
The following table shows the symbolic constant names, hexadecimal values, and mouse or keyboard equivalents for the virtual-key codes used by the system The codes are listed in numeric order
Symbolic constant name Value
(hexadecimal) Mouse or keyboard equivalent
VK_LBUTTON 01 Left mouse button
VK_RBUTTON 02 Right mouse button
VK_CANCEL 03 Control-break processing
VK_MBUTTON 04 Middle mouse button (three-button mouse)
VK_XBUTTON1 05 Windows 2000: X1 mouse button
VK_XBUTTON2 06 Windows 2000: X2 mouse button
— 07 Undefined
VK_BACK 08 BACKSPACE key
VK_TAB 09 TAB key
— 0A–0B Reserved
VK_CLEAR 0C CLEAR key
VK_RETURN 0D ENTER key
— 0E–0F Undefined
VK_SHIFT 10 SHIFT key
VK_CONTROL 11 CTRL key
VK_MENU 12 ALT key
VK_PAUSE 13 PAUSE key
VK_CAPITAL 14 CAPS LOCK key
VK_KANA 15 IME Kana mode
VK_HANGUEL 15 IME Hanguel mode (maintained for compatibility; use VK_HANGUL)
VK_HANGUL 15 IME Hangul mode
— 16 Undefined
VK_JUNJA 17 IME Junja mode
VK_FINAL 18 IME final mode
VK_HANJA 19 IME Hanja mode
VK_KANJI 19 IME Kanji mode
— 1A Undefined
VK_ESCAPE 1B ESC key
VK_CONVERT 1C IME convert
VK_NONCONVERT 1D IME nonconvert
VK_ACCEPT 1E IME accept
VK_MODECHANGE 1F IME mode change request
VK_SPACE 20 SPACEBAR
VK_PRIOR 21 PAGE UP key
VK_NEXT 22 PAGE DOWN key
VK_END 23 END key
VK_HOME 24 HOME key
VK_LEFT 25 LEFT ARROW key
VK_UP 26 UP ARROW key
VK_RIGHT 27 RIGHT ARROW key
VK_DOWN 28 DOWN ARROW key
VK_SELECT 29 SELECT key
VK_PRINT 2A PRINT key
VK_EXECUTE 2B EXECUTE key
VK_SNAPSHOT 2C PRINT SCREEN key
VK_INSERT 2D INS key
VK_DELETE 2E DEL key
VK_HELP 2F HELP key
30 0 key
31 1 key
32 2 key
33 3 key
34 4 key
35 5 key
36 6 key
37 7 key
38 8 key
39 9 key
— 3A–40 Undefined
41 A key
42 B key
43 C key
44 D key
45 E key
46 F key
47 G key
48 H key
49 I key
4A J key
4B K key
4C L key
4D M key
4E N key
4F O key
50 P key
51 Q key
52 R key
53 S key
54 T key
55 U key
56 V key
57 W key
58 X key
59 Y key
5A Z key
VK_LWIN 5B Left Windows key (Microsoft® Natural® keyboard)
VK_RWIN 5C Right Windows key (Natural keyboard)
VK_APPS 5D Applications key (Natural keyboard)
— 5E Reserved
VK_SLEEP 5F Computer Sleep key
VK_NUMPAD0 60 Numeric keypad 0 key
VK_NUMPAD1 61 Numeric keypad 1 key
VK_NUMPAD2 62 Numeric keypad 2 key
VK_NUMPAD3 63 Numeric keypad 3 key
VK_NUMPAD4 64 Numeric keypad 4 key
VK_NUMPAD5 65 Numeric keypad 5 key
VK_NUMPAD6 66 Numeric keypad 6 key
VK_NUMPAD7 67 Numeric keypad 7 key
VK_NUMPAD8 68 Numeric keypad 8 key
VK_NUMPAD9 69 Numeric keypad 9 key
VK_MULTIPLY 6A Multiply key
VK_ADD 6B Add key
VK_SEPARATOR 6C Separator key
VK_SUBTRACT 6D Subtract key
VK_DECIMAL 6E Decimal key
VK_DIVIDE 6F Divide key
VK_F1 70 F1 key
VK_F2 71 F2 key
VK_F3 72 F3 key
VK_F4 73 F4 key
VK_F5 74 F5 key
VK_F6 75 F6 key
VK_F7 76 F7 key
VK_F8 77 F8 key
VK_F9 78 F9 key
VK_F10 79 F10 key
VK_F11 7A F11 key
VK_F12 7B F12 key
VK_F13 7C F13 key
VK_F14 7D F14 key
VK_F15 7E F15 key
VK_F16 7F F16 key
VK_F17 80H F17 key
VK_F18 81H F18 key
VK_F19 82H F19 key
VK_F20 83H F20 key
VK_F21 84H F21 key
VK_F22 85H F22 key
VK_F23 86H F23 key
VK_F24 87H F24 key
— 88–8F Unassigned
VK_NUMLOCK 90 NUM LOCK key
VK_SCROLL 91 SCROLL LOCK key
92–96 OEM specific
— 97–9F Unassigned
VK_LSHIFT A0 Left SHIFT key
VK_RSHIFT A1 Right SHIFT key
VK_LCONTROL A2 Left CONTROL key
VK_RCONTROL A3 Right CONTROL key
VK_LMENU A4 Left MENU key
VK_RMENU A5 Right MENU key
VK_BROWSER_BACK A6 Windows 2000: Browser Back key
VK_BROWSER_FORWARD A7 Windows 2000: Browser Forward key
VK_BROWSER_REFRESH A8 Windows 2000: Browser Refresh key
VK_BROWSER_STOP A9 Windows 2000: Browser Stop key
VK_BROWSER_SEARCH AA Windows 2000: Browser Search key
VK_BROWSER_FAVORITES AB Windows 2000: Browser Favorites key
VK_BROWSER_HOME AC Windows 2000: Browser Start and Home key
VK_VOLUME_MUTE AD Windows 2000: Volume Mute key
VK_VOLUME_DOWN AE Windows 2000: Volume Down key
VK_VOLUME_UP AF Windows 2000: Volume Up key
VK_MEDIA_NEXT_TRACK B0 Windows 2000: Next Track key
VK_MEDIA_PREV_TRACK B1 Windows 2000: Previous Track key
VK_MEDIA_STOP B2 Windows 2000: Stop Media key
VK_MEDIA_PLAY_PAUSE B3 Windows 2000: Play/Pause Media key
VK_LAUNCH_MAIL B4 Windows 2000: Start Mail key
VK_LAUNCH_MEDIA_SELECT B5 Windows 2000: Select Media key
VK_LAUNCH_APP1 B6 Windows 2000: Start Application 1 key
VK_LAUNCH_APP2 B7 Windows 2000: Start Application 2 key
— B8-B9 Reserved
VK_OEM_1 BA Windows 2000: For the US standard keyboard, the ';:' key
VK_OEM_PLUS BB Windows 2000: For any country/region, the '+' key
VK_OEM_COMMA BC Windows 2000: For any country/region, the ',' key
VK_OEM_MINUS BD Windows 2000: For any country/region, the '-' key
VK_OEM_PERIOD BE Windows 2000: For any country/region, the '' key
VK_OEM_2 BF Windows 2000: For the US standard keyboard, the '/' key
VK_OEM_3 C0 Windows 2000: For the US standard keyboard, the '`~' key
— C1–D7 Reserved
— D8–DA Unassigned
VK_OEM_4 DB Windows 2000: For the US standard keyboard, the '[{' key
VK_OEM_5 DC Windows 2000: For the US standard keyboard, the '\|' key
VK_OEM_6 DD Windows 2000: For the US standard keyboard, the ']}' key
VK_OEM_7 DE Windows 2000: For the US standard keyboard, the 'single-quote/double-quote' key
VK_OEM_8 DF
— E0 Reserved
E1 OEM specific
VK_OEM_102 E2 Windows 2000: Either the angle bracket key or the backslash key on the RT 102-key keyboard
E3–E4 OEM specific
VK_PROCESSKEY E5 Windows 95/98, Windows NT 40, Windows 2000: IME PROCESS key
E6 OEM specific
VK_PACKET E7 Windows 2000: Used to pass Unicode characters as if they were keystrokes The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
— E8 Unassigned
E9–F5 OEM specific
VK_ATTN F6 Attn key
VK_CRSEL F7 CrSel key
VK_EXSEL F8 ExSel key
VK_EREOF F9 Erase EOF key
VK_PLAY FA Play key
VK_ZOOM FB Zoom key
VK_NONAME FC Reserved for future use
VK_PA1 FD PA1 key
VK_OEM_CLEAR FE Clear key
if( INT_0 != 0 ) //再次判断是否有键按下
{
EA=0;
scan_key();
delay(50);
INT_0 =judge_hitkey();
while( INT_0 !=1); //等待按键释放
EA=1;
}
在EA=0;这句前,有无加上了,重新把 INT_0 =judge_hitkey(); 再赋回来了?,,我在郭天祥的板子上调试不行; EXITEC(93): warning C206: 'manage_key1': missing function-prototype;
这是我花两个多小时写得51单片机,矩阵键盘的显示,希望能对你有帮助;
#include<reg52h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
sbit dula=P2^6;
sbit wela=P2^7;
void init();
void display(uchar);
uchar keyscan();
uchar temp,num; //键盘扫描
void delay(uint xms) //延时子函数
{
int i,j;
for(i=xms;i>0;i--) //延时xms毫秒
for(j=110;j>0;j--);
}
void main()
{
init();
while(1)
{
keyscan();//不断扫描键盘;
display(num);
}
}
void init()
{
num=0xff; //控制让程序开始时不出现乱码;
wela=1;
P0=0xc0; //打开数码管显示,静态显示;
wela=0;
}
uchar keyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;//按位与,只能用&;
if(temp!=0xf0) //在用while语句时,一定要加上去抖动,否则程序会停不下来的哦;
{ //还是统一用if语句吧,只有在去抖动才一定要用if语句;
delay(5); //至于中括号加在那都无所谓啦;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num=1;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
while (temp!=0xf0) //去抖动只能用while ,只有松开手才会执行下面的,才会有数码显;
{ ////一松开手,就相当于把P3口的电平改变了;所以去抖不能在switch前
temp=P3;
temp=temp&0xf0; //不能不要,只有松开手,才会退出这个循环;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;//按位与,只能用&;
if(temp!=0xf0)
{
delay(5);
if(temp!=0xf0)
{
temp=P3;
// temp=temp&0xf0; //该句子一定不能要,因为下面判断的,只是P3口的电平状态而已;
}
switch(temp)
{ case 0xed: num=5; break;
case 0xdd: num=6; break;
case 0xbd: num=7; break;
case 0x7d: num=8; break;
}
}
while (temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;//按位与,只能用&;
if(temp!=0xf0)
{
delay(5);
if(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
if(temp!=0xf0)
{
temp=P3;
// temp=temp&0xf0;
}
switch(temp)
{ case 0xeb: num=9; break;
case 0xdb: num=10; break;
case 0xbb: num=11; break;
case 0x7b: num=12; break;
}
while (temp!=0xf0) //去抖动只能用while ,只有松开手才会执行下面的,才会有数码显;
{ ////一松开手,就相当于把P3口的电平改变了;所以去抖不能在switch前
temp=P3;
temp=temp&0xf0; //不能不要,只有松开手,才会退出这个循环;
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;//按位与,只能用&;
if(temp!=0xf0)
{
delay(5);
if(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
if(temp!=0xf0) //该句子不能用while语句,因为如果用while语句,如果松手了,P3的电平就改变了,temp的值也会改变的。
//因此建议,非必要,还是用if语句;
{
temp=P3;
// temp=temp&0xf0;
}
switch(temp)
{ case 0xe7: num=13; break;
case 0xd7: num=14; break;
case 0xb7: num=15; break;
case 0x77: num=16; break;
}
while (temp!=0xf0) //去抖动只能用while ,只有松开手才会执行下面的,才会有数码显;
{ ////一松开手,就相当于把P3口的电平改变了;所以去抖不能在switch前
temp=P3;
temp=temp&0xf0; //不能不要,只有松开手,才会退出这个循环;
}
return num;
}
void display(uchar num)
{
P0=table[num-1];
dula=1;
dula=0;
}
下面的是郭天祥老师写的
#include<reg52h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};
uchar num,temp,num1;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar keyscan();
void display(uchar aa);
void main()
{
num=17;
dula=1;
P0=0;
dula=0;
wela=1;
P0=0xc0;
wela=0;
while(1)
{
display(keyscan());
}
}
void display(uchar aa)
{
dula=1;
P0=table[aa-1];
dula=0;
}
uchar keyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num=1;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:num=5;
break;
case 0xdd:num=6;
break;
case 0xbd:num=7;
break;
case 0x7d:num=8;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:num=9;
break;
case 0xdb:num=10;
break;
case 0xbb:num=11;
break;
case 0x7b:num=12;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xe7:num=13;
break;
case 0xd7:num=14;
break;
case 0xb7:num=15;
break;
case 0x77:num=16;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
return num;
}
以上就是关于使用p1.0-p1.7口实现4*4键盘输入,并用p0口和p2口控制数码管显示输入键值 单片机汇编语全部的内容,包括:使用p1.0-p1.7口实现4*4键盘输入,并用p0口和p2口控制数码管显示输入键值 单片机汇编语、MSP430 4*4小键盘、外接键盘驱动怎么下载等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)