Sei sulla pagina 1di 6

Experiment No.

Introduction to 8051 micro controller and I/O port programing using LED

1. To understand the 89c51 Microcontroller
2. To understand it pin configurations
3. Introduction to Keil (89c51 compiler) and Genius G540 (Programmer / Burner)
4. Introduction to 8051 Development Board
5. To interface LEDs with microcontroller
6. Writing first C code and program microcontroller
7. Running a simple program to blink LEDs
8. Use of Keil debugger


AT89C51 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to

many embedded control applications. It follows the basic architecture and instruction set of Intel’s
8bit, 8051 microcontrollers. There are many variants of 8051 like AT89S51, AT89S52 etc. They
differ each other in term of flash memory size,
number of I/O, number of timers etc. Atmel
is one of the leading manufacturers of

Features of AT89C51 Microcontroller:

• 128 bytes of RAM for storing data

• 4kB Flash code memory
• 32 I/O (8 x 4) lines for communicating
with other devices
• Two 16-bit timers / counters
• Five vector two-level interrupt
• Full duplex serial port, on-chip
oscillator and clock circuitry
• 0 to 24MHz crystal frequency
Pin Configuration:

1–8 Port 1: The bi-directional pins on this port may be used for input and output: each pin may be
individually controlled and – for example – some may be used for input while others on the
same port are used for output.

9 The ‘Reset’ pin. When this pin is held at Logic 0, the chip will run normally. If, while the
oscillator is running, this pin is held at Logic 1 for two (or more) machine
cycles,the microcontroller will be reset.

10–17 Port 3: Another bi-directional input port (same operation as Port 1). Each pin on this port also
serves an additional function. Pin 10 and Pin 11 are used to receive and transmit (respectively)
serial data using the ‘RS-232’ protocol. Pin 12 and Pin 13 are used
to process interrupt inputs. Pin 14 and Pin 15 have alternative functions associated with Timer 0
and Timer 1. Pin 16 and Pin 17 are used when working with external memory

18–19 these pins are used to connect an external crystal, ceramic resonator or oscillator module to the

20 Vss. This is the ‘ground’ pin.

21–28 Port 2: Another bi-directional input port (same operation as Port 1). These pins are also used
when working with external memory

29 Program Store Enable (PSEN) is used to control access to external CODE memory (if

30 Address Latch Enable (ALE) is used when working with external memory. Note that some
devices allow ALE activity to be disabled (if external memory is not used): this can help
reduce the level of electromagnetic interference (EMI) generated by your product. This pin is
also used (on some devices) as the program pulse input (PROG) during Flash programming.
31 External Access (EA). To execute code from internal memory (e.g. on-chip Flash, where
available) this pin must be connected to Vcc. To execute code from external memory, this pin
must be connected to ground. Forgetting to connect this pin to Vcc is a common error
when people first begin working with the 8051.

32–39 Port 0: Another bi-directional input port (same operation as Port 1). Note that – unlike Port 1,
Port 2 and Port 3 – this port does NOT have internal pull-up resistors. These pins are also
used when working with external memory

40 Vcc. This is the ‘5V’ pin (on 5V devices; 3V on 3V devices, etc).

Introduction to Keil Software:

Keil Software provides with software development tools for the 8051 family of microcontrollers. Keil
provides following tools for 8051 development:

1. C51 Optimizing C Cross Compiler

2. A51 Macro Assembler
3. 8051 Utilities (linker, object file converter, library manager)
4. Source-Level Debugger/Simulator
5. µVision for Windows Integrated Development Environment

Through Keil, you can write C or assembly language code and compile or assemble it for onward
generation of Hex file. Hex file is burned into microcontroller to perform the required operation.

Introduction to Genius G540 Universal Programmer:

Genius G540 is a universal programmer. It supports a wide range of different series

microcontrollers which includes the Atmel 8051 series microcontrollers as well. It can be connected
to the PC using its USB port.

I/O port Programming using LED Interfacing Hardware

Item Qty Item Qty

Bread Board 01 AT89C51 Microcontroller 01

Resistor 10kΩ 01 Capacitor 10uF/16V 01
Resistor 1kΩ 01 LED (any color) 01
Crystal Oscillator 12MHz 01 Capacitor 33pF 02
Power Supply 5V 01 Connecting Wires Various
Circuit Diagram:

XTAL1 is the crystal oscillator

connected between Pin 18 and Pin 19. If
you are using a clock source other than
crystal oscillator, then the clock will be
provided on XTAL1 (Pin 19) and
XTAL2 (Pin 18) will remain un-

Pin 40 is connected to +5V and Pin 20

is connected to ground to power ON
the microcontroller. R1 and C3 make the
power ON reset circuitry. When power
is switched ON, initially capacitor C3
acts as short circuit and initially +5V
appears at Pin9 which resets the
microcontroller. When capacitor is
completely charged, it acts as open
circuit and Pin9 is pulled low by the
resistor R1.

EA (Pin 31) will always be at high

potential to disable the external code
memory. We will always use the internal
code memory of microcontroller, so this
pin will always be connected to high
potential throughout the labs.


/* This program continuously toggles the Port1. Each toggle has a delay of one second
approximately */

void delay () //
/ / delay function
unsigned int x;
} // approx 1 second delay

void main (void)

P1 = 0x00; // Make Port1 as output
while(1) // Forever Loop
P1 = ~P1; // Toggle Port1
delay (); // call delay function
} // End forever Loop
} // End main

Lab Task

Connect eight LEDs with Port 1 and lit the LEDs in progress bar fashion. Keep the LEDs running
like forward and reverse progress bar, as shown in following figure:
Hint: Use loops to complete the required task
Lab Report

Q1: What is difference RISC and CISC architectures?


Q2: What do we need infinite loop in Embedded Systems?


Q3: Write down the steps for creating and compiling C code in Keil uVision software?

Q4: What is difference between microprocessor and microcontroller?