Interfacing a LED with a Microcontroller
AVR microcontrollers such as the ATMega8515 only supply a current of about 20mA and so we can drive an LED directly from the microcontroller port eliminating the resistor. In fact if a resistor is added the intensity of the LED will be low.
The figure below shows 8-LEDs connected to an ATMega8515 microcontroller. The code that follows if downloaded to the microcontroller will blink the LEDs continuously. Note that this code could work with other AVR microcontrollers such as the ATMega16, ATmega32, ATTiny2313, etc.
Note: In order for the circuit to operate as describe the internal oscillator of the ATMega8515 microcontroller must be program to run at 4MHz.
/* * Written in AVR Studio 5 * Compiler: AVR GNU C Compiler (GCC) * Author: AVR Tutorials * Website: AVR-Tutorials.com */ #include <avr/io.h> #define F_CPU 4000000UL #include <util/delay.h> int main() { DDRC = 0xFF; // Configure port C as output while(1) { PORTC = 0xFF; // Turn ON LEDs _delay_ms(250); // Wait 250ms PORTC = 0x00; // Turn OFF LEDs _delay_ms(250); // Wail 250ms } return 0; }
Video Demonstrating Code Running on the ATMega8515 Microcontroller
AVR Tutorials hopes this tutorial on interfacing LEDs with the AVR microcontroller was beneficial to you and looks forward to your continued visits for all your microcontroller tutorial needs.