Lab1 Final
Lab1 Final
Lab1 Final
1
Introduction to 8051 micro controller and I/O port programing using LED
Interfacing
Objective
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
Introduction
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
microcontroller.
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
used).
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
Keil Software provides with software development tools for the 8051 family of microcontrollers. Keil
provides following tools for 8051 development:
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.
Code:
/* This program continuously toggles the Port1. Each toggle has a delay of one second
approximately */
#include<AT89x51.h>
void delay () //
/ / delay function
{
unsigned int x;
for(x=0;x<25000;x++)
{
} // approx 1 second delay
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
Q3: Write down the steps for creating and compiling C code in Keil uVision software?
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________