4*4 matrix keyboard input digital tube based on stc89c52

Publisher:乘风翻浪Latest update time:2014-12-04 Source: 21icKeywords:stc89c52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

////////////////////////////////////////////////////////////////////////////////////////
 Function implemented: Complete the test of independent keys. When one of the twenty keys, key5-key20, is pressed, a
             specific value will be displayed on the first digital tube of the development board. The displayed value is
    defined as follows: when key5 is pressed, 0 is displayed; when key6 is pressed, 2 is displayed; and so on,
    until the corresponding value is displayed when the corresponding value is pressed.
 Experiment board model: BS-XYD-C52
 Experiment name: Static digital tube
 Author: TabLee
 Date of writing: 2014-3-21     
////////////////////////////////////////////////////////////////////////////////

#include
#include
                   
#define uchar unsigned char //Define unsigned char as uchar
#define uint unsigned int

sbit Duan = P2^6; //Define the segment selection enable terminal of the digital tube
sbit Wei = P2^7; //Define the bit selection enable terminal of the digital tube

#define Digital_tube_Wei_Enable Wei=1; //Turn on the bit select enable terminal for controlling the digital tube
#define Digital_tube_Wei_Disable Wei=0; //Turn off the bit select enable terminal for controlling the digital tube

#define Digital_tube_Duan_Enable Duan=1; //Turn on the segment selection enable terminal for controlling the digital tube
#define Digital_tube_Duan_Disable Duan=0; //Turn off the segment selection enable terminal for controlling the digital tube

#define Digital_tube_Duan P0 //Define the digital tube data port

#define KEY_DOWN 0
#define Keyport P3

uchar code Dis_table[]= //Convert BCD code into array of digital tube scan code
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,
                                                            0x79,0x71};
uchar code Dis_Position[]= //Define array of digital tube position selection
{0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
 ///
...


          ​
    ​
​No
precautions: This experiment realizes millisecond delay under the premise that the crystal oscillator used is 12M. This function is completed in
          the form ,      so  if the frequency  of  the crystal oscillator is changed, please make corresponding  changes
 /      ...  ////////////////////////////////////////////////////////////////////////////////









Function name: One_DigitalTube_display
Function function: Complete the specified display of the digital tube on the experimental board, that is, display a specific number on a specific digital tube, than
          displaying 0 on the first digital tube
Parameter introduction: uData: BCD code array of the number to be displayed
          uNumber: Select which digital tube to display, that is, let a specific digital tube display
Return value: None
Notes: The digital tube on the experimental board is a common cathode digital tube. If you use a common anode digital tube, be careful
          not to get it reversed
 / ...

void One_DigitalTube_display(uchar uData,uchar uNumber)
{
  Digital_tube_Duan=Dis_Position[uNumber]; //Light up a specific digital tube
  Digital_tube_Wei_Enable; //Enable the bit selection of the digital tube
  Digital_tube_Wei_Disable; //Disable the bit selection of the digital tube
  DelayMs(5); //Adjust the timing to achieve stable display
 
  Digital_tube_Duan_Enable; //Enable the segment selection of the digital tube
  Digital_tube_Duan=Dis_table[uData]; //Enter the value to be displayed
  Digital_tube_Duan_Disable; //Disable the segment selection of the digital tube
}
 ///
...
​    ​
          ​​​ ​




void Scan_Keyboard()
{
 uchar cTemp_Value;
 //Scan the first column of the matrix keyboardKeyport
 =0xef; //Assign a specific value to the keyboard port to achieve the following detectioncTemp_Value
 =Keyport; //Assign the keyboard port value to a temporary variableif
 (cTemp_Value!=0xef)
 {
  DelayMs(10); //Eliminate jitter, that is, eliminate interferencecTemp_Value
        =Keyport; //Reassign to temporary valueif
        (cTemp_Value!=0xef) //Check againwhile
        ((Keyport&0x0F)!=0x0F) //Judge again whether a key is pressed
  {
      switch(cTemp_Value)   
      {
       case 0xee:
         One_DigitalTube_display(0,0);break; //The fifth key is pressed, display 0
       case 0xed:
         One_DigitalTube_display(4,0);break; //The ninth key is pressed, display 4
       case 0xeb:
         One_DigitalTube_display(8,0);break; //The thirteenth button is pressed, and 8 is displayed
       case 0xe7:
         One_DigitalTube_display(12,0);break; //The seventeenth button is pressed, and C is displayed
      }
  }
 }
 //Scan the second column of the matrix keyboard
 Keyport=0xdf; //Assign a specific value to the keyboard port to achieve the following detection
 cTemp_Value=Keyport; //Assign the keyboard port value to a temporary variable
 if(cTemp_Value!=0xdf)
 {
  DelayMs(10); //Eliminate jitter, that is, eliminate interference
        cTemp_Value=Keyport; //Reassign to the temporary value
        if(cTemp_Value!=0xdf) //Check again
        while((Keyport&0x0F)!=0x0F) //Judge again whether a button is pressed
  {
      switch(cTemp_Value)   
      {
       case 0xde:
         One_DigitalTube_display(1,0);break; //The sixth button is pressed, and 1 is displayed
       case 0xdd:
         One_DigitalTube_display(5,0);break; //The tenth key is pressed, and 5 is displayed
       case 0xdb:
         One_DigitalTube_display(9,0);break; //The fourteenth key is pressed, and 9 is displayed
       case 0xd7:
         One_DigitalTube_display(13,0);break; //The eighteenth key is pressed, and D is displayed
      }
  }
 }
 //Scan the third column of the matrix
 keyboardKeyport=0xbf; //Assign a specific value to the keyboard port to achieve the following detection
 cTemp_Value=Keyport; //Assign the keyboard port value to a temporary variableif
 (cTemp_Value!=0xbf)
 {
  DelayMs(10); //Eliminate jitter, that is, eliminate interferencecTemp_Value
        =Keyport; //Reassign to the temporary valueif
        (cTemp_Value!=0xbf) //Check againwhile
        ((Keyport&0x0F)!=0x0F) //Judge whether a key is pressed again
  {
      switch(cTemp_Value)   
      {
       case 0xbe:
         One_DigitalTube_display(2,0);break; //The seventh button is pressed, and the display shows 2
       case 0xbd:
         One_DigitalTube_display(6,0);break; //The eleventh button is pressed, and the display shows 6
       case 0xbb:
         One_DigitalTube_display(10,0);break; //The fifteenth button is pressed, and the display shows A
       case 0xb7:
         One_DigitalTube_display(14,0);break; //The nineteenth button is pressed, and the display shows E
      }
  }
 }
 //Scan the fourth column of the matrix keyboard
 Keyport=0x7f; //Assign specific values ​​to the keyboard port to implement subsequent detection
 cTemp_Value=Keyport; //Assign the keyboard port value to the temporary variable
 if(cTemp_Value!=0x7f)
 {
  DelayMs(10); //Eliminate jitter, that is, eliminate interference
        cTemp_Value=Keyport; //Reassign to the temporary value
        if(cTemp_Value!=0x7f) //Check again
        while((Keyport&0x0F)!=0x0F) //Judge again whether a key is pressed
  {
      switch(cTemp_Value)   
      {
       case 0x7e:
         One_DigitalTube_display(3,0);break; //The eighth key is pressed, and 3 is displayed
       case 0x7d:
         One_DigitalTube_display(7,0);break; //The twelfth key is pressed, and 7 is displayed
       case 0x7b:
         One_DigitalTube_display(11,0);break; //The sixteenth key is pressed, and B is displayed
       case 0x77:
         One_DigitalTube_display(15,0);break; //The 20th button is pressed, and F is displayed
      }
  }
 }
}
/// ...

Function name: mainFunction
function: Continuously scan the keyboard in a loop. When a key is pressed, the corresponding value will be displayed on the digital tube.
Parameter introduction: None
Return value: None
Notes: None
/ ...

void main()
{
 DelayMs(50);
 while(1)
 {
  Scan_Keyboard(); //Call keyboard scanning function
 }
}

Keywords:stc89c52 Reference address:4*4 matrix keyboard input digital tube based on stc89c52

Previous article:Modular program of LCD12232 liquid crystal
Next article:The difference between open-drain output and push-pull output of microcontroller I/O port

Recommended ReadingLatest update time:2024-11-16 16:35

Design of smart home system based on S5PV210
A design method for a smart home system based on the S5PV210 chip is proposed. The software system and human-computer interaction interface are developed using QT on an embedded system platform based on the S5PV210 processor and the linux2.6.30 kernel, and various sensors are controlled to collect information as well
[Microcontroller]
Design of smart home system based on S5PV210
51 single chip microcomputer STC89C52 drives a digital tube to display 0~9, A~F
Program source code /*-----------------------Include header file area-------------------------*/ #include reg52.h   //MCU header file  /*-----------------------Data type definition area-----------------------*/ typedef unsigned char u8; //define type unsigned char alias u8 typedef unsigned int u16; //define type u
[Microcontroller]
51 single chip microcomputer STC89C52 drives a digital tube to display 0~9, A~F
[51 microcontroller STC89C52] Timer (interrupt) controls LED
1. Timer/Counter T0 1. Timer/counter related registers 2. Timer/counter control register TCON The TCON format is as follows: 3. Timer/counter operating mode register TMOD Mode selection:   2. Configure related registers 1. Use STC-ISP tool 2. Configuration register Set timer mode (16-bit timer) It is recom
[Microcontroller]
[51 microcontroller STC89C52] Timer (interrupt) controls LED
STC89C52 MCU - Serial port sending program 1
/*-----------------------------------------------   Name: Serial communication   Written by: LZM   Date: 2015.05   Modification: None   Content: Connect the serial port and set the baud rate to 9600 without parity check.         Crystal oscillator 11.0592MHz Connect to the serial port and you can receive the characte
[Microcontroller]
STC89C52 MCU - Serial port sending program 1
STC89C52 MCU PS2 keyboard decoding
///////////////////////////////////////////////////// /////////////////////////   Function: Realize the data collection, decoding and display of the P2 keyboard, that is,           collect the data value of the P2 keyboard through interruption, then decode it through software, and finally display the corresponding le
[Microcontroller]
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

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号