AVR Lab Manual for Students
AVR Lab Manual for Students
000000000000000000
2|Page
Index
Sl Name of Experiment Date Remarks
Vision and Mission statement
1 Safety Procedures
2 Handling electrostatic discharge (ESD)
3 Familiarization of AVR studio 6
4 Study of ports
6 Software delay
7 Bit manipulation
9 16 x 2 LCD Display
3|Page
VISION AND MISSION
Vision
Excel as a centre of skill education moulding professionals who sincerely strive for the
betterment of society.
Mission
• To impart state of the art knowledge and skill to the graduate and moulding them to
be competent, committed and responsible for the well being of society.
• To apply technology in the traditional skills, thereby enhancing the living standard
of the community
Vision
Mission
• To impart state of the art knowledge, skill and attitude to the students and
contributing to their sustainable development.
4|Page
Exp No. 1 Date: D D - M M - Y Y
PEO2: Acquire knowledge and competency in the domain to develop innovative, cost
effective and socially acceptable solutions to engineering problems in a multi disciplinary
work environment.
PEO3: Develop strong fundamental knowledge that prepares them for professional
careers/higher studies with attitude for lifelong learning.
PEO4: Instill the attitude to be sensitive to ethical, societal and environmental issues while
pursuing their professional duties.
PEO5: Possess leadership qualities and be effective communicator to work efficiently with
diverse teams, promote and practice appropriate ethical practices.
PO3: Experiments and practice: Able to plan and perform experiments and practices
and to solve engineering problems.
PO4: Engineering Tools: Apply appropriate technologies and tools with proper
understanding of their limitations.
PO5: The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
PO7: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
5|Page
PO8: Individual and team work: Function effectively as an individual and as a member
or leader in diverse multidisciplinary teams.
PO10: Lifelong learning: Recognize the need for, and have the preparation and ability to
engage in independent and lifelong learning in the context of technological changes.
6|Page
Exp No. 2 Date: D D - M M - Y Y
SAFETY PROCEDURES
Problem Statement:
The safety instructions are presented to the attention of the students as a mean of
preventing accidents while performing experiments and activities in the communication
lab of the department .The purpose is to draw attention to the risks involved in lab
activities to prevent human suffering and damage to equipment.
Working in the lab is not allowed without following electricity precautions displayed.
Laboratory in charge is responsible for the arrangements of your lab activities; Listen
carefully to his/her instructions and follow them.
Do not do any action that may harm people or equipments in the lab.
At the end and beginning of laboratory, follow 5S procedures and leave the work table
clean and tidy.
Electrical Safety:
Consult Electrical Engineering section available in the campus for electrical safety
queries.
The lab equipment is powered from electrical sockets installed on the tables. Do not use
equipment that is powered from a damaged socket.
Do not use equipment that is powered from flexible cable with damaged insulation or if it’s
plug is not assembled properly.
7|Page
Do not repair or disassemble electrical equipment including replacement of fuses installed
in the equipment.
Do not open the main fuse box, unless it is an emergency and you need to switch off main
circuit breaker.
Emergency Switches:
The laboratory has circuit breakers, which is located in the main panel. Identify the place.
In an emergency condition, switch off circuit breakers immediately.
Result
Familiarization of safety precautions performed.
8|Page
Exp No. 3 Date: D D - M M - Y Y
Problem Statement:
Theory
1. Make sure you have a reliable ground point available near the table.
2. Do not wear clothing which generates static electric charges every time you move.
5. Keep all ESD sensitive components and spares in anti-static envelopes for
storage.
6. Be sure to turn off the power and remove the power plug from all equipment
before working repairing or assembling.
Result
Familiarization of ESD protection procedures performed.
Problem Statement : To familiarize AVR Studio6 for ASM and C coding of ATMEGA 32
and programming software (extreme burner)
Theory
Result
10 | P a g e
Exp No. 5 Date: D D - M M - Y Y
STUDY OF PORTS
Problem Statement : To send one byte of data on to PORTB of ATMEGA 32 there by
understanding the operation of PORT as output.
Circuit Diagram
Theory
ATMEGA ports are 8 bit wide. Each port has 3 eight bit registers associated. Each bit in
these registers configures pins of associated port. Bit 0 of these registers is associated
with Pin 0 of the port, Bit1 of these registers is associated with Pin1 and so on.
– DDRx register
– PORTx register
– PINx register
11 | P a g e
DDRx register
DDRx (Data Direction Register) configures data direction of the port pins. Which, writing 0
to a bit in DDRx makes corresponding port pin as input, while writing 1 to a bit in DDRx
makes the corresponding port pin as output.
example:
Algorithm
Code
12 | P a g e
Result
One byte of data moved to PORTB and output verified on LED connected to PORTB.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
13 | P a g e
Exp No. 6 Date: D D - M M - Y Y
Circuit Diagram
Theory
ATMEGA ports are 8 bit wide. Each port has 3 eight bit registers associated. Each bit in
these registers configures pins of associated port. Bit 0 of these registers is associated
with Pin 0 of the port, Bit1 of these registers is associated with Pin1 and so on.
– DDRx register
– PORTx register
– PINx register
14 | P a g e
DDRx register
DDRx (Data Direction Register) configures data direction of the port pins. Which, writing 0
to a bit in DDRx makes corresponding port pin as input, while writing 1 to a bit in DDRx
makes the corresponding port pin as output.
example:
Algorithm
/*----------------------------------------------------------------
15 | P a g e
Result
One byte of data moved to PORTB and output verified on LED connected to PORTB.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
16 | P a g e
Exp No. 7 Date: D D - M M - Y Y
SOFTWARE DELAY
Problem Statement : To blink LEDs connected to PORTB at 1 sec interval while buzzer
and relay connected to PORTC beeps.
Algorithm
1. Ensure proper sitting of fuse bits to enable PORTC
2. Set PORTB as output by suitably initializing DDRB register
3. Set PORTC as input by suitably initializing DDRC register
4. Set PORTB and PORTC high
5. Invert PORTB
6. Invert PORTC
Set value of fuse bit as Fuse high = C9 and fuse low = E1 for enabling PORTC and clock at
internal RC 1 MHz
Code
/*----------------------------------------------------------------
17 | P a g e
Result
One byte of data moved to PORTB and output verified on LED connected to POERTB.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
18 | P a g e
Exp No. 8 Date: D D - M M - Y Y
BIT MANIPULATION
Problem Statement : To blink LEDs connected to PORTB and buzzer connected to PC5
at 1 sec interval relay connected to PC4 is on using logical operations.
Algorithm
1. Ensure proper sitting of fuse bits to enable PORTC
2. Set PORTB as output by suitably initializing DDRB register
3. Set PORTC as input by suitably initializing DDRC register
4. Set PORTB and PORTC high
5. Invert PORTB
6. Invert PORTC
Set value of fuse bit as Fuse high = C9 and fuse low = E1 for enabling PORTC and clock at
internal RC 1 MHz
19 | P a g e
Code
/*----------------------------------------------------------------
This program blink LEDs connected to PORTB and buzzer connected to PC5 at 1 sec
interval relay connected to PC4 is on using logical operations.
The program assumes internal RC oscillator at 1Mhz
Author : xxxxxxxxxxxxxx Date : [Link].20xx
---------------------------------------------------------------------*/
Result
Performed blinking of LEDs connected to PORTB and buzzer connected to PC5 at 1 sec
interval relay connected to PC4 is on using logical operations.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
20 | P a g e
Exp No. 9 Date: D D - M M - Y Y
Algorithm
1. Set PORTB as output by suitably initializing DDRB register
2. Set PORTB and PORTC high
3. Use for loop to increment 10 times and send value to PORTB
4. Go to indefinite loop
Code
/*----------------------------------------------------------------
21 | P a g e
Result
Performed blinking of LEDs connected to PORTB and buzzer connected to PC5 at 1 sec
interval relay connected to PC4 is on using logical operations.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
22 | P a g e
Exp No. 10 Date: D D - M M - Y Y
16 x 2 LCD Display
Problem Statement : Given lcd.h, write a program in C to display your name in first row
and class number in second row of 16 x 2 LCD display in 8 bit mode.
Information given
#define D0 eS_PORTB0
#define D1 eS_PORTB1
#define D2 eS_PORTB2
#define D3 eS_PORTB3
#define D4 eS_PORTB4
#define D5 eS_PORTB5
#define D6 eS_PORTB6
#define D7 eS_PORTB7
#define RS eS_PORTD4
#define EN eS_PORTD6
Theory
23 | P a g e
LCD display is an inevitable part in almost all embedded projects. It consists of 16 rows
and 2 columns of 5×7 or 5×8 LCD dot matrices. They are available in a 16 pin package
with back light, contrast adjustment. The pin numbers, their name and corresponding
functions are shown above.
LCD Initialization.
The steps that have to initializing the LCD display is given below.
The steps for sending data to the LCD module are given below. Make R/W low.
• Make RS=0 if data byte is a command and make RS=1 if the data byte is a data to
be displayed.
• Place data byte on the data register.
• Pulse E from high to low.
• Repeat above steps for sending another data.
24 | P a g e
Algorithm
Code
/*----------------------------------------------------------------
25 | P a g e
Result
Values 0x00 0xFF displayed on PORTB at 1sec delay
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
26 | P a g e
Exp No. 11 Date: D D - M M - Y Y
Theory
Seven segment displays are available in common anode and common cathode
configuration. They are usually used in multiplexed configuration. One segment from each
of the digits is connected to a common line which is controlled by a single output pin from
the microcontroller. One digit is activated at a time in this method.
Algorithm
1. Initialize ports
2. Send code corresponding to zero to segements
3. Select digit by making digit select low
4. Delay for 10 msec
5. Disable segments
6. Send value corresponding to digit 1
7. Repeat steps 2 to 5 for all four digits
8. Go to step2
27 | P a g e
Code
/*----------------------------------------------------------------
| | A | | | | | |
E | | | | | | | |
_____ ______ _____ _____
D | | B | | | | | |
| | | | | | | |
_____ ______ ______ ______
C
28 | P a g e
Result
Values “0123” displayed on common cathode display
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
29 | P a g e
Exp No. 12 Date: D D - M M - Y Y
ADC Interfacing
Problem Statement : To read temperature sensor connected to AD0 pin of ATMEGA32
at 10 bit resolution and transfer the content in ASCII format to PORTB. Bits should be
sent at an interval of 2 seconds.
Information provided
Theory
ADC Prescaler: The ADC needs a clock pulse to do its conversion. This clock generated
by system clock by dividing it to get smaller frequency. At higher frequency the conversion
is fast while a lower frequency the conversion is more accurate. The prescaler is provided
to produces acceptable frequency for ADC from any system clock frequency. System
clock can be divided by 2,4,16,32,64,128 by setting the Prescaler.
ADC Channels: The ADC in ATmega32 has 8 channels .We can connect up to 8 different
sensors and get their values separately.
30 | P a g e
Algorithm
1. Initialize ports
2. Initialize ADC
3. Read ADC
4. Convert to ascii string
5. Send to PORTB at 2 sec
6. Repeat 3 times from 4
7. Call 3 sec delay
8. Clear led
9. Go to step3
31 | P a g e
Code
32 | P a g e
Result
Values of temperature sensor displayed as string to PORTB
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
33 | P a g e
Exp No. 13 Date: D D - M M - Y Y
External Interrupt
Problem Statement : To toggles BUZZER connected to PC5 when interrupted with INT0
and relay connected to PC4 when interrupted with INT1.
Information provided
Theory
34 | P a g e
The External Interrupts are triggered by the INT0, INT1, and INT2 pins. Observe that, if
enabled, the interrupts will trigger even if the INT0..2 pins are configured as outputs. The
external interrupts can be triggered by a falling or rising edge or a low level (INT2 is only
an edge triggered interrupt). This is set up as indicated in the specification for the MCU
Control Register – MCUCR – and MCU Control and Status Register – MCUCSR. When
the external interrupt is enabled and is configured as level triggered (only INT0/INT1), the
interrupt will trigger as long as the pin is held low
Algorithm
1. Initialize ports
2. Initialize interrupt
3. Indefinite loop
ISR INT0
Toggle relay
ISR INT1
Toggle buzzer
CODE
35 | P a g e
Result
Buzzer connected to PC5 when interrupted with INT0 and relay connected to PC4 when
interrupted with INT1.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
36 | P a g e
Exp No. 14 Date: D D - M M - Y Y
Theory
Theory:
A stepper motor is a type of DC motor that rotates in steps. When digital sequence is
applied to it, the motor rotates in steps and the speed of rotation depends on the rate at
which the sequences are applied and the direction of rotation is dependent on the
pattern of pulses that is followed.
37 | P a g e
Step A B C D
1 1 0 0 1
2 1 1 0 0
3 0 1 1 0
4 0 0 1 1
In the diagram below, the center is the rotor which is surrounded by the stator
Algorithm
1. Initialize ports
2. Check for key press
3. If forward go to 6
4. If reverse go to 7
5. Wait for key press
6. Send forward sequence with delay
7. Send reverse sequence with delay
8. Goto 2
Code
/* Program to interface stepper motor to port pins PC3, PC2, PC1 and
PC0. To control forward and reverse motion by switches connected to
PD0 and PD1 respectively.
Author: XXXXXXXXXXXXXX Created: XX/XX/20XX
---------------------------------------------------------------------------------
------*/
38 | P a g e
Result
Stepper motor interfaced with forward and reverse rotation.
.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
39 | P a g e
Exp No. 15 Date: D D - M M - Y Y
Study of Timer
Problem Statement : To generate square wave at PORTB using timer in interrupt mode.
Theory
Timers generally have a resolution of 8 or 16 Bits. An 8 bit timer is 8 bit wide so capable of holding
value within 0-255. But these register increment or decrement automatically at a predefined rate
based on the timer clock. This operation does not need CPU’s intervention. That is its counts up to
its maximum value (255 for 8 BIT timers) and rolled back to 0. In this situation timer can issue an
interrupt and you must write an Interrupt Service Routine (ISR) to handle the event.
The ATmega32 has three different timers of which the simplest is TIMER0. Its resolution is
8 BIT i.e. it can count from 0 to 255. The Prescaler is a mechanism for generating clock for
timer by the CPU clock. As you know that CPU has a clock source such as a external crystal
of internal oscillator. Normally these have the frequency like 1 MHz,8 MHz, 12 MHz or
16MHz(MAX). The Prescaler is used to divide this clock frequency and produce a clock for
TIMER.
Algorithm
1. Initialize ports.
2. Initialize timer interrupt.
3. Indefinite loop.
ISR Timer 0
1. Increment counter.
2. If counter value greater than preset toggle PORTB.
3. Else increment count.
Code
40 | P a g e
Result
Square wave generated using Timer 0.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
41 | P a g e
Exp No. 16 Date: D D - M M - Y Y
UART
Problem Statement : Write a program in C to sent ASCII value 'A' to USART at 9600
baud rate. Any value received from USART is reverted back instead of 'A' and displayed
on PORTB with external crystal oscillator at 11.0592 Mhz
Theory
Algorithm
1. The UCSRB register is loaded with the value 08H, enabling the USART trans-
mitter.
The transmitter will override normal port operation for the TxD pin when
enabled.
2. The UCSRC register is loaded with the value 06H, indicating asynchronous
mode with 8-bit data frame, no parity, and one stop bit.
3. The UBRR is loaded with one of the values in Table 11-4 (if Fosc = 8 MHz)
to set the baud rate for serial data transfer.
4. The character byte to be transmitted serially is written into the UDR register.
5. Monitor the UDRE bit of the UCSRA register to make sure UDR is ready for
the next byte.
6. To transmit the next character, go to Step 4.
42 | P a g e
Code
/* This program sent ASCII value 'A' to USART at 9600 baud rate. Tha value is also
send to PORTB
Any value received from USARt is reverted bacl instead of 'A' and displayed on
PORTB with internal RC oscillator at 1Mhz
Author: XXXXXXXXXXXXXX Created: XX/XX/20XX Ver: 1.0 Modifications made: NIL
-------------------------------------------------------------------------------------------*/
43 | P a g e
Result
UART programmed at 9600 baud rate to send and receive values.
44 | P a g e
Exp No. 17 Date: D D - M M - Y Y
Code
45 | P a g e
Result
Project implemented to display value of temperature sensor on LCD display and control
buzzer accordingly.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
46 | P a g e
Exp No. 18 Date: D D - M M - Y Y
Code
/* this project Control relay and buzzer connected to PORTC using Bluetooth
* temp_disp.c
Author: XXXXXXXXXXXXXX Created: XX/XX/20XX
---------------------------------------------------------------------------------
------*/
47 | P a g e
Result
Bluetooth controller implemented.
Signature of Lab in
For Office use only charge Remarks
Readiness to do experiment
Completion of Experiment
48 | P a g e
Exp No. Date: D D - M M - Y Y
49 | P a g e
Exp No. Date: D D - M M - Y Y
50 | P a g e
Exp No. Date: D D - M M - Y Y
51 | P a g e
Exp No. Date: D D - M M - Y Y
52 | P a g e
GOVERNMENT POLYTECHNIC COLLEGE, PERUMBAVOOR
Koovappady P O, Perumbavoor, Ernakulam – 683544
[Link]
53 | P a g e