Microcontroller C language programming: doorbell designed with timer

Publisher:wmghyuLatest update time:2013-08-31 Source: 21icKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

 /* Name: Doorbell designed with timer


Description: When the button is pressed, the buzzer emits a doorbell sound.


*/


#include


#define uchar unsigned char


#define uint unsigned int


sbit Key=P1^7;


sbit DoorBell=P3^0;


if p=0;


//Main program


void main()


{


DoorBell=0;


TMOD=0x00; //T0 mode 0


TH0=(8192-700)/32; //700us timing


TL0=(8192-700)%32;


IE=0x82;


while(1)


{


if(Key==0) //Press the button to start the timer


{


TR0=1;


while(Key==0);


}


}


}[page]

//T0 interrupt controls the dot matrix screen display

void Timer0() interrupt 1

{

DoorBell=~DoorBell;

p++;


if(p<400) //If you need to prolong the sound, you can adjust 400 and 800


{


TH0=(8192-700)/32; //700us timing


TL0=(8192-700)%32;

}

else if(p<800)

{

TH0=(8192-1000)/32; //1ms timing


TL0=(8192-1000)%32;

}
else

{

TR0=0;

p=0;

}

}

Microcontroller C language programming: doorbell designed with timer

Keywords:MCU Reference address:Microcontroller C language programming: doorbell designed with timer

Previous article:Microcontroller C language programming: playing scales
Next article:Microcontroller C language programming: key control 8X8LED dot matrix screen display graphics

Recommended ReadingLatest update time:2024-11-15 18:00

MSP430 MCU 16-bit timer Timer_A operation
/**********(一)Timer A comparison mode*************/  int main( void )  {  WDTCTL=WDTPW+WDTHOLD; //Turn off watchdog  BCSCTL1 =CALBC1_1M Hz ; //Set DCO to 1MHZ  DCOCTL =CALBC1_1MHZ;    P1DIR |= BIT0; //LED enable  TACTL=TASSEL1+TACLR; //Timer A clock source is SMCLK, and clear TAR  CCTL0 |= CCIE; //CCR0 interrupt enabl
[Microcontroller]
Use 51 MCU and DAC0832 as waveform generator
LM324 can be used with a single power supply or with positive and negative dual power supplies. For this circuit, we hope that it can output: 0~-5V, so we must add positive and negative dual power supplies to it. If only a positive 12V power supply is added, its output can only be: 0~+12V, and it can never output a ne
[Microcontroller]
Use 51 MCU and DAC0832 as waveform generator
Using 89C51 single chip microcomputer to realize infrared communication interface circuit control
In communication systems, non-electrical signals are often used to transmit control signals and data to achieve remote control or telemetry functions. Infrared communication is a commonly used communication method with the characteristics of simple control, convenient implementation, and high transmission reliability.
[Microcontroller]
Using 89C51 single chip microcomputer to realize infrared communication interface circuit control
How does the automotive gateway improve the driving experience?
Automotive suppliers and OEMs are investing heavily in software development to add new functions and features to enable autonomy, electrification and connectivity. However, implementing these features by adding more electronic control units (ECUs) is not feasible as it would increase system complexity and cost.   Ther
[Embedded]
How does the automotive gateway improve the driving experience?
Design of wireless charger based on MSP430 microcontroller
   introduction   At present, the charging of portable electronic devices such as mobile phones, MP3 and laptops mainly adopts the traditional charging method of connecting one end to the AC power supply and the other end to the portable electronic device rechargeable battery. This method has many disadvantages, such
[Power Management]
Design of wireless charger based on MSP430 microcontroller
51 MCU timer clock
1.main.c Note: Sec, Min, Hour do not need to be assigned #include REGX52.H #include "Delay.h" #include "LCD1602.h" #include "Timer0.h"   unsigned char Sec=55,Min=59,Hour=23;   void main() { LCD_Init(); Timer0Init(); LCD_ShowString(1,1,"Clock:"); LCD_ShowString(2,1," : :");   while(1) { LCD_Show
[Microcontroller]
msp430 single chip microcomputer frequency measurement
/****************************************************** ****** Author: Made by Xura Date: 2008.8.28Program description: Use Timer_A to capture pulse width Use the MSP430 single-chip timer A and the capture/compare function module to measure the pulse width The program uses the CCI1A port of timer A (P1.2 pin of MS
[Microcontroller]
Principle of 80C196MC single chip microcomputer waveform generator and its application in inverter power supply
     PWM technology has evolved from using analog circuits with separate components to compare triangle waves and sine modulation waves to generate SPWM control signals. Now, it has adopted a fully digital solution to complete real-time online PWM (SPWM) signal output. PWM control circuits have evolved from being simpl
[Microcontroller]
Principle of 80C196MC single chip microcomputer waveform generator and its application in inverter power supply
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号