LED Interfacing with 8051 In Advance Level
If you are
looking for a beginners guide on “How to start with 8051 Microcontroller”,
here in this article I will show you how to work with 8051 microcontroller
practically. I am not going into detail of “What is 8051 microcontroller”
or “How to write a c-program” etc., but the scope of this article is to
tell about the hardware and software which are needed to work with
microcontroller and how to use them.
To get started with designing
mega projects or electronics innovation the understanding of basic and simple
projects is important. This will get familiarized with 8051
Microcontroller and also the designing environment. LED Interface with
8051 is one of the basic projects. Therefore, shall be looking at the
very basic project, which is interfacing LED with 8051 and then moving towards
mega projects.
Table of Content:
1. List of Inventories
1.1 Hardware Requirement
1.2 Software Requirements
1.3 Brief Introduction of component and calculate resistance
2. System Modelling
2.1 Circuit Diagram
2.2 Source Code Programming
2.2.1 LED Interfacing with 8051
2.2.1.1 How to Edit, Compile code and get .hex file
2.2.2 Multiple LED Interfacing with 8051
2.2.3 Multiple LED Light Interfacing with 8051
2.2.4 Traffic light Controlling System
1. List of Inventories
1.1 Hardware Requirement
1.2 Software Requirements
1.3 Brief Introduction of component and calculate resistance
2. System Modelling
2.1 Circuit Diagram
2.2 Source Code Programming
2.2.1 LED Interfacing with 8051
2.2.1.1 How to Edit, Compile code and get .hex file
2.2.2 Multiple LED Interfacing with 8051
2.2.3 Multiple LED Light Interfacing with 8051
2.2.4 Traffic light Controlling System
1.List of Inventories:
1.1
Hardware Requirements:
VI. 11.0592 Mhz
Crystal Oscillator
VII.
33pf capacitor - 2
1.1 Brief
introduction of the component:
1) 8051: The Intel 8051 is an 8-bit microcontroller which
means that most available operations are limited to 8 bits. There are 3 basic
"sizes" of the 8051: Short, Standard, and Extended. The Short and
Standard chips are often available in DIP (dual in-line package) form, but the
Extended 8051 models often have a different form factor, and are not
"drop-in compatible". All these things are called 8051 because they
can all be programmed using 8051 assembly language, and they all share certain
features (although the different models all have their own special features).
Some of the features that have made the 8051
popular are:
·
4 KB on chip program memory.
·
128 bytes on chip data memory(RAM)
o
32 bytes devoted to register banks
o
16 bytes of bit-addressable memory
o
80 bytes of general-purpose memory
·
4 register banks.
·
128 user defined software flags.
·
8-bit data bus
·
16-bit address bus
·
16 bit timers (usually 2, but may have more, or less).
·
3 internal and 2 external interrupts.
·
Bit as well as byte addressable RAM area of 16 bytes.
·
Four 8-bit ports, (short models have two 8-bit ports).
·
16-bit program counter and data pointer.
·
1 Microsecond instruction cycle with 12 MHz Crystal.
Variants of the 8051 may also have a number of
special, model-specific features, such as UART, ADC, Op_Amps, etc., making it
an even more powerful microcontroller.
Basic
Pins:
- PIN 9: PIN 9 is the reset pin which is used to reset the microcontroller’s internal registers and ports upon starting up. (Pin should be held high for 2 machine cycles.)
- PINS 18 & 19: The 8051 has a built-in oscillator amplifier hence we need to only connect a crystal at these pins to provide clock pulses to the circuit.
- PIN 40 and 20: Pins 40 and 20 are VCC and ground respectively. The 8051 chip needs +5V 500mA to function properly, although there are lower powered versions like the Atmel 2051 which is a scaled down version of the 8051 which runs on +3V.
- PINS 29, 30 & 31: As described in the features of the 8051, this chip contains a built-in flash memory. In order to program this we need to supply a voltage of +12V at pin 31. If external memory is connected then PIN 31, also called EA/VPP, should be connected to ground to indicate the presence of external memory. PIN 30 is called ALE (address latch enable), which is used when multiple memory chips are connected to the controller and only one of them needs to be selected.We will deal with this in depth in the later chapters. PIN 29 is called PSEN. This is "program store enable". In order to use the external memory it is required to provide the low voltage (0) on both PSEN and EA pins.
- Pin 29: If we use an external ROM then it should have a logic 0 which indicates Micro controller to read data from memory.
- Pin 30: This Pin is used for ALE that is Address Latch Enable. If we use multiple memory chips then this pin is used to distinguish between them.It is activated periodically with a constant rate of 1/6th of oscillator frequency. This Pin also gives program pulse input during programming of EPROM.
- Pin 31: If we have to use multiple memories then by applying logic 1 to this pin instructs Micro controller to read data from both memories first internal and afterwards external.
There are 4 8-bit ports: P0, P1, P2 and P3.
PORT P1 (Pins 1 to 8): The
port P1 is a general purpose input/output port which can be used for a variety
of interfacing tasks. The other ports P0, P2 and P3 have dual roles or
additional functions associated with them based upon the context of their
usage.The port 1 output buffers can sink/source four TTL inputs. When 1s are
written to portn1 pins are pulled high by the internal pull-ups and can be used
as inputs.
PORT P3 (Pins 10 to 17): PORT
P3 acts as a normal IO port, but Port P3 has additional functions such as,
serial transmit and receive pins, 2 external interrupt pins, 2 external counter
inputs, read and write pins for memory access.
PORT P2 (pins 21 to 28): PORT P2 can also be used as a general purpose 8 bit port when no external memory is present, but if external memory access is required then PORT P2 will act as an address bus in conjunction with PORT P0 to access external memory. PORT P2 acts as A8-A15, as can be seen from fig 1.1
PORT P0 (pins 32 to 39) PORT P0 can be used as a general purpose 8 bit port when no external memory is present, but if external memory access is required then PORT P0 acts as a multiplexed address and data bus that can be used to access external memory in conjunction with PORT P2. P0 acts as AD0-AD7
PORT P10: asynchronous communication input or Serial synchronous communication output.
PIN 11: Serial Asynchronous Communication Output or Serial Synchronous Communication clock Output.
The 8051 requires an external oscillator circuit.
The oscillator circuit usually runs around 12 MHz, although the 8051
(depending on which specific model) is capable of running at a maximum of
40 MHz. Each machine cycle in the 8051 is 12 clock cycles, giving an
effective cycle rate at 1 MHz (for a 12 MHz clock) to 3.33 MHz
(for the maximum 40 MHz clock). The oscillator circuit generates the clock
pulses so that all internal operations are synchronized.
One machine cycle has 6 states. One state is 2
T-states. Therefore one machine cycle is 12 T-states. Time to execute an
instruction is found by multiplying C by 12 and dividing product by Crystal
frequency.
T=(C*12d)/crystal frequency
What
is design re-usability?
There
are a lot of semiconductor companies that manufacture logic devices like CPUs,
microprocessor, microcontrollers and so on. The process of development of these
technologies is often time-consuming and needs a lot of investment.
Let’s
say Company A invests a lot of time and money in developing a state of the art
controller from the ground up. There are a lot of underlying processes which
come together to make a controller. For example, designing the architecture.
Once Company A has developed, tested and released their finished product, they
sell the license of the underlying technologies used to build that particular
controller of theirs, to other companies. So if Company B buys this license
from Company A, they don’t have to do all the work from scratch. They can just
use Company A’s underlying technology to build their own customized controller.
The
underlying technologies that are licensed are called Intellectual
Property (IP) Cores. Using popular IP cores maintains consistency and
people like us get a lot of options to work on without experiencing drastic
changes in usability. If every company had its own architecture, it would be
quite difficult to learn those every time you wanted to try a new
microcontroller. An excellent example of this are the Exynos chips from Samsung
and the AX chips from Apple. They both use ARM IP cores.
The
8051 IP cores are free to use. The actual microcontrollers are incredibly cheap
to buy. They are smaller and consume less power than 32 bit ARM cores. There is
a large community of people who are familiar with the architecture. These are
just some of the reasons why the 8051 is still popular.
System
design metrics
When
we design an embedded system, there are a few things that need consideration.
It is the job of an embedded systems engineer to make sure that all of the
following parameters (and more, as we will see later in this course) are
considered.
- Processing
power
- Reliability
- Power
consumption
- Cost
- Time
to prototype & time to market
- Maintainability
- Processing Power
Based
on the complexity of the software, a system requires a certain amount of
computing power. It is necessary to find the right amount of processing power,
not too less and definitely not more than required. 8051s
have enough variants that provide processing power from 1 MIPS (Original 8051)
to 450 MIPS (Million Instructions Per
Second)
- Reliability
An
embedded system needs to be tested and validated thoroughly. This stage
usually takes time and adds to the cost.The
8051 variants available in the market have been tested rigorously, thanks to
its popularity and free of cost IP cores.
- Power consumption
It is
imperative to treat power as a scarce resource while designing an embedded
system. You are always expected to develop a system that has just enough power
to be fully operational. The life of a system’s battery depends on the power
consumed by it.
- Costs
The
cost is usually considered way before the actual designing of an embedded
system even begins. The cost of the project is one of the biggest things to be
considered before designing a project.The
8051 has free IP cores, and the actual chips are inexpensive.
- Time to prototype and time to market
Time
equals higher costs and is usually mostly spent on implementing the
core functionality in a working prototype, scaling it and testing it. Time to market is the time required to make a
system ready for marketing.Since
the 8051 has a simple architecture, its testing is easy too.
- Maintainability
The
ease with which a system can be maintained or modified after its commercial
release. Especially by designers who were not involved in the original
designing of the system.
2) LED Matrix :
These matrix can be made by circuiting 64 LEDs, however that process is time consuming. Now a day they are available in compact forms as shown in below image. These compact modules are available in different sizes and many colors. The cost of module is same as cost of 64 LEDs, so for hobbyists this is easiest to work on.The bare LED matrix has 16 pin outs with 8 common positive and another 8 common negative. For connecting this matrix directly to a UNO, we need to spare 16 pins on the UNO. With the output pins low on UNO, we cannot spare 16 PINS. So we need to connect this matrix to a driver chip. This driver chip along with matrix comes as a set which is shown in below figure.
IDE
for Programming
I am assuming that you are aware about the basic
electronics components, wires, breadboard, battery etc, so I am directly
heading to 8051 Microcontroller.
Now first we need a C program to run microcontroller, so
that we can program it and it will work according to program. So we need an IDE
(Integrated development environment) to write and compile the program, there
are many editor available but unarguably the best IDE is “keil uVision IDE”. In
Keil uvision you can write, compile, debug and run a program. There are the
steps to use Keil uvision:
1. Download latest keil uvision4 and install the
program.
2. Go to Project and select ‘New uVision Project’,
give it a name and save it. You will find ‘Target 1’ and ‘Source Group 1’
folder structure in the left side.
3. Right click on Target 1, select “Options for Target
Target 1”, click on Output tab and check the checkbox ‘Create HEX file’ then
click OK.
1. Click on File menu and click on ‘New’, write c
program and save it with .c extension like ‘led_blinking.c’ (usually in same
folder in which we create uVision project)
2. Right click on ‘Source Group 1’ select ‘Add files
to Group Source Group 1’ and select your c program file and click ‘Add’ then
click ‘Close’.
3. Now go to Project menu and click on ‘Rebuild all
target Files’ or click on button as shown in above figure. In output window,
you can check for any Error and Warning. It also create HEX file in same folder
as c program file. We need this HEX file to program 8051 chip, explained in
next section.
So at the end of this section, we have the HEX file of c
program which we want to run through 8051 microcontroller.
2. System modelling:
2.1 Circuit Diagram:
2.2 Working of project
This is a simple project which will make LED blink. The basic idea is to turn on LED and after some time turn it off. The anode of the LED is connected through a 330 ohms resistor to pin 13 of Arduino and the cathode also through the 330 ohms resistor to GND. When the command to turn on the LED is given through code, a +5v is supplied to the anode of the LED and this makes it light up. Also when the command to turn off the LED is given, it takes it back to 0v thereby turning the LED off. The code is given below.
This is a simple project which will make LED blink. The basic idea is to turn on LED and after some time turn it off. The anode of the LED is connected through a 330 ohms resistor to pin 13 of Arduino and the cathode also through the 330 ohms resistor to GND. When the command to turn on the LED is given through code, a +5v is supplied to the anode of the LED and this makes it light up. Also when the command to turn off the LED is given, it takes it back to 0v thereby turning the LED off. The code is given below.
More About
I. How to select Board ?
II. How to compile program ?
III. How to add sensor/module library in proteus software?
2.2.2 Multiple LED Interfacing with Arduino
Introduction:
It is Similar to interfacing single LED just required to declare multiple LED pin as a OUTPUT and adjust the all LED blinking sequence as per choice of delay between each .
2.3 Result:
Published by, Electronics with shreyash :
2.2.3 Multiple LED lights Interfacing with Arduino
Introduction:
It is Similar to interfacing single LED just required to declare multiple LED pin as a OUTPUT and adjust the all LED blinking sequence as per choice of delay between each .
2.3 Result:
Published by, Electronics with shreyash :
To Download the code click here
2.2.4 Traffic Light control system
Introduction: Traffic Lights or Traffic Signals are signalling devices that are used to control the flow of traffic. Generally, they are positioned at junctions, intersections, ‘X’ roads, pedestrian crossings etc. and alternate the priority of who has to wait and who has to go. The traffic lights will provide instructions to the users (drivers and pedestrians) by displaying lights of standard color. The three colors used in traffic lights are Red, Yellow and Green.The system must be used to control the traffic lights for smooth and safe movement of traffic. These control systems consists of Micro-controllers with clockwork mechanisms or modern solid state computerized systems with easy setup and maintenance.
2.3 Result:
Published by, Electronics with shreyash :
Comments
Post a Comment