51 MCU C language programming: matrix keyboard input, display on digital tube

Publisher:JoyfulMelodyLatest update time:2018-05-09 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Input is made through a matrix keyboard and displayed on a single-digit digital tube.



#include

#define uint unsigned int

#define uchar unsigned char


sbit duanx = P2^6;

sbit weix = P2^7;

uchar  key, k_tmp, view;


uchar show[] = {

    0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,

    0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};


void keyscan(void)

{

    key = 16;  

    P3 = 0xf0;  k_tmp = P3 & 0xf0;

    if     (k_tmp == 0x70) key = 0; 

    else if(k_tmp == 0xb0) key = 1; 

    else if(k_tmp == 0xd0) key = 2;

    else if(k_tmp == 0xe0) key = 3;

    P3 = 0x0f;  k_tmp = P3 & 0x0f;

    if     (k_tmp == 0x07) key = key + 12; 

    else if(k_tmp == 0x0b) key = key + 8; 

    else if(k_tmp == 0x0d) key = key + 4; 

    else if(k_tmp == 0x0e) key = key + 0;


    view = show[key];


}


void display(uchar view)

{

    P0 = view; duanx = 1; duanx = 0;

    P0 = 0xfe; weix = 1;  weix = 0;

}


main()

{

    while(1) {

      keyscan();

      display(view);

    }

}


Reference address:51 MCU C language programming: matrix keyboard input, display on digital tube

Previous article:51 MCU C language: irregular matrix keyboard
Next article:51 MCU: Button control light on and off and flashing

Recommended ReadingLatest update time:2024-11-16 12:42

24-Design of 4x4 calculator based on 51 single chip microcomputer
Specific implementation functions The system consists of STC89C52 single chip microcomputer + 4 times 4 key module + LCD1602 liquid crystal display + power supply. Specific functions: Using a 4×4 matrix keyboard for input, several digital operations such as addition, subtraction, multiplication and division can be
[Microcontroller]
24-Design of 4x4 calculator based on 51 single chip microcomputer
Transplantation of Embedded Real-time Operating System ECOS on S3C2510
Introduction        ECOS (Embedded Configurable Operating System) is a portable embedded real-time operating system for 16-bit, 32-bit and 64-bit processors. As its source code is open, more and more designers are beginning to pay attention to the ECOS operating system. The biggest feature of ECOS is modularity and co
[Microcontroller]
Transplantation of Embedded Real-time Operating System ECOS on S3C2510
C51 digital tube numeric tube
#include reg52.h #define uchar unsigned char #define uint unsigned int uint i,j; sbit dula=P2^6; sbit temperature=P2^7; uchar table ={0x3f,0x06,0x5b, 0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77, 0x7c,0x39,0x5e,0x79,0x71}; void delay(uint); void main() { while(1) { P0=0xea; temperature=1; temperature=0; P0
[Microcontroller]
C51 digital tube numeric tube
S3C2440 Interrupts
The CPU and peripherals constitute a computer system. The CPU and peripherals are connected through a bus for data communication and control. The CPU manages and monitors all hardware in the computer system. Usually, the hardware is managed and monitored in two ways: Query method: The CPU keeps querying the cur
[Microcontroller]
S3C2440 Interrupts
33-Light intensity detection based on 51 single chip microcomputer (photoresistor)
Specific implementation functions The system is composed of STC89C52 single chip microcomputer + four-digit digital tube display + photoresistor + ADC0804 etc. Specific functions: ①The photoresistor collects the ambient light value in real time; ② Use ADC0804 to convert analog value into digital value; ③The fo
[Microcontroller]
33-Light intensity detection based on 51 single chip microcomputer (photoresistor)
Basketball scoreboard design based on 51 microcontroller
1. Design tasks Design a basketball scoreboard based on a microcontroller to realize the scoring function and 24-second timing function of the two teams. 2. Performance index requirements (1) Independently design the circuit required for the system according to the topic requirements, and complete the production and d
[Microcontroller]
How many categories can the 8051 microcontroller instruction system be divided into according to its functions? How many addressing modes does it have?
The instruction system of the MCS-51 single-chip microcomputer can be divided into five categories according to its function:  (1) Data transfer instructions   (2) Arithmetic operation instructions    (3) Logical operation and shift instructions    (4) Control transfer instructions  (5) Bit operation instructions  The
[Microcontroller]
s3c6410_clock initialization
refer to: 1) "USER'S MANUAL-S3C6410X" Chapter 3 SYSTEM CONTROLLER 2) u-boot/board/samsumg/smdk6410/lowlevel_init.S 1. Relationship between PLL and CLK: For a detailed relationship diagram, see Figure 3-2 The block diagram of clock generator on page 122 of the user manual. Three types of PLL:
[Microcontroller]
s3c6410_clock initialization
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号