Professional Documents
Culture Documents
AVR_LAB_1
Introduction:
This experiment will teach you how to write, compile, and trace a simple
program in Atmel Studio
Download the newest version of Atmel Studio from the Atmel website:
http://www.atmel.com/tools/atmelstudio.aspx
a. Choose Assembler.
c. Choose the path where you like to save the project by clicking on the
Browse button.
d. Press OK.
c. Select OK.
Department of Electronics & Communication Engineering
Building
Press F7 to assemble, or choose Build Solution from the Build menu. The
results of assembling the program are shown in the Output window.
Debugging
5. Now a yellow cursor is on the first line of the main program and the
IDE is ready to debug the program.
Department of Electronics & Communication Engineering
6. To execute the instructions line by line press F10 or click on the Step
over icon.
7. To monitor the peripherals, including the I/O ports, click on the Debug
menu, choose Windows and then I/O view.
8. The I/O view tab appears on the right hand side which shows the
peripherals of the microcontroller, including the I/O ports. Select PORTA.
The values of the related registers (PINA, DDRA, and PORTA) will be
shown below.
Department of Electronics & Communication Engineering
9. Press F10 (Step Over) a few times and see the PORTA register changes
in the I/O View.
Department of Electronics & Communication Engineering
AVR_LAB_2
THEORETICAL BACKGROUND:
The following is a brief explanation of the flag bits of the status register.
The impact of instructions on this register is then discussed.
This flag is set whenever the result of a signed number operation is too
large, causing the high-order bit to overflow into the sign bit. In general,
the carry flag is used to detect errors in unsigned arithmetic operations
while the overflow flag is used to detect errors in signed arithmetic
operations . The V and N flag bits are used for signed number arithmetic
operations
ACTIVITY 1
Write and assemble a program to add the following data and then use
the simulator to examine the C, H and Z flags after the execution of
each addition.
$92, $23, $66, $87, $F5
ACTIVITY 2
Write and assemble the following program. Use the simulator to single-
step and examine the flags and register content after the execution of
each instruction.
Department of Electronics & Communication Engineering
ACTIVITY 3
Write and assemble a program to load a value into each location of R20
– R23. Use the COM instruction to complement the value in each
register. Use the simulator to single-step and examine the flags and
register content after the execution of each instruction.
Find the value of the C flag after the execution of the following codes.
AVR_LAB_3
ACTIVITY 1
Write and assemble the following program to add two array and store the
result in other array
include file of atmega32
R16← 0x00
R17← 0x00
R26← 0x60
R27← 0x00
R20← 0x0A
R21← 0x00
load R17 from address store in register X and increment X
R16=R16 +R17
jump (branch) if carry flag if clear (not set) to XYZ
increment R21
decrement R20
jump (branch) if zero flag is clear (not set) to BACK
R18 = R16
jump toHERE
ACTIVITY 2
Write and assemble the following program to add two array with carry
include file of atmega32
R16← 0x00
R17← 0x00
R26← 0x60
Department of Electronics & Communication Engineering
R27← 0x00
R28← 0x73
R29← 0x00
R30← 0x86
R31← 0x00
R20← 0x0A
R21← 0x00
load R17 from address store in register X and increment X
load R16 from address store in register Y and increment Y
R16=R16 +R17
increment R30
store R16 to address store in register Z and increment Z
jump (branch) if carry flag if clear (not set) to XYZ
increment R21
decrement R30
decrement R30
store R21 to address store in register Z and increment Z
increment R30
increment R30
decrement R20
jump (branch) if zero flag is clear (not set) to BACK
R22 = R16
jump to HERE
Department of Electronics & Communication Engineering
AVR_LAB_4
ACTIVITY 1
Write and assemble the following program to toggle all bits of Port A
include file of atmega32
R20← 0x00
no operation
R16 = PINA
complement R16
jump to HERE
ACTIVITY 2
Write and assemble the following program such that when PB3 becomes
high write the value $45 to portc and also send high to low pulse to PD3
include file of atmega32
clear 3rd bit of port B as input pin
R16← $ff
write 0xff in DDRC register
set 3rd bit of port D as output pin
skip if bit 2 of port B is set
Department of Electronics & Communication Engineering
jump to AGAIN
R16← $45
write 45 in port A register
set 3rd bit of port D high
rd
clear 3 bit of port D high
jump to HERE
ACTIVITY 3
Write and assemble the following program such that a switch is connected
to pin PB2, check the status of switch and perform the following:
nd
clear 2 bit of port B as input pin
R16← $ff
jump to OVER
R16← ‘Y’
jump to AGAIN
Department of Electronics & Communication Engineering
R16← ‘N’
jump to AGAIN
Department of Electronics & Communication Engineering
AVR_LAB_5
/* connections
D0 - D7 to PB0 - PB7
#include <avr/io.h>
#include <util/delay.h>
void lcd_init()
LCD_DDDR = 0xFF;
LCD_CDDR = 0xFF;
_delay_us(2000); // wait
while(*p)
lcd_data(*p++);
int main(void)
lcd_init();
_delay_ms(200);
}
Department of Electronics & Communication Engineering
Department of Electronics & Communication Engineering
AVR_LAB_6
PROGRAM: -
#include <avr/io.h>
#include <util/delay.h>
delay_ms(d);
unsigned char keypad [4] [4] ={ “0”, “1”, “2”, “3”, “4’,
int main(void)
DDRD=0XFF;
KEY_DDR = 0XF0;
KEY_PRT = 0xFF;
while(1)
do
do
do
while(1)
if (colloc == 0x0E)
PORTD = (keypad[rowloc][0]);
PORTD = (keypad[rowloc][1]);
Department of Electronics & Communication Engineering
PORTD = (keypad[rowloc][2]);
else
PORTD = (keypad[rowloc][3]);
Return 0;