MCU simulates switch light

Publisher:SereneSerenityLatest update time:2013-04-02 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Verification Task

As shown in Figure 4.2.1, the monitoring switch K1 (connected to the P3.0 port) is used, and the light-emitting diode L1 (connected to the P1.0 port of the microcontroller) is used to display the switch status. If the switch is closed, the L1 light is on, and if the switch is open, the L1 light is off.

2-way schematic

Click to browse the next page

Figure 4.2.1

3 Hardware connections on the system board

(1) Connect the P1.0 port in the "MCU System" area to the L1 port in the "Eight-way LED Indicator Module" area with a wire;

(2) Connect the P3.0 port in the "MCU System" area to the K1 port in the "Four-way Slide Switch" area with a wire;

4. Programming content

(1) Off state detection process

The detection of switch status by the MCU is to input the signal from the P3.0 port of the MCU, and the input signal has only two types: high level and low level. When the switch K1 is turned up, the high level is input, which is equivalent to the switch being disconnected. When the switch K1 is turned down, the low level is input, which is equivalent to the switch being closed. The MCU can use the JB BIT, REL or JNB BIT, REL instructions to complete the detection of the switch status.

(2) Output control

As shown in Figure 3, when the P1.0 port outputs a high level, that is, P1.0=1, according to the unidirectional conductivity of the light-emitting diode, the light-emitting diode L1 is off; when the P1.0 port outputs a low level, that is, P1.0=0, the light-emitting diode L1 is on; we can use the SETB P1.0 instruction to make the P1.0 port output a high level, and use the CLR P1.0 instruction to make the P1.0 port output a low level.

5 Sequence diagram

Click to browse the next page

 

Figure 4.2.2[page]

6. Compile source code

                            ORG 00H

START:               JB P3.0,LIG

                            CLR P1.0

                           SJMP START

LIG: SETB P1.0

                            SJMP START

                           END

7. C language source program

#include

sbit K1=P3^0;

sbit L1=P1^0;

void main(void)

{

  while(1)

    {

      if(K1==0)

        {

          L1=0; //light on

        }

        else

          {

            L1=1; //light off

          }

    }

}

The above is the complete source code of the microcontroller analog switch light

Keywords:MCU Reference address:MCU simulates switch light

Previous article:51 MCU clock and reset
Next article:Design of single-chip one-button multi-function button recognition

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

Design of Phase Failure and Phase Sequence Protection System Based on MCS-51 Single Chip Microcomputer
1 Introduction Phase failure and phase sequence protection is an indispensable part of the AC motor starting equipment in high-power three-phase AC motors and irreversible transmission equipment. Usually, analog phase failure and phase sequence protection relays are used. With the development of digital techno
[Microcontroller]
Design of Phase Failure and Phase Sequence Protection System Based on MCS-51 Single Chip Microcomputer
Solar LED Street Light Solution Using STM32 MCU
As fossil energy is decreasing and the problem of global warming caused by excessive greenhouse gas emissions is becoming more and more important, people are actively developing various types of renewable energy on the one hand, and advocating green environmental protection technologies for energy conservation and emi
[Power Management]
Solar LED Street Light Solution Using STM32 MCU
Design of digital capacitance measuring instrument based on 51 single chip microcomputer
This design introduces in detail a design scheme and implementation method of a digital capacitance measuring instrument based on a single-chip microcomputer. The main design method is to use a 555 chip to form a monostable trigger to convert the capacitance into a pulse width. The pulse width is measured by the timer
[Microcontroller]
Design of digital capacitance measuring instrument based on 51 single chip microcomputer
Experts explain PIC microcontrollers: Getting started with microcontrollers is so simple
It is not difficult to get started with microcontrollers. This is an old article from a few years ago. It is easy to understand and shared with beginners. This little crab with eight legs is our first meal. As long as we eat it, the next big meal will be easy. The 1st and 8th legs are connected to the power supply +
[Microcontroller]
Experts explain PIC microcontrollers: Getting started with microcontrollers is so simple
MCU LCD Operation
LCD operation: 1602 LCD can only display ASCI. Today, I will drive 1602 LCD. LCD operation is simpler than digital tube.  Basic operation sequence of LCD: 1.1 Read state: Input: RS = L, RW = H, E = H Output D0~D7 1.2 Write instruction: Input: RS = L, RW = L, D0~D7 instruction code, E = high pulse, output: none; RS is
[Microcontroller]
MCU LCD Operation
A high performance avr microcontroller frequency meter program 10khz
  #include iom16v.h #define uchar unsigned char #define uint unsigned int const volatile SEG_CODE =  {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00}; int main()  {          float LastKey = 0xff;                  DDRA = 0xff;                     DDRB = 0xff;                    DDRC = 0xff;   PORTC = 0xff
[Microcontroller]
A high performance avr microcontroller frequency meter program 10khz
C51 MCU Study Notes Serial Communication
Introduction Serial communication is a communication method between the microcontroller and the PC. Communication mode: parallel, serial, synchronous, asynchronous (most commonly used) Transmission direction: simplex, half-duplex (different time), full-duplex basic structure Related registers SCON serial por
[Microcontroller]
C51 MCU Study Notes Serial Communication
Make a good MCU 89C51 programmer according to the crooked circuit diagram
Last time I used the 89C51 microcontroller , the K1200 programmer had some problems. I didn't know whether it was the programmer or the microcontroller that had problems, so I made a simple 89C51 programmer myself, mainly because I didn't want to spend any money and used local materials. The circuit diagram was refere
[Power Management]
Make a good MCU 89C51 programmer according to the crooked circuit diagram
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号