ATMEL Studio 6.0 Programming : Interfacing Beep Buzzer


Please copy and Paste:
/********************************************************************************
 Written by: Vinod Desai,Sachitanand Malewar NEX Robotics Pvt. Ltd.
 Edited by: e-Yantra team
 ATMEL Studio Version 6

 Date: 26th December 2010

 This experiment demonstrates the simple operation of Buzzer ON/OFF with
 one second delay. Buzzer is connected to PORTC.3 of ATMEGAM2560

 Concepts covered:
 Output operation, generating exact delay www.sureshQ.Blogspot.in

 Note: Make sure that in the configuration options following settings are
 done for proper operation of the code

 Microcontroller: atmega2560
 Frequency: 14745600
 Optimization: -O0 (For more information read section: Selecting proper optimization
  options below figure 2.22 in the Software Manual)
*********************************************************************************/

/********************************************************************************
  ********************************************************************************/
#define F_CPU 14745600
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

//Function to initialize Buzzer
void buzzer_pin_config (void)
{
 DDRC = DDRC | 0x08; //Setting PORTC 3 as output
 PORTC = PORTC & 0xF7; //Setting PORTC 3 logic low to turnoff buzzer
}

void port_init (void)
{
 buzzer_pin_config();
}

void buzzer_on (void)
{
 unsigned char port_restore = 0;
 port_restore = PINC;
 port_restore = port_restore | 0x08;
 PORTC = port_restore;
}

void buzzer_off (void)
{
 unsigned char port_restore = 0;
 port_restore = PINC;
 port_restore = port_restore & 0xF7;
 PORTC = port_restore;
}

void init_devices (void)
{
 cli(); //Clears the global interrupts
 port_init();
 sei(); //Enables the global interrupts
}

//Main Function
int main(void)
{
init_devices();
while(1)
{
buzzer_on();
_delay_ms(1000); //delay
buzzer_off();
_delay_ms(1000); //delay
}
}
ATMEL Studio 6.0 Programming : Interfacing Beep Buzzer ATMEL Studio 6.0 Programming : Interfacing Beep Buzzer Reviewed by Suresh Bojja on 9/07/2018 09:35:00 PM Rating: 5
Theme images by sebastian-julian. Powered by Blogger.