LED Blinking with ATmega32 Microcontroller
Đèn LED nhấp nháy là bước đầu tiên bạn muốn làm để bắt đầu với thiết bị điện tử. Trong hướng dẫn này, chúng ta sẽ kết nối đèn LED với ATmega32, là vi điều khiển dòng AVR. Chúng tôi sẽ nhấp nháy đèn LED với tốc độ nửa
Components Required
Hardware:
ATmega32A Microcontroller
Power supply (5v)
AVR-ISP Programmer
100uF Capacitor
LED
220Ω Resistor
Software
Atmel studio 6.1
Progisp or flash magic
Circuit and Working Explanation
Programming Explanation
#include <avr/io.h> //header to enable data flow control over pins
#define F_CPU 1000000 //telling controller crystal frequency
#include <util/delay.h> //header to enable delay function in program
int main(void)
{
DDRD = 0xFF; // ( or 0b1111 1111) In AVRSTUDIO for telling the controlling to use a certain bit of a port as input we use “ZERO”, for telling it to use a certain bit as output we use “ONE”. Since we put eight “ONE’s”, all the pins of PORTD are enabled as output. If we put a zero as “0b1111 0111”, now all the pins 0,1,2,4,5,6,7 are enabled as inputs and PIN 3 is Enabled as input.
while(1) // loop goes on forever and the LED will be blinking forever
{
PORTD = 0xFF; // all pins of PORTD are said to provide 5v output or told to pull high (LED ON)
_delay_ms(220); //delay for 200ms
_delay_ms(220); ); //delay for 200ms
PORTD = 0x00; // all pins of PORTD are said to provide ground at output or pull down
_delay_ms(220); ); //delay for 200ms
_delay_ms(220); ); //delay for 200ms
}
}
#include <avr/io.h>
#define F_CPU 1000000
#include <util/delay.h>
int main(void)
{
DDRD = 0xFF;
while(1)
{
PORTD = 0xFF;
_delay_ms(220);
_delay_ms(220);
PORTD = 0x00;
_delay_ms(220);
_delay_ms(220);
}
}