MY PROJECTS
robotics - electronics - machining
  Thursday March 28th 2024 11:59:10 AM

Atmega 168 led blink using delay

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 Example Code Section

#include <avr/io.h>
void Delay(int delay);       // function declaration
int main (void)
{
DDRB = 0xFF;                // set up pin direction
while(1)                    // start the loop
   {
   PORTB ^= 0xFF ;          // toggle the pins
   Delay(1000);             // delay a bit
   }
}
void Delay(int delay)
{
int x, y;
for (x = delay; x != 0; x--)
   {
   for (y = 1000; y != 0; y--)
       {
          asm volatile ("nop"::); //do nothing for a bit
       }
    }
}

C Source code for this project.


Copyright © Tom_L 2009-2020