AVR Lesson 5: Buzzer

Publisher:GoldenSunriseLatest update time:2020-07-24 Source: 51heiKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*

*info:buzzer

*author:chenlu

*date:2014.11.20

*/


//input the head file so that the program can work normally

//iom16v---know the register

//macros---know the BIT(x)

#include

#include

//use those can make your study very conveninet

#define uint unsigned int

#define uchar unsigned char


//display methods 

void initSystem();

void delay();


//the main function

void main()

{

  //init your system

initSystem();

while(1)

{

  //start your function,and this is core solution

PORTA = PORTA & (~BIT(1));

delay();

delay();

delay();

delay();

PORTA = PORTA | BIT(1);

delay();

delay();

delay();

delay();

}

}


//the method of init system

void initSystem()

{

  //to make PA1 port output 

DDRA = DDRA | BIT(1);

//to make PA1 port output high level

PORTA = PORTA | BIT(1);

}


//the sub method of delay

void delay()

{

  flying i,j;

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

  for(j=0;j<250;j++);

}


Make the buzzer sound once, then stop, and repeat this cycle.

Keywords:AVR Reference address:AVR Lesson 5: Buzzer

Previous article:AVR Lesson 8: Independent Buttons
Next article:AVR microcontroller controls light emitting diodes

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

Bascom AVR MCU simulation OLED display
800000 Config Clockdiv = 1 ' make sure the chip runs at 8 MHz Config Scl = Portc.5 ' used i2c pins Config Sda = 0 ' ' -------------------------------------------------------------------------------------------- ' SSD1306 -   I2C.BAS ' ( c) MCS Electronics 1995-2015 ' Sample to demo the 128x64 I2C OLED display ' '----
[Microcontroller]
Bascom AVR MCU simulation OLED display
51 MCU Basics of IoT 04-Buzzer
Preface In the previous section, we completed the key operation. In this section, we will learn to use the buzzer. First, we will introduce the buzzer, and then complete the experiment: the default driving frequency after power-on is 5KHZ, the driving frequency is controlled by KEY1 to 1KHZ, and the buzzer, KEY2 contr
[Microcontroller]
51 MCU Basics of IoT 04-Buzzer
AVR timer/counter 1 --TC1 --input capture mode (capture external event mode)
The input capture unit of the T/C can be used to capture external events and give them a time stamp to indicate the time when this time occurs. The trigger signal of the external event is input by pin ICP1 (PD6) or can be realized by the analog comparator unit. The time stamp can be used to calculate the frequency, du
[Microcontroller]
Avr128 watchdog settings
 When there is WDR() in the program, that is, the watchdog is fed, the program only executes the part in while, because the watchdog is fed again before the watchdog timing is up, which means the counter is still counting again. There is no WDR() in the program, that is, the watchdog is not fed. When the program execu
[Microcontroller]
ABDAC peripheral audio playback design on AVR32 MCU
  The ABDAC peripheral on the AVR32 MCU is ideal for generating audio playback. This article explains how to do this and includes a link to a sample driver that generates a sine wave output.   Many embedded applications increasingly feature audio playback capabilities, whether simple audio feedback in response to us
[Microcontroller]
ABDAC peripheral audio playback design on AVR32 MCU
Proteus introductory tutorial: AVR microcontroller simulation example
Introduction: This article is an introductory tutorial for Proteus and a simulation example of AVR microcontroller. 1. Simulation example of AVR microcontroller This example is to realize AVR driving LCD1602 and use oscilloscope to monitor the data line. Before you start, you need to prepare the simulation file,
[Microcontroller]
Proteus introductory tutorial: AVR microcontroller simulation example
JTAG is used to download hex files in Changxue multifunctional AVR experimental box
1) Hardware connection is the same as the JTAG simulation above 2) Open the studio and click cancel. 3) Open the menu Tools-program AVR-Connect 4) The following interface appears, select JTAG ICE-Auto, and then click connect 5) If the following interface appears, congratulations, JTAG has been connected to
[Microcontroller]
JTAG is used to download hex files in Changxue multifunctional AVR experimental box
IAR For AVR Precision Delay
It is not easy to use an accurate delay program in C language. IAR has a function called __delay_cycles(), which is defined in the header file intrinsics.h. The function is to delay N instruction cycles. Based on this function, an accurate delay function can be implemented (but it cannot be 100% accurate). Implementat
[Microcontroller]
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号