AVR - ATMEGA32 - Project Report
AVR - ATMEGA32 - Project Report
Atmega32
A PROJECT REPORT
submitted by
of
Bachelor of Engineering
degree in
1
INSTITUTE OF ENGINEERING AND TECHNOLOGY
DECLARATION
We hereby declare that the project entitled “AVR Development kit Using AVR Atmega32”
submitted by us to the Institute of Engineering and Technology, DAVV, Indore in partial
fulfilment of the requirements for the award of the degree of Bachelor of Engineering in
Electronics and Telecommunications is a record of Bonafide work carried out by us under
the supervision of Dr. Uma Bhatt, Assistant Professor (Senior). We further declare that the
work reported in this project has not been submitted and will not be submitted, either in
part or in full, for the award of any other degree or diploma of this institute or of any other
institute or university.
Rounak Likhar(16T8136)
Varun Mohane(16T8148)
Shivam Choudhary(17T8185)
2
Institute of Engineering and Technology
CERTIFICATE
The project report entitled “AVR Development kit Using AVR Atmega32” is prepared and
submitted by Rounak Likhar (Register No: DE16343), Varun Mohane (Register No: DE16343),
Amrit Singh Patel (Register No:DE17608) and Shivam Choudhary (Register No:DE17619). It
has been found satisfactory in terms of scope, quality and presentation as partial fulfilment
of the requirements for the award of the degree of Bachelor of Engineering in DAVV, India.
3
ACKNOWLEDGEMENT
We would like to take this opportunity to extend our deepest gratitude to our project
guide, Asst. Professor Dr. Uma Bhatt. for her constant guidance throughout the duration of
our project. Finally, we would like to thank DAVV, all our professors, fellow students and
friends for providing us with the necessary resources and motivation to carry out our work.
It was their constant encouragement and support that helped us to complete our project
successfully.
4
TABLE OF CONTENTS
CHAPTER NO TITLE
1. INTRODUCTION
i. GENRAL
ii. MOTIVATION
iii. AIM AND OBJECTIVE
2. REQUIREMENTS
i. HARDWAR
ii. SOFTWARE
PROGRAMS
6. ORIGINAL BOARD
7. REFERENCES
5
1. INTRODUCTION
1.1 General
Our project AVR development board is based on AVR microcontroller Atmega32 which is
used to run various modules such relay motor, 7-segment, LCD display etc. The
microcontroller is programmed using USB to TTL logic, USBasp can be used for this purpose.
The programming part can be done on the Atmel studio and we need to generate a hex file
for the program that can be burned in the microcontroller through a software Progisp. This
AVR development board is handy and can be used for the leaning purpose and for the basic
understanding of the AVR microcontroller and its interfacing with various components.
1.2 Motivation
The motivation behind the project is to enable the students to learn electronics and its
practical applications. In college while we were learning microcontroller and its
programming, we noticed that there were not many resources in the college to understand
working of programs. There were some development kits purchased by the institution but
they were much expensive for any student to afford. And with limited number of kits
available, students were not able to get a clear insight into the working. Also, there were no
proper instruction to operate them. Hence, we decided to make development boards for
this purpose and submit in the college.
6
2.1 H/W requirements
AVR Atmega32
16 MHz Crystal Oscillator
Two 100nf capacitor
Two 22pf capacitor
10nf Capacitor
Resistor 470 ohm
L293D/UML2003 motor driver
Stepper motor
DC induction motor
4x4 keyboard
16x2 LCD display
Variable resistor 1 to 100 kiloohm
Led lights
USB asp
Progisp
Zadig
Atmel Studio
7
3. Analysis and Design
The project goal was to create minimalist development board that will:
1). base on single-layer PCB layout,
2). include only through hole parts,
3). expose AVR ISP socket (JP3) for USBasp programmer,
4). make all GPIO pins available on the PCB via headers (JP1, JP2), 5).
contain MCU socket and extra power connector (JP4).
8
3.1 Brief Introduction
9
3.2 Working –
Before inserting a code into microcontroller, we have to develop code with the help of suitable
software like Atmel studio and etc. For this we have to follow the steps showed below
Here we can see in system, system type which says it is a 64-bit operating system. Depending
on the system type, install the compatible Atmel studio
10
We will see the below file opened
11
Then install
12
CREATING A NEW AVR ASM(ASSEMBLER) PROJECT IN AVR STUDIO 7
Step 1: To create an ASM project first start AVR Studio 7 by going to the start menu on your
PC select Atmel Studio 7.0. See the figure below.
After AVR Studio 7 starts the following window will appear. From which get help, open an
existing project, create a new project, open an example project, etc.
13
Step 2: Click on New Project to start a new project. The following window will appear.
Step 3: To start a new ASM project select ASM from the panel to the left. Also type the
file Name and Location. The following window will then appear.
14
Step 4: The window above is the device selection screen for AVR Studio 7. Scroll down and
select the microcontroller you will be using. The following window will then appear
This is the AVR studio 7 editor where you type your ASM program. The editor starts your
ASM program for you by providing you with the structure shown in the editor of the figure
above.
To start with microcontroller development board, we should follow steps written below –
Step 1 –
We have to interface or connect microcontroller with the device which can load or write the
code into the microcontroller. The devices could be laptop, PC’s connected via Boot loader
devices (TTL logic, Arduino Uno, USB ISP flasher and may be other than that).
15
If we are using laptop or PC’s we should have USB ASP flasher or Arduino Uno which connects
this device to the microcontroller board (This flasher or Arduino used to load the code into
microcontroller). For this connection we should have preinstalled drivers of that flasher or
Arduino Uno into the device. Since the driver generally not available in the PC, we have to
use some software to install the required drivers into the PC (The software’s may be Zadig,
boot-loader).
Step 2 –
Now in this step we are going to connect or interface the desired module with the
microcontroller (Which are connected with PC’s via boot loader device).
To write the code into the microcontroller we have to use some software (The software may
be Arduino IDE, Atmel Studio).
Now after that we can write the code into microcontroller with the help of this software
(Progisp, Arduino IDE or any other)
If we are using progisp to load code –
First, we have to select the microcontroller serial number (in our case it is Atmega32)
Then erase this controller using its erase function and then load the code into this from the
load flash function
After the code insertion our controller send the commands to module and it starts working
16
Zadig is meant to install a libusb compatible driver, for a device that does not yet have such
a driver installed. With the application running, you should see your USB device appear in
the dropdown list (click on the dropdown to see all devices).
You can also plug your USB device after Zadig is running, as the list is refreshed automatically.
Its recommended to leave only the device you want to install a driver for, and unplug any
other USB device. You can also select the driver you want to install, (between WinUSB/
libusbwin32/libusb0 / libusbK). Once you are satisfied with the selection and device
description, simply click the Install Driver Button.
If you open the PROGISP application (to load HEX file on to8051), you see the PRG ISP icon
greyed out, as the programmer is not yet detected.
Image shows the progisp interface when the drivers are successfully installed.
17
After writing the code or insertion of code, the microcontroller read the code and start the
execution of code through the board and send the instruction to the module. After that our
module starts working.
18
Description of components/Modules –
1. Stepper motor-
A stepper motor is an electric motor whose main feature is that its shaft rotates by
performing steps, that is, by moving by a fixed amount of degrees. This feature is obtained
thanks to the internal structure of the motor, and allows to know the exact angular position
of the shaft by simply counting how may steps have been performed, with no need for a
sensor. This feature also makes it fit for a wide range of applications. ULN 2003 can be used
as a motor driver.
19
Sample Program-
To interface Stepper motor with Microcontroller and move it into different directions
int main(void)
{
int period;
DDRD = 0x0F; /* Make PORTD lower pins as output */
period = 100; /* Set period in between two steps */
while (1)
{
/* Rotate Stepper Motor clockwise with Half step sequence */
for(int i=0;i<12;i++)
{
PORTD = 0x09;
_delay_ms(period);
PORTD = 0x08;
_delay_ms(period);
PORTD = 0x0C;
_delay_ms(period);
PORTD = 0x04;
_delay_ms(period);
PORTD = 0x06;
_delay_ms(period);
PORTD = 0x02;
_delay_ms(period);
PORTD = 0x03;
_delay_ms(period);
PORTD = 0x01;
_delay_ms(period);
}
PORTD = 0x09; /* Last step to initial position */
_delay_ms(period);
_delay_ms(1000);
20
/* Rotate Stepper Motor Anticlockwise with Full step sequence */
for(int i=0;i<12;i++)
{
PORTD = 0x09;
_delay_ms(period);
PORTD = 0x03;
_delay_ms(period);
PORTD = 0x06;
_delay_ms(period);
PORTD = 0x0C;
_delay_ms(period);
}
PORTD = 0x09;
_delay_ms(period);
_delay_ms(1000);
}
}
2. Temperature sensor-
A temperature sensor is an electronic device that measures the temperature of its
environment and converts the input data into electronic data to record, monitor, or signal
temperature changes. There are many different types of temperature sensors. Some
temperature sensors require direct contact with the physical object that is being monitored
(contact temperature sensors), while
others indirectly measure the
temperature of an object (non-
contact temperature sensors).
21
Sample Program-
To interface Temperature sensor with Microcontroller
void ADC_Init(){
DDRA = 0x00; /* Make ADC port as input */
ADCSRA = 0x87; /* Enable ADC, with freq/128 */
ADMUX = 0x40; /* Vref: Avcc, ADC channel: 0 */
}
22
int main()
{
char Temperature[10];
float celsius;
while(1)
{
LCD_String_xy(1,0,"Temperature");
celsius = (ADC_Read(0)*4.88);
celsius = (celsius/10.00);
sprintf(Temperature,"%d%cC ", (int)celsius, degree_sysmbol);/* convert integer va
lue to ASCII string */
LCD_String_xy(2,0,Temperature);/* send string data for printing */
_delay_ms(1000);
memset(Temperature,0,10);
}}
3. 4X4 Keyboard-
The 4*4 matrix keypad usually is used as input in a project. It has 16 keys in total, which
means the same input values.
The 4X4 Matrix Keypad Module is a matrix non- encoded keypad consisting of 16 keys in
parallel. The keys of each row and column are connected through the pins outside – pin
Y1Y4 as labelled beside control the rows, when X1-X4, the columns.
23
Sample Program –
To interface 4X4 keyboard with Microcontroller and get the input from keyboard and display
it on LCD
#include "LCD16x2_4bit.h"
#include <avr/io.h>
#include <util/delay.h>
char keyfind()
24
{
while(1)
{
KEY_DDR = 0xF0; /* set port direction as input-output */
KEY_PRT = 0xFF;
do
{
KEY_PRT &= 0x0F; /* mask PORT for column read only */
asm("NOP");
colloc = (KEY_PIN & 0x0F); /* read status of column */
}while(colloc != 0x0F);
do
{
do
{
_delay_ms(20); /* 20ms key debounce time */
colloc = (KEY_PIN & 0x0F); /* read status of column */
}while(colloc == 0x0F); /* check for any key press */
if(colloc == 0x0E)
return(keypad[rowloc][0]); else
if(colloc == 0x0D)
return(keypad[rowloc][1]); else
if(colloc == 0x0B)
return(keypad[rowloc][2]);
else
return(keypad[rowloc][3]);
}
int main(void)
{
LCD_Init();
LCD_String_xy(1,0,"Press a key");
while(1)
{
LCD_Command(0xc0);
LCD_Char(keyfind()); /* Display which key is pressed */
}
}
26
4. Seven segment display-
A seven-segment display is a form of electronic display device
for displaying decimal numerals that is an alternative to the
more complex dot matrix displays. Seven-segment displays are
widely used in digital clocks, electronic meters, basic calculators,
and other electronic devices that display numerical information.
Sample Program-
To print values from 0 to 9 in 7-Segment using Microcontroller
{
LED_Direction |= 0xff; /* define LED port direction is output */
LED_PORT = 0xff;
char array[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
/* write hex value for CA display from 0 to 9 */
while(1)
{
for(int i=0;i<10;i++)
{
LED_PORT = array[i]; /* write data on to the LED port */
_delay_ms(1000); /* wait for 1 second */
}
}
}
28
29
Sample Program-
1. To interface LCD with Microcontroller
{
LCD_Data_Port= cmnd;
LCD_Command_Port &= ~(1<<RS); /* RS=0 command reg. */
LCD_Command_Port &= ~(1<<RW); /* RW=0 Write operation */
LCD_Command_Port |= (1<<EN); /* Enable pulse */
_delay_us(1);
LCD_Command_Port &= ~(1<<EN);
_delay_ms(3);
}
{
LCD_Data_Port= char_data;
LCD_Command_Port |= (1<<RS); /* RS=1 Data reg. */
LCD_Command_Port &= ~(1<<RW); /* RW=0 write operation */
LCD_Command_Port |= (1<<EN); /* Enable Pulse */
_delay_us(1);
LCD_Command_Port &= ~(1<<EN);
_delay_ms(1);
}
{
LCD_Command_Dir = 0xFF; /* Make LCD command port direction as o/p */
30
LCD_Data_Dir = 0xFF; /* Make LCD data port direction as o/p */
_delay_ms(20); /* LCD Power ON delay always >15ms */
{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
LCD_Char (str[i]);
}
}
{
if (row == 0 && pos<16)
LCD_Command((pos & 0x0F)|0x80); /* Command of first row and
required
position<16 */
else (row == 1 && 16)
if pos< x0F 0xC0); /* Command of first row and required
LCD_Command((pos &0 )| position<16 */
LCD_String(str); /* Call LCD string
function */
}
{
); 0x01/* clear display */
LCD_Command ( ); 0x80/* cursor at home position */
LCD_Command ( }
31
LCD_String("ElectronicWINGS") ; /* write string on 1st line of LCD*/
LCD_Command(0xC0 "Hello); /* Go to 2nd line*/
LCD_String(World" ); /* Write string on 2nd line*/
} return 0;
#define F_CPU 8000000UL /* Define CPU Frequency e.g. here its 8MHz */
#include <avr/io.h> /* Include AVR std. library file */
#include <util/delay.h> /* Include inbuilt defined Delay header file */
32
void LCD_Char (unsigned char char_data) /* LCD data write function */
{
LCD_Data_Port= char_data;
LCD_Command_Port |= (1<<RS); /* RS=1 Data reg. */
LCD_Command_Port &= ~(1<<RW); /* RW=0 write operation */
LCD_Command_Port |= (1<<EN); /* Enable Pulse */
_delay_us(1);
LCD_Command_Port &= ~(1<<EN);
_delay_ms(2); /* Data write delay */
}
void LCD_String_xy (char row, char pos, char *str) /* Send string to LCD with xy position */
{
if (row == 0 && pos<16)
LCD_Command((pos & 0x0F)|0x80); /* Command of first row and required position<16 */
33
else (row == 1 && 16)
if pos< x0F 0xC0); /* Command of first row and required
LCD_Command((pos &0 )| position<16 */
LCD_String(str); /* Call LCD string
function */
}
void LCD_Clear()
{
); 0x01/* clear display */
LCD_Command ( ); 0x80/* cursor at home position */
LCD_Command ( }
int main()
{
char i;
unsigned char Character1[8] = { 0x00, 0x0A, 0x15, 0x11, 0x0A, 0x04, 0x00, 0x00 };
/*
Custom char set for alphanumeric LCD Module */
34
unsigned 8] 0x04, 0x1F, 0x11, 0x11, 0x1F, 0x1F, 0x1F, };
charCharacter2[ = 0x1F
{ 0x00, 0x04,};
unsigned 8] 0x04, 0x0E, 0x0E, 0x0E, 0x1F, 0x00
charCharacter3[ = 0x07, 0x03,};
{ 0x01 }
unsigned 8] 0x01, 0x03, 0x07, 0x1F, 0x1F, 0x0B, 0x1B,
}
charCharacter4[ = 0x18;
}
{ , 0x0E, 0x04,
unsigned 8] 0x01, 0x03, 0x05, 0x09, 0x09 0x04;
charCharacter5[ = , , 0x11, 0x0E, };
{ 0x00; 0x04, 0x00, 0x00
unsigned 8] 0x0A , 0x0A , 0x1F , 0x11 , 0x11
charCharacter6[ = LCD_Init();
{
unsigned 8] 0x00, 0x00, 0x0A , 0x00 , 0x04
charCharacter7[ = LCD_Custom_Char(
{ LCD_Custom_Char(
unsigned 8] 0x00, 0x0A , 0x1F , 0x1F, 0x0E, LCD_Custom_Char(
charCharacter8[ = LCD_Custom_Char(
{ LCD_Custom_Char(
LCD_Custom_Char(
LCD_Custom_Char(
LCD_Custom_Char(
35
{
LCD_Char(i); /* char at 'i'th position will display on lcd */
LCD_Char(' '); /* space between each custom char. */
}
while(1);
}
6. DC motor-
A DC motor consists of a stator, an armature, a rotor and a
commutator with brushes. Opposite polarity between the two
magnetic fields inside the motor cause it to turn. DC motors are
the simplest type of motor and are used in household appliances,
such as electric razors, and in electric windows in cars.
Motor driver-
Motor drivers acts as an interface between the motors and the control circuits. Motor
require high amount of current whereas the controller circuit works on low current signals.
So the function of motor drivers is to take a low-current control signal and then turn it into a
higher-current signal that can drive a motor
36
Sample Program-
Here, we are going to interface DC motor with AVR ATmega16 microcontroller. In which we
will control the DC motor speed by using POT connected to ADC of ATmega16 and direction
by using a switch.
We are going to use L293D motor driver IC to control DC motor movement in both directions.
It has in-built H-bridge motor drive.
37
{ ADMUX = 0x40 | (channel & 0x07);/* set input
DDRA = 0x00; channel to read */
ADCSRA = 0x87; /* Start ADC conversion */
ADMUX = 0x40; while (!(ADCSRA & (1<<ADIF))); /* Wait until end of
} conversion */
/* Clear interrupt flag */
{ /* Wait a little bit */
/* Return ADC word */
ADCSRA |= (1<<ADSC);
ADCSRA |= (1<<ADIF);
_delay_ms(1);
return ADCW; /* Toggle Direction */
}
/* Software de-bouncing control delay */
ISR(INT0_vect)
{
Direction = ~Direction;
_delay_ms(50);
}
{
0xFF/* Make PORTC as ; output Port */
DDRD &= ~(1<<PD2); /* DDRC = Make INT0 pin as Input
*/
DDRB |= (1<<PB3); /* Make OC0 pin as Output */
GICR = (1<<INT0); /* Enable INT0*/
MCUCR = ((1<<ISC00)|(1<<ISC01));/* Trigger INT0 on Rising Edge triggered
*/ sei(); /* Enable Global Interrupt */ ADC_Init(); /*
Initialize ADC */
TCNT0 = 0; /* Set timer0 count zero */
TCCR0 = (1<<WGM00)|(1<<WGM01)|(1<<COM01)|(1<<CS00)|(1<<CS01);/* Set Fast
PWM with Fosc/64 Timer0 clock */
while(1)
{
if (Direction !=0) /* Rotate DC motor Clockwise */
PORTC = 1;
else /* Else rotate DC motor Anticlockwise */
PORTC = 2;
OCR0 = (ADC_Read(0)/4); /* Read ADC and map it into 0-255 to write in OCR0 register */
}
}
38
7. Description of Microcontroller development board –
Atmega32 Microcontroller-
ATMEGA32 is easy to program AVR controller. With appreciable program memory it can satisfy
most EMBEDDED SYSTEMS. With various sleep modes it can work on MOBILE EMBEDDED
SYSTEMS. Along with 32 programmable Input/Output pins, it can interface many peripherals
easily. With Watchdog timer to reset under error it can be used on systems with no human
interference. With so many features with each appreciating other we can implement
ATMEGA32 in many control systems.
39
8. 16 Mhz Crystal oscillator-
This is like a heart for MCU. It provides a beat that makes the MCU take steps. In AVR series
of MCU each clock pulse executes one instruction (some instruction needs more than one
clock cycle to execute) for accurate timing in your application you need a crystal oscillator.
It provides a clean, voltage and temperature independent clock source. Generally, you can
use crystals from 1 MHz to 16 MHz on most AVRs as required for your project. Actually, the
AVR has an internal oscillator also !!! that means this can be omitted. But one limitation is
there the internal oscillator provides maximum frequency of 1 MHz if that’s enough for you,
then its ok else you have to go for an external crystal of say 12Mhz or 16 MHz
9. Capacitor- If the input voltage drops, then a decoupling capacitor will be able to provide
enough power to an IC to keep the voltage stable. If the voltage increases, then a
decoupling capacitor will be able to absorb the excess energy trying to flow through to the
IC, which again keeps the voltage stable.
40
10.Resister- Pull-up resistors are resistors used in logic circuits to ensure a well-defined logical
level at a pin under all conditions. ... It is neither in a high or low logic state, and a
microcontroller might unpredictably interpret the input value as either a logical high or
logical low.
11.LED light-
Commonly, used LEDs will have voltage drop of 1.7v and current of 10mA to glow at full
intensity. This is applied through the output pin of the micro controller.
12.Variable Resister- variable resistor, also known as a potentiometer, or pot for short to the
Analog/Digital converter (ADC) input of a microcontroller to create a volume control like
input device. A voltage divider is simply two resistors in series with the free ends
connected to power and ground.
41
13.ISP Connector-
For flexibility you should have a nice connector for is so that you can connected/disconnect
a programmer easily for programming. The MCU has 3 PINs for the downloading a program
in its flash namely • MOSI – Master Out Slave In • MISO – Master In Slave Out • SCK – Serial
Clock That’s for date transfer and you also need to connect RESET PIN of MCU to the ISP
Connector so that programmer can put it in programming mode. One more pin should be
there that is the common or ground of the two system. So, all you need is a 5 PIN connector
for programming. However, our AVR programmer has one additional PIN that is not
connected to anything so you need a 6 PIN connector in your target system.
42
Circuit diagram of board-
43
ORIGINAL BOARD AFTER DEVELOPMENT –
44
REFERENCES –
1. https://blog.podkalicki.com/mbavr-4-minimalist-development-board-for-
atmega16atmega32/
2. http://www.electronicwings.com/
3. http://www.electrosome.com/
4. http://www.circuitdigest.com/
THANK YOU.
45