Exp1 Introduction of Microchip Studio, SimulIDE and Hardware Programming Tool (Khazama AVR Programmer) With LED Blink
Exp1 Introduction of Microchip Studio, SimulIDE and Hardware Programming Tool (Khazama AVR Programmer) With LED Blink
(ATMEGA32)
Submitted by
Ronit Dutta, MS in IOT and Signal Processing
Department of Electrical Engineering, IIT Kharagpur
2
Embedded System on AVR ATMEGA32:Exp1
3
Embedded System on AVR ATMEGA32:Exp1
4
Embedded System on AVR ATMEGA32:Exp1
Step 2:
Then click on Assembler and then AVR Assembler Project and then rename it then
click Ok.
5
Embedded System on AVR ATMEGA32:Exp1
Step 3:
Select the device ATMEGA32 then click OK.
Step 4:
Write the assembly code in the main.asm
6
Embedded System on AVR ATMEGA32:Exp1
Step 5:
After writing the assembly code go to the build menu then build solution to generate
the HEX file.
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 1 End
RET
7
Embedded System on AVR ATMEGA32:Exp1
#include <avr/io.h>
#define F_CPU 1000000L
#include <util/delay.h>
int main(void)
{
DDRB=0xFF; //DDRB=0X01;
/* Replace with your application code */
while (1)
{
PORTB=0xFF; //PORTB=0X01;
_delay_ms(500);
PORTB=0X00;
_delay_ms(500);
}
}
8
Embedded System on AVR ATMEGA32:Exp1
Simulation on SimulIDE
SimulIDE Download Link: https://simulide.com/p/downloads/
Make the below circuit on SimulIDE
Then right click on the microcontroller and upload the HEX file on it. Set the proper
clock frequency then simulate it.
9
Embedded System on AVR ATMEGA32:Exp1
Attach an oscilloscope to observe the generated square wave signal (LED Blink Signal).
Right click on the microcontroller and click on “Open Mcu Monitor”. Check the RAM status.
To check the simulation less than Real-Time speed then click on settings and decrease the
simulation speed.
10
Embedded System on AVR ATMEGA32:Exp1
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.
11
Embedded System on AVR ATMEGA32:Exp1
Step 3:
Go to device manager and check the USBasp under the Microchip/libusb-win32
Tools dropdown menu to verify.
12
Embedded System on AVR ATMEGA32:Exp1
Step 1:
http://khazama.com/project/programmer/
Click on the above link and download the latest software package.
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).
13
Embedded System on AVR ATMEGA32:Exp1
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
14
Embedded System on AVR ATMEGA32:Exp1
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.
15
Embedded System on AVR ATMEGA32:Exp1
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.
16
Embedded System on AVR ATMEGA32:Exp1
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.
Assignment: Change the duty cycle of the LED Blink with 25% duty cycle and 75% duty
cycle.
17