<meta name="keywords" content="必胜时时彩开户,keywords" /> 单片机一键多功效按键识别设计 联系我们

单片机一键多功效按键识别设计

1.实验义务


如图4.9.1所示,开关SP1接在P3.7/RD管脚上,在AT89S51单片机的P1端口接有四个发光二极管,上电的时间,L1接在P1.0管脚上的发光二极管在闪灼,当每次按下开关SP1的时间,L2接在P1.1管脚上的发光二极管在闪灼,再按下开关SP1的时间,L3接在P1.2管脚上的发光二极管在闪灼,再按下开关SP1的时间,L4接在P1.3管脚上的发光二极管在闪灼,再按下开关SP1的时间,又轮到L1在闪灼了,云云轮替下去。

 

 

 

2.电路原理图

图4.9.1

3.系统板上硬件连线

(1.       把“单片机系统”区域中的P3.7/RD端口毗连到“自力式键盘”区域中的SP1端口上;

(2.       把“单片机系统”区域中的P1.0-P1.4端口用8芯排线毗连到“八路发光二极管指导模块”区域中的“L1-L8”端口上;请求,P1.0毗连到L1,P1.1毗连到L2,P1.2毗连到L3,P1.3毗连到L4上。

4.法式模范模范设计措施

(1.       设计头脑由来

在我们生涯中,我们很容易经由历程这个叫张三,谁人叫李四,另外一个是王五;那是由于每小我有不合的名子,我们就很快认出,异常,关于要经由历程一个按键来识别每种不合的功效,我们给每个不合的功效模块用不合的ID号标识,这样,每按下一次按键,ID的值是不类似的,以是单片机就很容易识别不合功效的身份了。

(2.       设计措施

从下面的请求我们可以看出,L1到L4发光二极管在每个时间的闪灼的时间是受开关SP1来控制,我们给L1到L4闪灼的时段界说出不合的ID号,当L1在闪灼时,ID=0;当L2在闪灼时,ID=1;当L3在闪灼时,ID=2;当L4在闪灼时,ID=3;很显着,只需每次按下开关K1时,划分给出不合的ID号我们便能够完成下面的义务了。下面给出有关法式模范模范设计的框图。

5.法式模范模范框图

 

 

 

 

 

 

 

 

 

 

 

 

 

 

图4.9.2

6.汇编源法式模范模范

ID                                 EQU 30H

SP1                               BIT P3.7

L1                                 BIT P1.0

L2                                 BIT P1.1

L3                                 BIT P1.2

L4                                 BIT P1.3

                                     ORG 0

                                     MOV ID,#00H

START:                        JB K1,REL

                                     LCALL DELAY10MS

                                     JB K1,REL

                                     INC ID

                                     MOV A,ID

                                     CJNE A,#04,REL

                                     MOV ID,#00H

REL:                    JNB K1,$

                                     MOV A,ID

                                     CJNE A,#00H,IS0

                                     CPL L1

                                     LCALL DELAY

                                     SJMP START

IS0:                               CJNE A,#01H,IS1

                                     CPL L2

                                     LCALL DELAY

                                     SJMP START

IS1:                               CJNE A,#02H,IS2

                                     CPL L3

                                     LCALL DELAY

                                     SJMP START

IS2:                               CJNE A,#03H,IS3

                                     CPL L4

                                     LCALL DELAY

                                     SJMP START

IS3:                               LJMP START

DELAY10MS:    MOV R6,#20

LOOP1:                        MOV R7,#248

                                     DJNZ R7,$

                                     DJNZ R6,LOOP1

                                     RET

DELAY:                        MOV R5,#20

LOOP2:                        LCALL DELAY10MS

                                     DJNZ R5,LOOP2

                                     RET

                                     END

7.C语言源法式模范模范

#include <AT89X51.H>

unsigned char ID;

void delay10ms(void)

{

  unsigned char i,j;

  for(i=20;i>0;i--)

  for(j=248;j>0;j--);

}

void delay02s(void)

{

  unsigned char i;

  for(i=20;i>0;i--)

    {delay10ms();

    }

}

void main(void)

{ while(1)

    { if(P3_7==0)

        {delay10ms();

          if(P3_7==0)

            {

              ID++;

              if(ID==4)

                {

                  ID=0;

                }

              while(P3_7==0);

            }

        }

      switch(ID)

        { case 0:

            P1_0=~P1_0;

            delay02s();

            break;

          case 1:

            P1_1=~P1_1;

            delay02s();

            break;

          case 2:

            P1_2=~P1_2;

            delay02s();

            break;

          case 3:

            P1_3=~P1_3;

            delay02s();

            break;

        }

    }

以上是一键多功效按键识别设计手艺的代码,转载请生涯版权http://mamjap.com