51 Experiment 11: The 16 keys of the matrix keyboard represent 0-9, af

Publisher:温暖心情Latest update time:2021-09-27 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

51 Experiment 11: The 16 keys of the matrix keyboard represent 0-9, a-f respectively, and the last digit is displayed by the digital tube

#include

#include


typedef unsigned int u16;  

typedef unsigned char u8;


#define GPIO_DIG P0

#define GPIO_KEY P1


//Digital Tube

sbit LSA=P2^2;

sbit LSB=P2^3;

sbit LSC=P2^4;

//Digital watch

u8 code smgduan[16]={0x3f,0x06,0x5b,0x4f,0x66,

         0x6d,0x7d,0x07,0x7f,0x6f,

         0x77,0x7c,0x39,0x5e,0x79,

         0x71};

//Store button number

u8 KeyValue;


//Delay function

void delay(u16 i)

{

  while(i--);

}



//Get the button number

void KeyDown()

{

  char a=0;

      GPIO_KEY=0x0f;

  if(GPIO_KEY!=0x0f)

{

   // Determine the column

   switch(GPIO_KEY)

{

case(0x07):KeyValue=0;break;   

case(0x0b):KeyValue=1;break;

case(0x0d):KeyValue=2;break;          

case(0x0e):KeyValue=3;break;

}

GPIO_KEY=0xf0;

//Confirm the row

switch(GPIO_KEY)

{

case(0x70):KeyValue=KeyValue;break;

case(0xb0):KeyValue=KeyValue+4;break;

case(0xd0):KeyValue=KeyValue+8;break;

case(0xe0):KeyValue=KeyValue+12;break;

}

while((a<50)&&(GPIO_KEY!=0xf0))

{

    delay(1000);

  a++;

}

}

}



void main()

{

   while(1)

{

      //Get the button number

  KeyDown();

  //Determine the position of the digital tube

  LSA=0;LSB=0;LSC=0;

  //keyvalue determines the number

  GPIO_DIG=smgduan[KeyValue];

}

}


Reference address:51 Experiment 11: The 16 keys of the matrix keyboard represent 0-9, af

Previous article:51 Experiment 12: Digital tube display 12345678
Next article:51 Experiment 10: Independent button controls a digital tube to display 0-9, and only adds 1 when pressed once.

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components
Guess you like

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号