NEX Robotics
2.4 Writing your first code in AVR Studio
This program will make robot's buzzer beep.
Copy the following code in window "code area" as shown in figure 2.25. We will see how this
code works in the next chapter.
//Buzzer is connected at the third pin of the PORTC
//To turn it on make PORTC 3
#include
<avr/io.h>
#include
<avr/interrupt.h>
#include
<util/delay.h>
//Function to initialize Buzzer
void
buzzer_pin_config (void)
{
DDRC = DDRC | 0x08;
PORTC = PORTC & 0xF7;
}
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);
buzzer_off();
_delay_ms(1000);
}
}
www.nex-robotics.com
rd
(PC3 )pin logic 1
//Setting PORTC 3 as output
//Setting PORTC 3 logic low to turnoff buzzer
//delay
//delay
Fire Bird V Software Manual
24
Need help?
Do you have a question about the Fire Bird V ATMEGA2560 and is the answer not in the manual?