STC51 MCU running light + external interrupt buzzer

Publisher:painterLatest update time:2020-12-03 Source: 51heiKeywords:STC51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I made a simple running light in my spare time. The design idea is to display the LED lights from 0 to 7 one by one, and then from 7 to 0 one by one. If an external interrupt occurs (i.e. a button is pressed), all 8 LED lights will light up, and then the running light state will be restored.


#include

#include


#define uchar unsigned char

#define uint unsigned int

sbit K=P3^2; //Start button, external interrupt

uchar led;


void delay(uint x)               

{

        while(x--);       

}


void XX()//interrupt setting

{

        EA=1;

        EX0=1;

}


void DD()

{

        uint i=0; //define i=0 for the following call

        led=0xfe; //1111 1110

        delay(30000);

        while(1)

        {

                for(i=0;i<7;i++)

                {

                        led=_crol_(led,1); //1111 1101 (A,B), A is the value of left shift, B is the number of bits of left shift

                        P1=led;

                        delay(30000);

                }

                for(i=0;i<7;i++)

                {

                        led = _cror_ (led, 1); // 0111 1111

                        P1=led;

                        delay(30000);

                }

        }

}


void main()

{

        XX();

        DD();

}


void XX1() interrupt 0

{

        delay(1000); //anti-shake

        if(K==0)

        {       

                P1 = 0X00;

                delay(30000);

        }               

}


Keywords:STC51 Reference address:STC51 MCU running light + external interrupt buzzer

Previous article:The PWM wave of the single-chip mechanical arm controls multiple servos according to regular movements
Next article:51 single chip Hall bicycle meter speedometer odometer

Recommended ReadingLatest update time:2024-11-16 23:39

CT107D Bluebridge Buzzer and Relay (2)
Today I will tell you about the buzzer and relay of this board. 1,——Buzzer First find the picture, the buzzer is called buzz Then I saw that it was N BUZZ port control, and continued to look for Here we know that the buzzer is controlled by the latch U9. When Q7 is 0, the buzzer works. Then we continue to fin
[Microcontroller]
CT107D Bluebridge Buzzer and Relay (2)
STC51 MCU serial port sending program
#include reg52.h    #define uchar unsigned char    unsigned char rtemp,sflag; unsigned char code Buffer = "Welcome To The MCU World.";//Data to be sent unsigned char *p;   unsigned char TestBuff ; unsigned char mode=0; unsigned char ArrayIndex=0; void SerialInit() //11.0592M crystal, baud rate 19200    {       TMO
[Microcontroller]
AVR microcontroller driving active buzzer experimental program
/*           Active buzzer experiment;   Features: Active buzzer is extremely simple, it is a two-source component,            this system uses a buzzer working voltage of 5v, as long as it is connected to a 5V power supply, the buzzer will sound.            Hardware connection: PC7 pin;       Sound system: s
[Microcontroller]
C51 single chip buzzer wish you peace music
#include "reg52.h" unsigned char Count; sbit _Speak =P1^5 ;  unsigned char code SONG ={ //Wish you peace 0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20, 0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20, 0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x
[Microcontroller]
How to use STC51 microcontroller EEPROM
STC51 microcontroller has a flash-like function EEPROM, which can save data when power is turned off. Different models can save data of different sizes. Taking 12C5A60S2 as an example, the size of the EEPROM is 2K and is divided into two sectors. It needs to be saved in many places when power is turned off. . First
[Microcontroller]
How to use STC51 microcontroller EEPROM
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号