0% found this document useful (0 votes)
20 views11 pages

LAB1

The document outlines a laboratory work focused on AVR microcontrollers, specifically aiming to improve programming skills and understanding of I/O systems. It provides an overview of AVR architecture, including components like CPU, ROM, RAM, and EEPROM, as well as practical exercises involving GPIO port operations and Morse code signal generation. The document concludes with instructions for validating the code using Proteus simulation software.
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)
20 views11 pages

LAB1

The document outlines a laboratory work focused on AVR microcontrollers, specifically aiming to improve programming skills and understanding of I/O systems. It provides an overview of AVR architecture, including components like CPU, ROM, RAM, and EEPROM, as well as practical exercises involving GPIO port operations and Morse code signal generation. The document concludes with instructions for validating the code using Proteus simulation software.
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/ 11

Laboratory work №1

Introduction to AVR microcontrollers

AIM

• Improving skills on microcontroller programming


• Practicing work with I/O systems,
• studying <util/delay.h> library

AVR Microcontrollers

Microcontroller can be termed as a single on chip computer which includes number of


peripherals like RAM, EEPROM, Timers etc., required to perform some predefined task.
There are number of popular families of microcontrollers which are used in different
applications as per their capability and feasibility to perform the desired task, most common
of these are 8051, AVR and PIC microcontrollers. Importance of AVR is their capability to
work fast, it means they execute most of the instructions in single execution cycle. AVRs are
about 4 times faster than PICs, they consume less power and can be operated in different power
saving modes. AVR is an 8-bit microcontroller belonging to the family of Reduced Instruction
Set Computer (RISC). In RISC architecture the instruction set of the computer are not only
fewer in number but also simpler and faster in operation. The other type of categorization is
CISC (Complex Instruction Set Computers). We will explore more on this when we will learn
about the architecture of AVR microcontrollers in following labs.

Let’s see what all this means. What is 8-bit? This means that the microcontroller is
capable of transmitting and receiving 8-bit data. The input/output registers available are of 8-
bits. The AVR family controllers have register based architecture which means that both the
operands for an operation are stored in a register and the result of the operation is also stored
in a register. Following figure shows a simple example performing OR operation between two
input registers and storing the value in Output Register.
The CPU takes values from two input registers INPUT-1 and INPUT-2, performs the
logical operation and stores the value into the OUTPUT register. All this happens in 1
execution cycle.

The most commonly used AVR microcontrollers are Atmega 8 and Atmega 32, but
they do not have a lot disticntions with other type of mega controllers, they only differ in terms
of their memory size and cost. As an example, let’s consider the architecture of Atmega 16.
Following figure shows the architecture of Atmega16 that is based on Harvard Architecture
and comes with separate buses and memories. Instructions are stored in the program memory.
Since AVR can perform single cycle execution, it means that AVR can execute 1 million
instructions per second if cycle frequency is 1MHz. The higher is the operating frequency of
the controller, the higher will be its processing speed. We need to optimize the power
consumption with processing speed and hence need to select the operating frequency
accordingly.
CPU

CPU is like a brain of the controller which helps in executing a number of instructions.
It can handle interrupts, perform calculations and control peripherals with the help of registers.
Atmega16 comes with two buses called instruction bus and data bus.

The CPU reads the instructions in the instruction bus while data bus is used to read or
write the corresponding data. The CPU mainly consists of the program counter, general
purpose registers, stack pointer, instruction register and an instruction decoder.

ROM

The controller program is stored in ROM, also known as non-volatile programmable


flash memory. The flash memory comes with a resolution of at least 10,000 write/erase cycles.
Flash memory is mainly divided into two parts known as Application flash section and booth
flash section.

Program of the controller is stored in the applications flash section. While booth flash
section is optimized to work directly when the controller is powered up.

RAM

The SRAM (static random access memory) is used for storing information temporarily
and comes with 8-bit registers. This is just like a regular computer RAM which is used to
supply data through the runtime.

EEPROM

The EEPROM (Electronically Erasable Read Only Memory) is non-volatile memory


used as a long time storage. It has no involvement in executing the main program. It is used
for storing the configuration of the system and device parameters which continues to work in
the reset of the application processor.

EEPROM comes with a limited write cycle up to 100,000 while read cycles are
unlimited. While using EEPROM, write minimum instructions as per requirement, so you can
get benefit from this memory for a longer time.

Interrupt

The interrupt is used for an emergency which puts the main function on hold and
executes the necessary instructions at that time. Once the interrupt is called and executed the
code switches back to the main program.
Analog and Digital I/O Modules

Digital I/O modules are used to set a digital communication between the controller and
external devices. While analog I/O modules are used for transferring analog information.
Analog comparators and ADC fall under the category of analog I/O modules.

Timer/Counter

Timers are used for calculating the internal signal within the controller. Atmega16
comes with two 8-bit timers and one 16-bit timer. All these timers work as a counter when
they are optimized for external signals.

Watchdog Timer

The watchdog timer is a remarkable addition in this controller which is used to generate
the interrupt and reset the timer. It comes with 128kHz distinct CLK source.

Serial Communication

Atmega16 comes with USART and SPI units that are used for developing serial
communication with the external devices.

Following figure shows the pin diagram of this AVR microcontroller Atmega16.
PROGRESS OF WORK
1) Start the atmel studio

2) Create a new GCC C executable project


3) Select the device (in our case it’s ATmega2561)

Port Operation Registers

The following registers are related to the various port operations that we can perform with the
GPIO pins.

• DDRx – Data Direction Register - initializes the port.


• PORTx – Pin Output Register - determines whether the output should be HIGH or LOW
of the output pins.
• PINx – Pin Input Register - gets the reading from the input pins of the MCU

where x = GPIO port name (A, B, C or D)

DDRC = 0b10110001; // 1 stands for output and 0 stands for input.

PORTC = 0b10010001;

The port C is initialized using the DDRx register. The highlighted bits correspond to the
output pins. Now, just concentrate on the highlighted bits only. Since they are output pins,
wherever I state ‘1’ in PORTC, that pin goes HIGH (1), giving an output voltage of VCC at
that pin.
In order to display a Morse code symbol, 2 functions are needed: short and long signals:
void dot(void)
{
delay(10000);
PORTB=0b00000000; // 1
delay(10000);
PORTB=0b00000000;
}
void dashe(void)
{
//write for dashe function
}

The dot function makes a delay, turns on the LED, takes another delay and turns off the LED.
The dashe function works in a similar way, but makes the delay three times longer than at dot.
We also write the pause function — a very long delay to see the difference between Morse
symbols.
void pause(void)
{
delay(60000);
delay(60000);
}

Delay of 120,000 is divided into two by 60,000 , due to constraints such as time uint16_t.
The time parameter has uint16_t, it takes 2 bytes and allows to store a number from 0 to
65,535.

Operation of the program is as follows:

The 0th output of port B opens to the output; Turns off LED0; In an endless loop, sequentially
Morse code, the first letters of the name, call the function dot and dashe; Before repeating the
Morse signal sequence is a pause for about one second.

For example:

int main(void)
{
DDRB=0b00000001;
PORTB=0b00000000;
while(1)
{
//FIRST NAME

// letter A-..
dot();
dashe();
pause();
//letter N -..
dashe();
dot();
pause();
dashe();
dot();
pause();
}

return 0; }
After successful compilation of .hex file, we are opening Proteus. Choosing ATmega2561
and LED. We sew in charge of our program to validate our code and transmit Morse code as
a message to our name.

Рic 1. Choosing LED

Рic 2. Board with LED


Рic 3. Adding into Program File our .hex file

Рic 4. Compile circuit


CONCLUSION:

Your conclusion ....

You might also like