Skip to main content

ATmega32 LED Blink (PC0)

This tutorial explains how to blink an LED using the ATmega32 microcontroller.


🔌 LED Connection

  • LED is connected to PC0

Logic Type: Active-HIGH

  • PC0 = 1 → LED ON
  • PC0 = 0 → LED OFF

⚙️ Requirements

Hardware

Software

  • Atmel Studio / Microchip Studio / AVR-GCC
  • Programmer software (e.g., AVRDude)

🧱 Project Setup

  1. Open your AVR IDE (Atmel Studio / Microchip Studio)
  2. Create a New GCC C Project
  3. Select device: ATmega32
  4. Add a new file: main.c

Note: Delay depends on CPU frequency. Here we assume 12 MHz.

#define F_CPU 12000000UL  // CPU frequency

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
// Set PC0 as output
DDRC |= (1 << PC0);

// LED OFF initially
PORTC &= ~(1 << PC0);

while (1)
{
// LED ON
PORTC |= (1 << PC0);
_delay_ms(500);

// LED OFF
PORTC &= ~(1 << PC0);
_delay_ms(500);
}
}