Continue with the previous post of line follower using 8051 micro controller . . .
The line follower using AVR micro controller you just need to change the development environment form8051 to AVR.
Rest of the things are mentioned below..
AVR ATMega16 Micro controller:
Microcontroller acts as the Brain of robot, which generates desired output for corresponding inputs. In present days, there are several companies that manufacture microcontrollers, for example ATMEL, Microchip, Intel, Motorola, Philips etc. We will be using ATMega16 microcontroller in our robot. ATmega16 is an 8-bit high performance microcontroller of Atmel’s Mega AVR family with low power consumption. Atmega16 is based on enhanced RISC (Reduced Instruction Set Computing) with 131 powerful instructions.Most of the instructions execute in one machine cycle. Atmega16 can work on a maximum frequency of 16MHz. ATmega16 has 16 KB programmable flash memory, static RAM of 1 KB and EEPROM of 512 Bytes.
ATmega16 is a 40 pin microcontroller. There are 32 I/O (input/output) lines which are divided into four 8-bit ports designated as PORTA, PORTB, PORTC and PORTD.
ATmega16 has various in-built peripherals like USART, ADC, Analog Comparator, SPI, JTAG etc. Each I/O pin has an alternative task related to in-built peripherals.
AVR Pin Diagram |
AVR Microcontroller Programmer Unit:
It is used to feed the .hex file from PC to AVR IC
muincept AVR Development board |
Software Details:
The program code acts as the decision-maker embedded in the
microcontroller i.e. it decides what will be the outputs for particular
set of input combination. Programs for the AVR series of
microcontrollers can be written in assembly (ASM) and C. AVR studio 4,
Ponyprog etc. are some free development software’s for programming the
ATMega16 Microcontrollers.
AVR Studio 4:
Atmel® Studio 4 is the integrated development platform (IDP) for
developing and debugging Atmel ARM® Cortex™-M and Atmel AVR®
microcontroller- (MCU-) based applications. The Atmel Studio 4 IDP gives
you a seamless and easy-to-use environment to write, build and debug
your applications written in C/C++ or assembly code.
AVR studio is an Integrated Development Environment (IDE) by ATMEL for developing applications based on 8-bit AVR microcontroller. Prior to installation of AVR Studio you have to install the compiler WinAVR. This will allow AVR Studio to detect the compiler.
Download from www.atmel.in/microsite/atmel_studio6/
Code for Line follower Robot:
#include<avr/io.h> //Header file
#define sensor1 PA0 //Left Sensor
#define sensor2 PA1 //Right sensor
void sw();
int main(void) //main function
{
DDRB=0xFF; //output pin high
DDRA=0xFC; //input pin low
while(1)
{
PINA=0x03; //initialize input pin high in pin register
sw();
}
}
void sw1()
{
if(bit_is_clear(PINA,sensor2)) //checks whether right sensor is low
PORTB=0b00000000; //both left and right side motor low if true
else
PORTB=0b00000001; //right side motor turns on and left motor off if false
}
void sw2()
{
if(bit_is_clear(PINA,sensor2)) //checks whether right sensor is low
PORTB=0b00000010; //right side motor turns off and left motor on if true
else
PORTB=0b00000011; //both left and right side motor high if false
}
void sw()
{
if(bit_is_clear(PINA,sensor1)) //Checks whether left sensor is low
sw1(); //terminate to this function if true
else
sw2(); //terminate to this function if false
}
#define sensor1 PA0 //Left Sensor
#define sensor2 PA1 //Right sensor
void sw();
int main(void) //main function
{
DDRB=0xFF; //output pin high
DDRA=0xFC; //input pin low
while(1)
{
PINA=0x03; //initialize input pin high in pin register
sw();
}
}
void sw1()
{
if(bit_is_clear(PINA,sensor2)) //checks whether right sensor is low
PORTB=0b00000000; //both left and right side motor low if true
else
PORTB=0b00000001; //right side motor turns on and left motor off if false
}
void sw2()
{
if(bit_is_clear(PINA,sensor2)) //checks whether right sensor is low
PORTB=0b00000010; //right side motor turns off and left motor on if true
else
PORTB=0b00000011; //both left and right side motor high if false
}
void sw()
{
if(bit_is_clear(PINA,sensor1)) //Checks whether left sensor is low
sw1(); //terminate to this function if true
else
sw2(); //terminate to this function if false
}
Ponyprog:
PonyProg is a serial device programmer software with a user friendly GUI
framework available for Windows95/98/ME/NT/2000/XP and Intel Linux. Its
purpose is reading and writing every serial device. At the moment it
supports I²C Bus, Microwire, SPI eeprom, the Atmel AVR.
Download from http://www.lancos.com/prog.html
Serial Cable:
A serial cable is a cable used to transfer information between two devices using a serial communication protocol.
No comments:
Post a Comment