0% found this document useful (0 votes)
27 views14 pages

Setup For Programming Environment of AVR Microcontroller and LED Blink Code

The document outlines the setup process for programming the ATMEGA32 microcontroller using the Zadig tool and Khazama AVR Programmer. It details the installation steps for both software, configuration of fuse and lock bits, and provides a coding environment setup using Microchip Studio for LED blinking experiments. Additionally, it includes assembly code for blinking an LED connected to the microcontroller.

Uploaded by

Rocking Reelz
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)
27 views14 pages

Setup For Programming Environment of AVR Microcontroller and LED Blink Code

The document outlines the setup process for programming the ATMEGA32 microcontroller using the Zadig tool and Khazama AVR Programmer. It details the installation steps for both software, configuration of fuse and lock bits, and provides a coding environment setup using Microchip Studio for LED blinking experiments. Additionally, it includes assembly code for blinking an LED connected to the microcontroller.

Uploaded by

Rocking Reelz
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/ 14

Setup for Programming Environment of AVR

Microcontroller
(ATMEGA32)

Submitted by
Ronit Dutta, MS in IOT and Signal Processing
Department of Electrical Engineering, IIT Kharagpur

Under the guidance of


Aurobinda Routray, Professor, Electrical Engineering

Department of Electrical Engineering


Indian Institute of Technology Kharagpur
January, 2023
Setup for AVR Programming Environment

• Setup for Programming Environment


For the flashing of ATMEGA32, we have required two software
I. Zadig tool
II. Khazama AVR Programmer
Zadig tool:
Zadig tool is required for the installation of the USBASP AVR Programmer driver.
Step 1:
https://zadig.akeo.ie/
Click on the above link and download the software package.

Step 2:
Double Click on the the zadig file and select USBasp from the dropdown menu

Select libusb-win32 driver for the USBasp programmer then click on install driver to
install successfully.

2
Setup for AVR Programming Environment

Step 3:
Go to device manager and check the USBasp under the Microchip Tools dropdown
menu to verify.

Now, we are going to install Khazama AVR Programmer.


Khazama AVR Programmer
Khazama AVR Programmer is required to flash any AVR Group microcontroller. Here
we are going to flash ATMEGA32 as our target microcontroller.

3
Setup for AVR Programming Environment

Step 1:
http://khazama.com/project/programmer/
Click on the above link and download the latest software package.

A .rar file will be downloaded.


Step 2:
Extract the .rar file and click on the .exe file to install the Khazama AVR Programmer.
Step 3:
We have to setup Fuses bits and Lock bits.
Fuse bits and Lock bits are master registers whose values directly affects functioning
of microcontroller.
ATmega32 microcontroller has two fuse bytes namely high fuse and low fuse. Both of them
are 8 bits.
In fuse bits 0 means programmed and 1 means not programmed.
The default value of ATmega32 fuse bit is 0x99E1 i.e. high fuse =0x99 and low fuse =0xE1.

OCDEN : This pin is used to enable or disable on chip debugging. On chip debugging provides
a real time emulation of microcontroller when running in target system. By default it is
disabled as 1 means not programmed.
JTAGEN : There is a built in JTAG interfaces for debugging. It is enabled in new microcontroller.
This is the reason why some newbies say “PORTC of ATmega32 not working!!” Disable it if
you are not using JTAG by making JTAGEN bit 1(high).

4
Setup for AVR Programming Environment

SPIEN : 0 value (programmed) means Serial programing of ATmega32 is enabled. Don’t


change this unless you have a parallel programmer! Because once disabled ATmega32 can’t
be programmed using serial programmer.
EESAVE : If programmed (0) it will save EEPROM from erasing during chip erase else EEPROM
would also be erased with flash.
BOOTSZ0 and BOOTSZ1 : These are used to set the boot loader size.
CKSEL [3-0] : These bits are used to select different clock options available.

The default value of CKSEL3..0 is 0001 i.e. internal RC oscillator running at 1 MHz. If you want
to add external crystal you need to change these values according to the table above. Some
common fuse bits values are given in the end of the article.
CKOPT : The CKOPT Fuse Selects between two different oscillator amplifier modes. When
CKOPT is programmed, the oscillator output will oscillate with a full rail-to-rail swing on the
output. When not programmed, the oscillator has a smaller output swing. If you are using
external crystal oscillator it is better to program CKOPT i.e. CKOPT=0.
BODEN : ATmega32 has an On-chip Brown-out Detection (BOD) circuit for monitoring the VCC
level during operation by comparing it to a fixed trigger level. When the BOD is enabled
(BODEN programmed), and VCC decreases to a value below the trigger level, the Brown-out
Reset is immediately activated. When VCC increases above the trigger level, it starts the
microcontroller again.
BODLEVEL : The trigger level for the BOD can be selected by this fuse bit. When programmed
(0) the trigger level is 4V and when not programmed (1) the trigger level is 2.7V.
BOOTRST : If BOOTRST bit is programmed (0), the device will jump on first address boot-
loader block.
Some fuse bits values are

5
Setup for AVR Programming Environment

Lock Bits: These bits are very important to lock the microcontroller for the further
programming. We have to choose these very carefully.

Run Khazama AVR Programmer and go to command & click on Fuses and Lock Bits for setting
the bits.

6
Setup for AVR Programming Environment

Step 4:
Select the Lock Bits as the following fashion

Step 5:
Set H-Fuse and L Fuse as our desired manner. Then click on Write All tab.

Note: To check the previously set Fuse bits and Lock bits just click on Read All tab
Step 6:
Then to load .hex file into Khazama AVR Programmer click on file & then click on Load FLASH
file to Buffer and then select your .hex file.

7
Setup for AVR Programming Environment

Step 7:
To flash the .hex file into the targeted microcontroller just click on command & then Write
FLASH Buffer to Chip

After flashing the code Just press on the Reset button at your Hardware setup to run the
Embedded System.

8
Setup for AVR Programming Environment

• Setup for Hardware Environment


Components Required for bare minimum setup
I. Bread Board
II. Tactile Push Button
III. USBasp AVR Programmer
IV. ATMEGA32 DIP package
V. Resistor 10KOhm (Quantity=1)
VI. Male to Male jumper wires

Make the above bare minimum circuit on the bread board as shown in the below picture.

For the LED blink additionally we have required 1 LED and 100 Ohm resistor(Quantity=1)

9
Setup for AVR Programming Environment

Connect LED as shown in the below diagram at PORTB in pin PB0.

10
Setup for AVR Programming Environment

• Setup for Coding Environment


Step 1:
Install Microchip Studio from the below link to setup coding environment.
https://www.microchip.com/en-us/tools-resources/develop/microchip-studio#Downloads

Install with web installer or offline installer as your choice.


Step 2:
Click on the Microchip Studio icon to run the IDE(Integrated Development Environment)

Now we can go for Assembly Coding or C/C++ Coding.

11
Setup for AVR Programming Environment

• Experiment: LED Blinking


Assembly coding for LED Blinking on ATMEGA32
Step 1:
Click on File then New then Project

Step 2:
Then click on Assembler and then AVR Assembler Project and then rename it then
click Ok.

12
Setup for AVR Programming Environment

Step 3:
Select the device ATMEGA32 then click OK.

Step 4:
Write the assembly code in the main.asm

13
Setup for AVR Programming Environment

Step 5:
After writing the assembly code go to the build menu then build solution and flash
into ATMEGA32.

// LED Blink program


.INCLUDE "M32DEF.INC"
.ORG 0
SBI DDRB,PINB0

LDI R16, HIGH(RAMEND)


OUT SPH,R16
LDI R16, LOW(RAMEND)
OUT SPL, R16

MAIN: SBI PORTB,PINB0


CALL Delay
CBI PORTB,PINB0
CALL Delay
JMP MAIN

Delay:
LDI R16,0xFF //Loop 1
L1: LDI R17,0xFF // Loop 2
L2: LDI R18,0x07 // Loop 3
L3: NOP
DEC R18
BRNE L3 //Loop 3 End
DEC R17
BRNE L2 //Loop 2 End
DEC R16
BRNE L1 // Loop 3 End
RET

14

You might also like