转载(留着慢慢看):void main(void) - the Wrong Thing
毕业设计的开始:传感器无线网络——入手的几个模块

关于单片机8个I/0口 实现36个按键功能

G-one posted @ 2010年3月28日 23:21 in program , 4081 阅读

 

算是闲着无聊弄了弄,不弄不知道一弄发现原来那么简单

先上图

这是整体仿真图,用51单片机接,数码管显示每个按键的返回值;

按键以8个起始 递减的链接,7、6、5...  因此共36个按键

下面是检测按键的简单程序

#include<reg51.h>
#include<intrins.h>

#define uchar unsigned char
#define uint unsigned int
#define LED P0
#define Keycheck P1

sbit LED1=P2^0;
sbit LED2=P2^1;
sbit LED3=P2^2;
sbit LED4=P2^3;


void delay(uchar);

uchar code NUM[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//公阳
	  			//0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71	公阴
uint DATA=0;


void LEDplay(void);
void Keych(void);
void delay(uchar);

int main(void)
{
   DATA=0X00;

	while(1)
	{
	Keych();
	LEDplay();
	}

}


void Keych(void)
{
uchar i=0,temp,Keycode;
uchar Keynum=0xfe;
Keycheck=0xff;


if(Keycheck!=0xff)	//I/O口全为高电平扫描列8个按键
	{ delay(5);
	  if(Keycheck!=0xff)
	    Keycode=Keycheck;
	}

else				   
	{								
		while((Keynum&0x80)!=0)		//每次一个低电平口,循环移动扫描按键
		{								   
		Keycheck=Keynum;
			if(Keycheck!=Keynum)
			{
			  delay(5);
			  if(Keycheck!=Keynum)
			  Keycode=Keycheck;	
			  break;
			}
			else
			Keynum=_crol_(Keynum,1);
			

		}

	} 
//else Keycode=0x00;   //无按键按下的返回值,这里为保持所找按键值,估不设定返回


 if(temp!=Keycode)
	{
	temp=Keycode;
	DATA=Keycode;
	}


}


void LEDplay(void)
{
P2=0x00;



	LED=NUM[DATA&0X0F];LED4=1;delay(3);LED4=0; 
	LED=NUM[DATA>>4];  LED3=1;delay(3);LED3=0; 
    LED=0x89;LED2=1;delay(3);LED2=0; 	  //0x89为共阳数码管H
    LED=NUM[0];LED1=1;delay(3);LED1=0; 

}



void delay(uchar x)
{
uchar k;
while(x--)
for(k=0;k<128;k++);

}

 

 

哎呀~ 为啥行距那么宽呢~?  下回再弄

按照图上的那种接法按键返回值分别为:

                                                                                                                                 0XFE

                                                                                                                0XFC        0XFD 

                                                                                               0XF9        0XFA        0XFB

                                                                              0XF3        0XF5        0XF6        0XF7

                                                            0XE7       0XEB        0XED        0XEE        0XEF

                                          0XCF        0XD7       0XDB       0XDD       0XDE        0XDF

                         0X9F        0XAF        0XB7        0XBB        0XBD       0XBE        0XBF

        0x3F        0X5F        0X6F        0X77        0X7B        0X7D        0X7E          0X7F

若返回值有出入纯粹 链接模式差异或程序上的的差异。原理一样即可;

Avatar_small
TLHL28 说:
2010年4月10日 10:24

噢噢.不错不错.
这个blog好把.:)

Avatar_small
EDWARD 说:
2020年10月18日 19:30

Wow, What an Outstanding post. I found this too much informatics. It is what I was seeking for Funny Cat videos

Avatar_small
EDWARD 说:
2020年10月19日 18:30

Excellent information providing by your Article thank you for taking the time to share with us such a nice article. buy weed online

Avatar_small
FOX 说:
2020年10月28日 04:40

Speechelo is a brand new text to speech software that is completely cloud base. You get 30 tts voices to help you with your voice over projects. Using Text to Speech has never been easier. speechelo discount

Avatar_small
ROXEN 说:
2020年10月31日 23:36

Everything has its own value, but this is really precious information shared by Author of internet providers ontario

Avatar_small
Anonymous 说:
2021年9月29日 22:37

I just thought it may be an idea to post incase anyone else was having problems researching but I am a little unsure if I am allowed to put names and addresses on here. مكافحة حشرات

Avatar_small
Things to do 说:
2022年5月23日 18:07

What do you love about traveling? There are many reasons why people love traveling: to meet new people, to see the beautiful world by our own eyes, to experience new things, to capture the beautiful moment, beautiful place with yourself in it, or just simple love the wanderlust feeling... Things to do post will show you the best ideas to travel from all around the world, and makes you want to grab to backpack and go.

Avatar_small
LIC term plan calcul 说:
2022年8月04日 01:18

As the name suggests, this LIC premium calculator online introduced by LIC India helps its customer to calculate the amount of premium to be paid against any particular Life insurance policy on any type of endowment, child, pension, money back, term plan, LIC term plan calculator whole life plan or health plan. Where LIC premium calculator not only calculates about premium but also calculates the amount that you will get after the LIC maturity. The calculation of Life Insurance premium and maturity seems easy for some who are good at mathematics and can do wonders with a calculator in hand, but not all the people are that much efficient. Moreover, the availability of LIC online premium calculator helps one to make the premium calculations in a matter of seconds.

Avatar_small
Gujarat STD-1 Questi 说:
2022年9月10日 22:15

Gujarat State Department of School Education, Gandhinagar and the State level subject experts and other private school teaching staff of the Elementary Level Primary School have designed and suggested the GSEB 1st Class Model Paper 2023 with sample answers Set wide as SET-A, SET-B, SET-C and SET-D to know the new exam scheme or question pattern. Gujarat STD-1 Question Paper Students of the Gujarat state can download the NCERT & SCERT Syllabus GSEB STD-1 Question Paper 2023 Pdf with sample answers along with the class teacher’s suggested all lesson or chapter’s most important questions for Part-A, Part-B, Part-C and Part-D exams of Term-1 & Term-2 to the academic year of 2023.

Avatar_small
Satta King 786 说:
2022年9月11日 18:05

Satta King 786, usually known as gambling is also a widely known game within the republic of Asian country. Gamblers can any time play Satta king 786 online effectively visible technological advancements. people can sit in their cherished articles of clothing and play their beloved game at any time of day.

Avatar_small
NCERT Urdu Sample Pa 说:
2022年9月26日 13:50

Urdu prose and poetry have a lot of work in history. When kids learn it, they get to learn a lot about our history. Our kids must learn about our rich history. To be able to grasp the present, NCERT Urdu Sample Paper Class 11 we must know the past well.Urdu learning can help kids gain a lot of cultural knowledge. The work of Urdu prose and poetry is the best source for the kids to learn about our values and norms.Urdu prose and poetry have a lot of work in history. When kids learn it, they get to learn a lot about our history. Our kids must learn about our rich history. To be able to grasp the present.

Avatar_small
Anonymous 说:
2023年3月13日 18:22

Yo, this is some eminent work you've done here. As a person who is a noteworthy lover of the web, I was impressed to see the exquisite work done in the post here. Well done, my friend. 먹튀폴리스

Avatar_small
Anonymous 说:
2023年3月14日 13:55

I was able to pass this semester only because. This year has been quite eventful for me and I havent had time to do. This service has helped me a lot in this matter. 온라인카지노

Avatar_small
10thmodelpaper.in 说:
2023年4月23日 09:44

10thmodelpaper is a initiative of professional writers who have come together for dedicated news coverage of latest happenings around the country (India). Our team comprises of professional writers & citizen journalists with diverse range of interest in Journalism who are passionate about publishing the Education Updates with transparency in general public interest.Our10thmodelpaper.in reporting team intends to publish the Education & Recruitment Update for all age groups and present the true picture of the recent events with the inside coverage. Our objective would be to cater the requirements of people of all age groups as we intend to publish news classified into General, Political, Crime, Sports, Entertainment, Education and World News.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter