0% found this document useful (0 votes)
471 views

AVR - ATMEGA32 - Project Report

The document is a project report submitted by 4 students for their Bachelor of Engineering degree. It describes the development of an AVR development board using an Atmega32 microcontroller. The board allows users to program the microcontroller using a USBasp programmer and run basic modules like motors, 7-segment displays, and an LCD. The goal is to create a minimal development board for learning and prototyping with the AVR microcontroller.

Uploaded by

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

AVR - ATMEGA32 - Project Report

The document is a project report submitted by 4 students for their Bachelor of Engineering degree. It describes the development of an AVR development board using an Atmega32 microcontroller. The board allows users to program the microcontroller using a USBasp programmer and run basic modules like motors, 7-segment displays, and an LCD. The goal is to create a minimal development board for learning and prototyping with the AVR microcontroller.

Uploaded by

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

AVR Development Board Using AVR

Atmega32

A PROJECT REPORT

submitted by

Rounak Likhar (16T8136)


Varun Mohane (16T8148)
Amrit Singh Patel(17T8181)
Shivam Choudhary(17T8185)

in partial fulfilment for the award

of

Bachelor of Engineering

degree in

Electronics and Telecommunication

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)

Amrit Singh Patel(17T8181)

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.

Internal Examiner External Examiner

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

3. ANALYSIS AND DESIGN


i. BRIEF INTRODUCTION
a. Product features
b. User characteristics
c. Operating requirements
ii. WORKING

4. DESCRIPTION OF COMPONENTS AND INTERFACING

PROGRAMS

5. CIRCUIT DIAGRAM OF BOARD

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.

1.3 Aim & Objective


In order to learn any MCU like AVR we need an AVR MCU that has all the basic connections
like power supply, crystal oscillator, proper reset signal and an ISP connector for uploading
a program. All these things are required for any project you will make. A development board
is a circuit board that contains all these connections and it has connectors for IO pins of MCU
so that they can be connected to any external circuit with ease. So, as you see it is like a basic
framework. Once you make a good development board and test it, you will have a solid
foundation and for your project you can concentrate on the specific requirement of that
project.

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

2.2 S/W Requirements

 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

3.1.1 Product features-


The following are the key features that are included in the system: -
1. Using USB to burn program

2. Operating motor driver

3. Demonstrating 7-segment functionality

4. Displaying LCD using programming

3.1.2 User characteristics-


• The use should be well versed with AVR microcontroller coding.
• The user must have the basic knowledge connecting hardware’s.

3.1.3 Operating requirements-


For the system to operate properly and effectively, first of all the modules should
be properly connected to the development board and also the wires. Then the code
written in Atmel Studio needs to be dumped in the Atmega32 chip before running
the program.

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

CHECKING THE CONFIGURATION OF THE SYSTEM

1. Right click on This PC->Properties

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

INSTALLING THE ATMEL STUDIO


1. Type on google “download Atmel studio”
2. Select the link of microchip.com
3. Click on the download button next to Atmel Studio 7.0 (build 1931) offline installer
Or
Take the cracked avr installer
Click on as-installer-7.0.1931-full

10
We will see the below file opened

Select all the architecture.


Click on `next ‘
Then agree to the license terms and conditions

11
Then install

Then click on `close’

Your installation is completed.

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.

DEBUGGING AND RUNNING THE PROJECT


1. On the toolbar go to Build->Build Solution
2. Go to Debug->Start debugging and break

A window appears in which select the “Selected debugger/programmer” to Simulator.

After writing code -

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

#define F_CPU 8000000UL /* Define CPU Frequency 8MHz */


#include <avr/io.h> /* Include AVR std. library file */
#include <util/delay.h> /* Include delay header file */

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

#define F_CPU 8000000UL


#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
#include <stdio.h>
#include "LCD_16x2_H_file.h"

#define degree_sysmbol 0xdf

void ADC_Init(){
DDRA = 0x00; /* Make ADC port as input */
ADCSRA = 0x87; /* Enable ADC, with freq/128 */
ADMUX = 0x40; /* Vref: Avcc, ADC channel: 0 */
}

int ADC_Read(char channel)


{
ADMUX = 0x40 | (channel & 0x07); /* set input channel to read */
ADCSRA |= (1<<ADSC); /* Start ADC conversion */
while (!(ADCSRA & (1<<ADIF))); /* Wait until end of conversion by polling ADC inte rrupt
flag */
ADCSRA |= (1<<ADIF); /* Clear interrupt flag */
_delay_ms(1); /* Wait a little bit */
return ADCW; /* Return ADC word */
}

22
int main()
{
char Temperature[10];
float celsius;

LCD_Init(); /* initialize 16x2 LCD*/


ADC_Init(); /* initialize ADC*/

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>

#define KEY_PRT PORTA


#define KEY_DDR DDRA
#define KEY_PIN PINA

unsigned char keypad[4][4] = { {'7','8','9','/'},


{'4','5','6','*'},
{'1','2','3','-'},
{' ','0','=','+'}};

unsigned char colloc, rowloc;

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 */

_delay_ms (40); /* 20 ms key debounce time */


colloc = (KEY_PIN & 0x0F);
}while(colloc == 0x0F);

/* now check for rows */


KEY_PRT = 0xEF; /* check for pressed key in 1st row
*/ asm("NOP"); colloc = (KEY_PIN & 0x0F); if(colloc
!= 0x0F)
{
rowloc = 0;
break;
}

KEY_PRT = 0xDF; /* check for pressed key in 2nd row


*/ asm("NOP"); colloc = (KEY_PIN & 0x0F);
if(colloc != 0x0F)
{
rowloc = 1;
break;
25
}

KEY_PRT = 0xBF; /* check for pressed key in 3rd row */


asm("NOP");
colloc = (KEY_PIN & 0x0F);
if(colloc != 0x0F)
{
rowloc = 2;
break;
}

KEY_PRT = 0x7F; /* check for pressed key in 4th row


*/ asm("NOP"); colloc = (KEY_PIN & 0x0F);
if(colloc != 0x0F)
{
rowloc = 3;
break;
}
}

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

#define F_CPU 8000000UL


27
#include <avr/io.h>
#include <util/delay.h>
#define LED_Direction DDRA /* define LED Direction */
#define LED_PORT PORTA /* define LED port */

{
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 */
}
}
}

5. 16X2 LCD display-


LCD (Liquid Crystal Display) is a type of flat panel display which uses liquid crystals in its
primary form of operation
A 16x2 LCD display is very basic module and is very commonly used in various devices and
circuits. A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In
this LCD each character is displayed in 5x7 pixel matrix

28
29
Sample Program-
1. To interface LCD with Microcontroller

#define F_CPU 8000000UL /* Define CPU Frequency e.g. here 8MHz */


#include <avr/io.h> /* Include AVR std. library file */
#include <util/delay.h> /* Include inbuilt defined Delay header file */

#define LCD_Data_Dir DDRB /* Define LCD data port direction */


#define LCD_Command_Dir DDRC /* Define LCD command port direction register
*/
#define LCD_Data_Port PORTB /* Define LCD data port */
#define LCD_Command_Port PORTC /* Define LCD data port */
#define RS PC0 /* Define Register Select (data/command reg.)pin */
#define RW PC1 /* Define Read/Write signal pin */
#define EN PC2 /* Define Enable signal pin */

{
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 */

LCD_Command (0x38); /* Initialization of 16X2 LCD in 8bit mode */


LCD_Command (0x0C); /* Display ON Cursor OFF */
LCD_Command (0x06); /* Auto Increment cursor */
LCD_Command (0x01); /* Clear display */
LCD_Command (0x80); /* Cursor at home position */
}

{
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 ( }

LCD_Init(); /* Initialize LCD */

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;

2. Display Custom Characters-


After storing all custom characters in CGRAM, we can display it on LCD16x2.
To display custom characters, simply provide custom character number (from 0 to 7) as a
data to LCD16x2.

#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 */

#define LCD_Data_Dir DDRB /* Define LCD data port direction */


#define LCD_Command_Dir DDRC /* Define LCD command port direction register */
#define LCD_Data_Port PORTB /* Define LCD data port */
#define LCD_Command_Port PORTC /* Define LCD data port */
#define RS PC0 /* Define Register Select signal pin */
#define RW PC1 /* Define Read/Write signal pin */
#define EN PC2 /* Define Enable signal pin */

void LCD_Command(unsigned char cmnd)


{
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(2);
}

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_Init (void) /* LCD Initialize function */


{
LCD_Command_Dir = 0xFF; /* Make LCD command port direction as o/p */
LCD_Data_Dir = 0xFF; /* Make LCD data port direction as o/p */
_delay_ms(20); /* LCD Power ON delay always >15ms */

LCD_Command (0x38); /* Initialization of 16X2 LCD in 8bit mode */


LCD_Command (0x0C); /* Display ON Cursor OFF */
LCD_Command (0x06); /* Auto Increment cursor */
LCD_Command (0x01); /* clear display */
_delay_ms(2); /* Clear display command delay> 1.63 ms */
LCD_Command (0x80); /* Cursor at home position */
}

void LCD_String *str) (char/* Send string to LCD function */


{
int i;
for(i=0;str[i]!=0;i++)
{
LCD_Char (str[i]);
}
} /* Send each
char of string till the NULL */

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 ( }

void LCD_Custom_Char (unsigned char loc, unsigned char *msg)


{
unsigned char i;
if(loc<8)
{
LCD_Command (0x40 + )); (loc*8/* Command 0x40 and onwards
forces the device to point CGRAM address */
for(i=0;i<8;i++) /* Write 8 byte for generation of 1 character */
LCD_Char(msg[i]);
}
}

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(

, Character1); 0/* Build Character1 at position 0 */


, Character2); 1/* Build Character2 at position 1 */
, Character3); 2/* Build Character3 at position 2 */
, Character4); 3/* Build Character4 at position 3 */
, Character5); 4/* Build Character5 at position 4 */
, Character6); 5/* Build Character6 at position 5 */
, Character7); 6/* Build Character6 at position 6 */
, Character8); 7/* Build Character6 at position 7 */

LCD_Command(0x80); /*cursor at home position */


LCD_String("Custom char LCD");
LCD_Command(0xc0);

for(i=0;i<8;i++) /* function will send data 1 to 8 to lcd */

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.

#define F_CPU 8000000UL /* Define CPU Frequency 8MHz */


#include <avr/io.h> /* Include AVR std. library file */
#include <avr/interrupt.h>
#include <stdio.h> /* Include std. library file */
#include <util/delay.h> /* Include Delay header file */

volatile uint8_t Direction = 0;

/* Make ADC port as input */


/* Enable ADC, with freq/128 */
/* Vref: Avcc, ADC channel: 0 */

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.

Entire process of using an ATMEGA32 goes like this:


1. List the functions to be executed by ATMEGA32
2. write the functions in IDE programs using relative language
3. After writing the desired program compile for error elimination using IDE.
4. Opt the IDE application to generate HEX file for the written program.
5. Choose the programming device (usually SPI programmer made for AVR controllers)
which establishes communication between PC and ATMEGA32
6. Run the HEX file dumping software which is related to the chosen programming
device.
7. Choose the appropriate program HEX file in the SPI or other programmer software.
8. Burn the HEX file of program in ATMEGA32 flash memory using this program.
9. Disconnect the programmer, connect the appropriate peripherals for the controller
and power the system.

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

You might also like