Program for microcontroller to detect the status of switch pressing

Publisher:HarmonyJoyLatest update time:2015-06-29 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The following program is to enable us to display the corresponding status through an LED light when we press the switch button. The function of this program is: we can control the output of multiple circuits through the single-chip microcomputer and buttons. Of course, if we change the LED light to a circuit that realizes other functions, we can achieve the purpose of controlling multiple circuits. For example, in the application of the buzzer, when our contestants press it, the digital tube can display the contestant's number. Of course, the buzzer is more complicated than this. There is a production of this on the www.51hei.com single-chip learning website, but this program is the basis of the buzzer. I think it is very practical, so I share it with you.

The specific circuit is as follows:
 


The procedure is as follows:

#include
sbit p20=P2^0;
sbit p21=P2^1;
sbit p22=P2^2;
sbit p23=P2^3;
sbit p24=P2^4;
sbit p25=P2^5;
sbit p26=P2^6;
sbit p27=P2^7;
void main()
{
 while(1)
 {
 if(p24==0)
  p23=0;
 else
 p23=1;
 if(p25==0)
  p22=0;
 else
 p22=1;
 if(p26==0)
  p21=0;
 else
 p21=1;

 if(p27==0)
  p20=0;
 else
 p20=1; 
 }
}

Keywords:MCU Reference address:Program for microcontroller to detect the status of switch pressing

Previous article:Control of single chip matrix keyboard
Next article:Single chip LCD1602 liquid crystal display

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

AVR microcontroller learning asynchronous serial port UART
1. Overview of serial communication technology Popular definition of serial communication: One bit is sent one bit at a time (relative to parallel), of course, through bit synchronization frame synchronization Classification of serial communication Synchronous serial communication Clock line, data line, keep
[Microcontroller]
AVR microcontroller learning asynchronous serial port UART
A brief discussion on modular programming of single-chip microcomputers in C language - with ds1302 clock chip driver
In single-chip C language programming, modular programming is very important. I think modularization just reflects the good portability of C language. In embedded programming, the hardware modules are clearly distinguished, so modular programming of the driver is very convenient and concise. The reason for the error
[Microcontroller]
Application of PHILIPS 51LPC series microcontroller
    1. Introduction     PHILIPS 51LPC series microcontrollers currently include seven models, P87LPC760/1/2/4/7/8/9. 51LPC provides high-speed and low-speed crystal oscillator and RC oscillation modes, which can be selected programmably; it has a wide operating voltage range of 2.7~6.0V, programmable I/O port line out
[Microcontroller]
Application of PHILIPS 51LPC series microcontroller
Application of μPSD 32XX MCU in the Development of Tax Controller
introduction --- Tax control equipment is one of the inevitable means for the national taxation department to implement tax management informatization. As one of the tax control equipment, the tax controller is an electronic device that realizes the tax control function in cooperation with computers and
[Microcontroller]
51 MCU [IV] Buzzer crystal oscillator MCU frequency
I suddenly remembered the sound of the computer self-test when I was a child. Of course, we also have washing machines, air conditioners, etc. The principle of the buzzer is that two iron plates are used to make the positive and negative poles of one end of the plate change continuously, so that the other end can
[Microcontroller]
51 MCU [IV] Buzzer crystal oscillator MCU frequency
Using the MCU serial port to realize parallel communication with PC
Introduction     As a kind of embedded system, single-chip microcomputer has been widely used in fields such as automation control and household appliances. Common single-chip microcomputer systems have one serial port (such as 80C51 series), and some have two serial ports (such as DS80C320 series) or even multiple se
[Microcontroller]
Design of 16×16 LED Chinese Character Scrolling Display Screen Based on AT89C51 Single Chip Microcomputer
O Introduction LED display is a flat display screen composed of light-emitting diode dot matrix modules or pixel units. It has the advantages of high luminous efficiency, long service life, flexible configuration, rich colors and strong adaptability to indoor and outdoor environments. It is widely used for informati
[Microcontroller]
Design of 16×16 LED Chinese Character Scrolling Display Screen Based on AT89C51 Single Chip Microcomputer
51 MCU I/O port simulation serial communication implementation method
The commonly used MCS51 and PIC series microcontrollers usually have only one (or no) UART asynchronous serial communication interface. If multiple serial interfaces are required in the application system (for example, in a multi-machine communication system, the host needs to communicate with both the slave and the
[Microcontroller]
51 MCU I/O port simulation serial communication implementation method
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号