Doorbell set by MCU timer

Publisher:不见南师久Latest update time:2020-01-02 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is a doorbell program set by a microcontroller timer, with source code and documentation. The doorbell designed with the timer is described as follows: When the button is pressed, the buzzer emits a ding-dong doorbell sound.


program

/* After downloading the program, pressing button K1 will trigger the buzzer doorbell to ring "Ding Dong" */


#include

typedef unsigned char u8;

typedef unsigned int u16;

sbit beep=P1^5;

sbit k1=P3^1;

u8 ding,dong,flag,stop;

u16 n;

void delay(u16 i)

{

        while(i--);

}

void time0init() //Timer 0 initialization

{

        TMOD=0X01; //Timer 0 mode 1

        TH0=0Xff;

        TL0=0X06; //timing 250us

//TR0=1;

        EA=1;

        ET0=1;

}

void biaohaoinit() // Initialize each label

{

        ding=0; //ding sound counting flag

        dong=0; //dong sound counting mark

        n=0; //0.5s timing mark

        flag=0;

        stop=0; //end mark

}

void main()

{

        time0init();

        biaohaoinit();

        while(1)

        {

                if(k1==0) // Check if the button is pressed

                {

                        delay(1000); //debounce

                        if(k1==0)

                        {

                                TR0=1; //Turn on timer 0

                                while(!stop);

                        }

                }        

        }        

}

void time0() interrupt 1

{

        n++;

        TH0=0Xff;

        TL0=0X06; //250us

        if(n==2000) //Timer 0.5s, ding for 0.5 seconds, dong for 0.5 seconds

        {

                n=0;

                if(flag==0)

                {

                        flag=~flag;

                }

                else

                {

                        flag=0;

                        stop=1;

                        TR0=0; //Turn off timer 0

                }

        }

        if(flag==0)

        { //The doorbell sound can be changed by changing the timing count time

                ding++; //ding

                if(ding==1)

                {

                        ding=0;

                        beep=~beep;

                }

        }

        else

        {

                dong++;

                if(dong==2) //dong

                {

                        dong=0;

                        beep=~beep;

                }        

        }

}

Keywords:MCU Reference address:Doorbell set by MCU timer

Previous article:51 MCU reads and writes RC522 card (LCD12864) RFID development program and schematic diagram
Next article:MCU programming practice infrared interrupt timing 12864 step by step explanation

Recommended ReadingLatest update time:2024-11-16 13:29

How long does it take to learn the basics of microcontroller? What can you do after learning the microcontroller?
Many friends are discouraged when they see that the microcontrollers circulated on the Internet are difficult and require both hardware and programming. In fact, to put it bluntly, this is a kind of human fear of unknown things. Afraid of spending time and energy and getting nothing in the end. There is a saying that
[Microcontroller]
An anti-interference power supply based on low-power single-chip microcomputer
introduction In recent years, various low-power microcontrollers have been widely used in various instruments, especially the 89C51/2 microcontroller, which has won a large number of users with its excellent performance, low price, standard power consumption reduction characteristics, and fast erasability of on
[Microcontroller]
STM32 timer1 generates PWM (complementary channels)
1. Introduction This article describes how to use the TIM1_CH2N channel (PB14) of timer1 to generate PWM in the STM32 series. 2. Experimental Platform Library version: STM32F10x_StdPeriph_Lib_V3.5.0 Compiler software: MDK4.53 Hardware platform: STM32 development board (main chip stm32f103c8t6) Emulator
[Microcontroller]
Using real-time MCUs to adapt to server power supply design trends
As servers and data centers are increasingly used around the world, there is a growing need for stable and efficient power supplies to cope with the increasing power consumption. Power consumption has been growing rapidly, requiring more integrated central processing units, graphics processing units, and
[Power Management]
Using real-time MCUs to adapt to server power supply design trends
Design of LED intelligent lighting system based on single chip microcomputer control
  AC LED intelligent lighting system provides convenience for people's daily life lighting, avoiding circuit failures caused by frequent switching. AC LED lighting does not add an AC/DC converter like DC LED lamps, which not only reduces costs, but also improves system efficiency and achieves the purpose of energy sav
[Microcontroller]
Design of LED intelligent lighting system based on single chip microcomputer control
AVR MCU external interrupt example and download and burn method
Memory Lock Bit (2) Protection Type LB Mode LB2LB1111 Memory protection feature is not enabled 210 Further programming of Flash and EEPROM is prohibited in parallel and SPI/JTAG serial programming modes, and the fuse bits are locked. (1) 300 Further programming and verification of Flash and EEPROM are prohibited in pa
[Microcontroller]
AVR MCU external interrupt example and download and burn method
The role of crystal oscillator in single chip microcomputer
When the microcontroller is working, it fetches instructions from the RoM one by one and then executes them step by step. The time it takes for the microcontroller to access the memory is called a machine cycle, which is a time base. A machine cycle consists of 12 clock cycles. If a microcontroller selects a 12MHz c
[Microcontroller]
Asphalt intelligent softening point tester based on single chip microcomputer
introduction The asphalt ball sample with a diameter of 10mm is placed on a bracket immersed in a heat transfer medium. When heated to a certain temperature, the asphalt melts. At this time, asphalt solution will drip from the sample through the holes on the bracket and be detected by the photoelectric dete
[Industrial Control]
Asphalt intelligent softening point tester based on single chip microcomputer
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号