Class 1 - Blinking an LED

April 26, 2025

Hi buddies! 👋

Today, let’s learn how to make an LED blink using the 8051 microcontroller. This is one of the most basic and essential experiments when you’re getting started with embedded systems.

🔌 What Is LED Blinking?

Blinking an LED simply means turning it ON and OFF repeatedly, with a delay in between.

To do this, we need to understand two key concepts:

  1. Port Configuration
  2. Delay Generation

⚙️ 1. Port Configuration

The 8051 microcontroller has 4 ports: PORT0, PORT1, PORT2, and PORT3.
Each port has 8 pins, so in total, you get 32 input/output (I/O) pins.

Important Note About PORT1:

Among these, only PORT1 has internal pull-up resistors by default.
For PORT0, external pull-up resistors are required because it’s an open collector.

Also, these ports support both:

  • Byte addressable access (working with full 8-bit ports)
  • Bit addressable access (working with individual bits)

Examples:

We’ll cover more on bit addressable operations in upcoming tutorials!

⏱ 2. Delay – What and Why?

A delay is a pause where the system does nothing. We need this to control the timing between turning the LED ON and OFF.

How to Create a Delay?

In Assembly, there’s a NOP() instruction.
In C, we use _nop_() from the header file.

But how much time does one _nop_() take?

Assume Crystal Frequency = 11.0592 MHz

  • Clock Period = 1 / 11.0592 MHz ≈ 0.09042 microseconds
  • One Machine Cycle = 12 × Clock Period ≈ 1.085 microseconds

So,
_nop_(); // ≈ 1.085 microseconds delay

To get a 1-second delay, you would need:
1 sec / 1.085 µs ≈ 921,600 NOPs

That’s a lot! So we use nested loops instead.

💡 Solution: Nested Loops for Delay

Delay Calculation:

  • Inner Loop: 384 × 1.085 µs ≈ 416.6 µs
  • Outer Loop: 240 × 416.6 µs ≈ 1 second

🔁 Final Step – Blinking the LED

Now that we understand ports and delays, let’s write the complete code to blink an LED connected to pin P1.1.

Note: Make sure you’ve installed the required software and set up the hardware. Links are in the video description!

✅ Code:

🎉 That’s It!

You’ve just written your first LED blinking program using the 8051 microcontroller!
This is a great foundation before moving on to more complex tasks like using timers, interrupts, and sensors.

Let me know in the comments if you have any questions, or if you’re curious why we specifically used the 11.0592 MHz crystal frequency!

Leave a reply
Intro – BuddyKit – Software InstallationClass 2 – Input Handling – LED Control with Button

Leave Your Reply