MY PROJECTS
robotics - electronics - machining
  Friday November 22nd 2024 06:16:24 PM

Atmega 168 led blink using interrupt

Things you will need:


The breadboard setup as shown on the main page 330resistor.jpg (67138 bytes) A 330 to 470 ohm resistor
led.jpg A led


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

1) Take the breadboard assembled from the main tutorial page and set it in front of you.

2) Connect the resistor with the led to PB0 (14) on the Atmega and to GND as shown in the schematic. The flat side of the led (cathode) goes to negative.

led_sch.png

The result should be something that looks similar to below.

  blink_side.jpg   blink_top.jpg

The ISP programmer hookup can be seen at the rear.

3) Download the following sample code and load it into the Atmega using your favorite download software. The specifics of programming the Atmega are not covered here since there are several different ways to do it.

4) Program the fuse settings as follows:
lfuse = 0x62, hfuse = 0xDF, efuse = 0xF9

C Code Section

#include <avr/io.h>
#include <avr/interrupt.h>

int main (void)
{
DDRB = 0xFF;             // set up pin direction
TCCR1B = 0x01;           // set prescaler to /1

// set interrupt mask register
TIMSK|=(1<<TOIE1);       // mega8 to enable overflow interrupt
//TIMSK1|=(1<<TOIE1);    // For mega48 88 or 168

sei();                   // turn interrupts on

while(1);                // chase the tail
}


ISR(TIMER1_OVF_vect)
{
    PORTB ^= 0xFF;    
   //toggle portB
}

C Source code for this project.


Copyright © Tom_L 2009-2020