0% found this document useful (0 votes)
64 views3 pages

AVR Atmega2560 Input Output Peripherals

This code configures the ports and pins of a microcontroller to control the movement and buzzer of a robot. It initializes ports for output, configures motion pins for wheels and PWM, defines functions for movement directions and buzzer control, and implements a main loop that moves the robot forward and backward while turning the buzzer on and off periodically.

Uploaded by

mathstopper
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views3 pages

AVR Atmega2560 Input Output Peripherals

This code configures the ports and pins of a microcontroller to control the movement and buzzer of a robot. It initializes ports for output, configures motion pins for wheels and PWM, defines functions for movement directions and buzzer control, and implements a main loop that moves the robot forward and backward while turning the buzzer on and off periodically.

Uploaded by

mathstopper
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <avr/io.

h>

#include <avr/interrupt.h>

#include <util/delay.h>

void port_init(void)

DDRC=0X08; //DDRC register is used to initialize PortC as output port.

//Buzzer is connected to PIN 3 of PORTC

//Write suitable value to ensure only buzzer PIN 3 can be used.

PORTC=0X00; //PORTC register is used to turn on/off output device.

//Write suitable value to ensure buzzer is turned off at the start.

void motion_pin_config (void)

DDRA =0X0F; //set direction of the PORTA pins (PA3-PA0) as output

PORTA =0X00; //set initial value of the PORTA pins (PA3-PA0) to logic 0

DDRL =0X18; //Setting PL3 and PL4 pins as output for PWM generation

PORTL =0X18; //PL3 and PL4 pins are used for velocity control using PWM

}
void forward (void) //both wheels forward

PORTA=0X06; // Write sutiable value in PORTA to set direction of both wheels as


forward.

void stop (void)

PORTA=0X00; //Write suitable value in PORTA register to stop the robot.

void buzzer_on(void)

PORTC=0X08 ; //Write suitable value in PORTC to turn ON the buzzer

void buzzer_off(void)

PORTC=0X00; //Write suitable value in PORTC to turn off the buzzer

//Main Function
int main()

port_init();

motion_pin_config();

while(1)

forward();

_delay_ms(500);

stop();

buzzer_on();

_delay_ms(200);

buzzer_off();

//write your code here to moveto trace the straight line(in forward direction) using the
path traversed by the Firebird V for 5 seconds

// and then stop and turn ON Buzzer for 2 second.

//You can use _delay_ms() to generate the required delay

You might also like