This is a very basic tutorial for atmega32 microcontroller beginners to get started. You can call this little program as Hello World for atmega programmers.
LED Tutorial Requirements:
- IDE and Compiler Recommended AVR Studio 5
- Wiro Board or Skills to design PCB according to the under given schematic
- ATmega32 microcontroller
- (1)10k resistor
- (8) 330 ohm resistors
- (8) Leds
- (2) 18 pf capacitor (for xtal crystal oscilator drive)
- (1) XTAL crystal Oscilator of any frquency within the limits recommended 4MHz
- 5 Volts DC Power Source to drive the circuit
Schematic Diagram for ATmega32 Led Blink Circuit:
LED Blinking Code:
code is written in C language.
/*
* ledb_blinking_using_Atmega.c
* Author: Bailal Ayoub
*/
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB=0xFF; //Setting all pins of PORTB as output
PORTB=0×00; //Initializing PORTB as Zero (or Sending LED OFF Instruction)
while(1)
{
//Project Code Starts from Here
PORTB=0xFF; //Enabling LED
_delay_ms(200); //giving 200 milisec delay
PORTB=0×00; //Disabling LED
_delay_ms(200); //giving 200 milisec delay
} //while 1 loop ends
} //main ends
Step 1:
Create above circuit using components mentioned in project requirements on Wiroboard or create using PCB.
Step 2:
You need to have ATMEL AVR Studio 5 IDE and compiler. Which will help you to write and edit the C language Code easily. Insert the above source code given C Language code in the avr studio.
Step 3:
Compile the code and create the HEX file
Step 4:
Burn the Hex file to atmega32 Chip using any avr programmer or you can create your own avr usb programmer
Step 5:
Power the circuit and you will have led blinking with the delay of 200 millisecond.