Download - A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
1/26
A BRIEF INTRODUCTION TO8051 MICROCONTROLLER
When we have to learn about a new computer we have to familiarize about the machine capability we are
using, and we can do it by studying the internal hardware design (devices architecture), and also to know
about the size, number and the size of the registers.A microcontroller is a single chip that contains the
processor (the CPU), non-volatile memory for the program (ROM or flash), volatile memory for input
and output (RAM), a clock and an I/O control unit. Also called a "computer on a chip," billions of
microcontroller units (MCUs) are embedded each year in a myriad of products from toys to appliances to
automobiles. For example, a single vehicle can use 70 or more microcontrollers. The following picture
describes a general block diagram of microcontroller.89s52: The AT89S52 is a low-power, high-
performance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. The
device is manufactured using Atmels high-density non-volatile memory technology and is compatible
with the industry-standard 80C51 instruction set and pin out. The on-chip Flash allows the programmemory to be reprogrammed in-system or by a conventional non volatile memory programmer. By
combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel's
AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to
many embedded control applications. The AT89S52 provides the following standard features: 8K bytes
of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit
timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator,
and clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero
frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU
while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The
Power-down mode saves the RAM con-tents but freezes the oscillator, disabling all other chip functions
until the next interrupt. The hardware is driven by a set of program instructions, or software. Once
familiar with hardware and software, the user can then apply the microcontroller to the problems easily.
The pin diagram of the 8051 shows all of the input/output pins unique to microcontrollers:
The following are some of the capabilities of 8051 microcontroller.
Internal ROM and RAM
I/O ports with programmable pins
Timers and counters
Serial data communication
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
2/26
INTRODUCTION
Amicrocontroller is a computer-on-a-chip built for specific tasks such as displaying/receiving information
through LEDs or remote controlled devices. 8051 introduced the world to the most revolutionary set of
microcontrollers.
Apart from 8051, 8052 and 8031 complete the 8051 family. The 8052 microcontroller has 256 bytes of
RAM and 3 timers. Programs written for 8051 projects can be used for 8052 as well. The 8031 has all
features of 8051 except that it is ROM-less. An external ROM that is as large as 64 k bytes can be
programmed and added to this chip for execution. The main disadvantage of adding external ROM is that 2
out of 4 ports are used up leaving less for I/O operations.
The different types of memory used in 8051 are:
i. Internal RAMLocated from address 0 to 0xff.
ii. Special Function Registers (SFR)Located from address 0x80 to 0Xff.
iii. Program MemoryLocated at address 0. Uses 16 bit Special Function Register DPTR, to save the tables
of constants.
iv. External Data MemoryLocated at address 0. Uses MOVX (Move External) to access the external data
memory.
8051s history dates back to when Intel Corporation first built the 8 bit microcontroller in 1981. This
microcontroller was referred as system on a chip because it had 128 bytes of RAM, 4 Kbytes of ROM, 2Timers, 1 Serial port, and four ports on a single chip.
Intel permitted other microcontroller manufacturers to fabricate different versions of 8051 with the condition
that code compatibility should be maintained. The advantage of this is that when the program is written, it
can be used for any version of 8051 irrespective of manufacturer.
http://vj86.hubpages.com/hub/embeddedsystemshttp://vj86.hubpages.com/hub/embeddedsystemshttp://vj86.hubpages.com/hub/embeddedsystems -
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
3/26
8051 BLOCK DIAGRAM
8051 Microcontroller Block Diagram Explanation:
CPU (Central Processor Unit):
As you may be familiar that Central Processor Unit or CPU is the mind of any processing machine. It
scrutinizes and manages all processes that are carried out in the Microcontroller. User has no power over the
functioning of CPU. It interprets program printed in storage space (ROM) and carries out all of them and do
the projected duty.
Interrupts:
As the heading put forward, Interrupt is a sub-routine call that reads the Microcontrolle rs key function or
job and helps it to perform some other program which is extra important at that point of time. The
characteristic of Interrupt is extremely constructive as it aids in emergency cases. Interrupts provides us a
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
4/26
method to postpone or delay the current process, carry out a sub-routine task and then all over again restart
standard program implementation.
The Micro-controller 8051 can be assembled in such a manner that it momentarily stops or break the core
program at the happening of interrupt. When sub-routine task is finished then the implementation of core
program initiates automatically as usual. There are 5 interrupt supplies in 8051 Microcontroller, two out offive are peripheral interrupts, two are timer interrupts and one is serial port interrupt.
Memory:
Micro-controller needs a program which is a set of commands. This program enlightens Microcontroller to
perform precise tasks. These programs need a storage space on which they can be accumulated and interpret
by Microcontroller to act upon any specific process. The memory which is brought into play to accumulate
the program of Microcontroller is recognized as Program memory or code memory. In common language
its also known as Read Only Memory or ROM.
Micro-controller also needs a memory to amass data or operands for the short term. The storage space which
is employed to momentarily data storage for functioning is acknowledged as Data Memory and we employ
Random Access Memory or RAM for this principle reason. Microcontroller 8051 contains code memory or
program memory 4K so that is has 4KB Rom and it also comprise of data memory (RAM) of 128 bytes.
Bus:
Fundamentally Bus is a group of wires which functions as a communication canal or mean for the transfer
Data. These buses comprise of 8, 16 or more cables. As a result, a bus can bear 8 bits, 16 bits all together.
There are two types of buses:
1. Address Bus:Microcontroller 8051 consists of 16 bit address bus. It is brought into play to address
memory positions. It is also utilized to transmit the address from Central Processing Unit to Memory.
2. Data Bus:Microcontroller 8051 comprise of 8 bits data bus. It is employed to cart data.
Oscillator:
As we all make out that Microcontroller is a digital circuit piece of equipment, thus it needs timer for its
function. For this function, Microcontroller 8051 consists of an on-chip oscillator which toils as a time
source for CPU (Central Processing Unit). As the productivity thumps of oscillator are steady as a result, it
facilitates harmonized employment of all pieces of 8051 Microcontroller. Input/output Port: As we are
acquainted with that Microcontroller is employed in embedded systems to manage the functions of devices.
Thus to gather it to other machinery, gadgets or peripherals we need I/O (input/output) interfacing ports in
Micro-controller. For this function Micro-controller 8051 consists of 4 input/output ports to unite it to other
peripherals.
Timers/Counters: Micro-controller 8051 is incorporated with two 16 bit counters & timers. The counters are
separated into 8 bit registers. The timers are utilized for measuring the intervals, to find out pulse width etc.
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
5/26
8051 Architecture
16 bit PC &data pointer (DPTR)
8 bit program status word (PSW)
8 bit stack pointer (SP)
Internal ROM 4k
Internal RAM of 128 bytes.
4 register banks, each containing 8 registers
80 bits of general purpose data memory
32 input/output pins arranged as four 8 bit ports P0-P3
Two 16 bit timer/counters: T0-T1
Two external and three internal interrupt sources
Oscillator and clock circuits
For any electronics project the power supply plays a very important role in its proper functioning. In this
project we are using external A.C supply (220 v) as input, this high voltage is converted into 12 Volts A.C
by step down transformer, then we use voltage regulators and filters with bridge rectifier to convert the A.C
into D.C voltage. For voltage regulation we are using LM 7805 and 7812 to produce ripple free 5 and 12
Volts D.C constant supply.
A circuit breaker capable of microcontroller-based fault detection having a backup circuit for causing the
circuit to trip in response to a microcontroller fault or a failure of a regulated power supply powering the
microcontroller. The circuit breaker includes an RC circuit connected to an SCR. The resistor of the RC
circuit is connected between the anode and gate of the SCR, and the capacitor is connected between the gateand cathode of the SCR. The microcontroller has a first pin coupled to the RC circuit, which is initially in a
high input impedance state. In the event of a microcontroller fault or power supply failure, the capacitor will
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
6/26
charge to a voltage sufficient to activate the SCR and trip the breaker. If the microcontroller start-up routine
is successful, the pin is configured as an output and is pulled low, shorting out the capacitor.
DESCRIPTION OF 8051INTERFACINGS
It is very important to keep a track of the working of almost all the automated and semi-automated devices,
be it a washing machine, an autonomous robot or anything else. This is achieved by displaying their status
on a small display module.LCD (Liquid Crystal Display) screen is such a display module and a 16x2 LCD
module is very commonly used. These modules are replacingseven segments and other multi segment LEDs
for these purposes. The reasons being: LCDs are economical, easily programmable, have no limitation of
displaying special & evencustom characters (unlike in seven segments), animations and so on. LCD can be
easily interfaced with a microcontroller to display a message or status of a device. This topic explains the
basics of a 16x2 LCD and how it can be interfaced withAT89C51 to display a character.
http://engineersgarage.com/content/lcdhttp://engineersgarage.com/content/seven-segment-displayhttp://engineersgarage.com/content/how-create-custom-characters-16x2-lcd-using-at89c51http://engineersgarage.com/content/microcontroller-at89c51http://engineersgarage.com/content/microcontroller-at89c51http://engineersgarage.com/content/how-create-custom-characters-16x2-lcd-using-at89c51http://engineersgarage.com/content/seven-segment-displayhttp://engineersgarage.com/content/lcd -
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
7/26
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
8/26
controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII
value of the character to be displayed on the LCD. Click to learn more about internal structure of aLCD.
PinDiagram:
http://www.engineersgarage.com/insight/how-lcd-workshttp://www.engineersgarage.com/insight/how-lcd-works -
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
9/26
Pin Description:
Pin No Function Name
1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V5.3V) Vcc
3 Contrast adjustment; through a variable resistor VEE
4 Selects command register when low; and data register when high Register Select
5 Low to write to the register; High to read from the register Read/write
6 Sends data to data pins when a high to low pulse is given Enable
7
8-bit data pins
DB0
8 DB1
9 DB2
10 DB3
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC(5V) Led+
16 Backlight Ground (0V) Led-
SEVEN SEGMENT
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
10/26
A seven segment display is the most basic electronic display device that can display digits from 0-9. They
find wide application in devices that display numeric information like digital clocks, radio, microwave
ovens, electronic meters etc. The most common configuration has an array of eight LEDs arranged in a
special pattern to display these digits. They are laid out as a squared-off figure 8.Every LED is assigned a
name from 'a' to 'h' and is identified by its name. Seven LEDs 'a' to 'g' are used to display the numerals while
eighth LED 'h' is used to display the dot/decimal.
A seven segment is generally available in ten pin package. While eight pins correspond to the eight LEDs,
the remaining two pins (at middle) are common and internally shorted. These segments come in two
configurations, namely, Common cathode (CC) and Common anode (CA). In CC configuration, the negative
terminals of all LEDs are connected to the common pins. The common is connected to ground and a
http://www.engineersgarage.com/content/ledhttp://www.engineersgarage.com/content/led -
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
11/26
particular LED glows when its corresponding pin is given high. In CA arrangement, the common pin is
given a high logic and the LED pins are given low to display a number
AT89C51 MICROCONTROLLER
AT89C51 is an 8-bitmicrocontroller and belongs to Atmel's8051 family.ATMEL 89C51has 4KB of Flash
programmable and erasable read only memory (PEROM) and 128 bytes of RAM. It can be erased and
program to a maximum of 1000 times.
In 40 pin AT89C51, there are four ports designated as P1, P2, P3and P0. All these ports are 8-bit bi-
directional ports, i.e., they can be used as both input and output ports. Except P0which needs external pull-
ups, rest of the ports have internal pull-ups. When 1s are written to these port pins, they are pulled high by
the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also
be accessed individually.
http://www.engineersgarage.com/microcontrollerhttp://www.engineersgarage.com/8051-microcontrollerhttp://www.engineersgarage.com/8051-microcontrollerhttp://www.engineersgarage.com/microcontroller -
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
12/26
Port P0and P2are also used to provide low byte and high byte addresses, respectively, when connected to an
external memory. Port 3 has multiplexed pins for special functions likeserial communication, hardware
interrupts, timer inputs and read/write operation from external memory. AT89C51 has an inbuilt UART for
serial communication. It can be programmed to operate at different baud rates. Including twotimers &
hardwareinterrupts,it has a total of six interrupts.
Pin Diagram:
http://www.engineersgarage.com/microcontroller/8051projects/interface-serialport-RS232-AT89C51http://www.engineersgarage.com/tutorials/timers-8051-timer-programming-tutorialhttp://www.engineersgarage.com/tutorials/interrupts-8051-interrupt-programminghttp://www.engineersgarage.com/tutorials/interrupts-8051-interrupt-programminghttp://www.engineersgarage.com/tutorials/timers-8051-timer-programming-tutorialhttp://www.engineersgarage.com/microcontroller/8051projects/interface-serialport-RS232-AT89C51 -
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
13/26
Pin Description:
Pin
No
Function Name
1
8 bit input/output port (P1) pins
P1.0
2 P1.1
3 P1.2
4 P1.3
5 P1.4
6 P1.5
7 P1.6
8 P1.7
9 Reset pin; Active high Reset
10Input (receiver) for serial
communicationRxD
8 bit
input/output
port (P3) pins
P3.0
11Output (transmitter) for serial
communicationTxD P3.1
12 External interrupt 1 Int0 P3.2
13 External interrupt 2 Int1 P3.3
14 Timer1 external input T0 P3.4
15 Timer2 external input T1 P3.5
16 Write to external data memory Write P3.6
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
14/26
17 Read from external data memory Read P3.7
18
Quartz crystal oscillator (up to 24 MHz)
Crystal 2
19 Crystal 1
20 Ground (0V) Ground
21
8 bit input/output port (P2) pins
/
High-order address bits when interfacing with external memory
P2.0/ A8
22 P2.1/ A9
23 P2.2/ A10
24 P2.3/ A11
25 P2.4/ A12
26 P2.5/ A13
27 P2.6/ A14
28 P2.7/ A15
29 Program store enable; Read from external program memory PSEN
30
Address Latch Enable ALE
Program pulse input during Flash programming Prog
31
External Access Enable; Vcc for internal program executions EA
Programming enable voltage; 12V (during Flash programming) Vpp
32
8 bit input/output port (P0) pins
Low-order address bits when interfacing with external memory
P0.7/ AD7
33 P0.6/ AD6
34 P0.5/ AD5
35 P0.4/ AD4
36 P0.3/ AD3
37 P0.2/ AD2
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
15/26
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
16/26
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
17/26
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
18/26
CODE LOGIC
To create a particular effect, any of these code(s) can be used in a pattern. For example, shifting the entire
display right (5H) in a loop will keep moving the text to right. To create oscillating text, first keep shifting
the string to right (for say, 8 positions) and then shift it to left. This left-right shifting can be done in an
infinite loop.
Hex Code Command to LCD Instruction Register
1 Clear screen display
2 Return home
4 Decrement cursor
6 Increment cursor
5 Shift display right
7 Shift display left
8 Display OFF, cursor OFF
A Display OFF, cursor ON
C Display ON, cursor OFF
E Display ON, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right80 Force the cursor to the beginning of the 1stline
C0 Force cursor to the beginning of the 2n line
38 Use 2 lines and 5x7 matrix
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
19/26
Here P2is used as output port of the 8051 microcontroller (AT89C51) which sends the data byte to data pins
of the LCD. The control pins (pin 4, 5 & 6) are connected to pins 0, 1 & 6, respectively, of P 3port of the
microcontroller. Pin 3 is connected to apreset of 10k to adjust the contrast on LCD screen.
CODE (ASSEMBLE PROGRAMME OR C PROGRAMME)
// Program to display dynamic text on LCD
#include
#define msec 50
sbit rs=P3^0; //Register select (RS)
sbit rw=P3^1; //Read write (RW) pin
sbit en=P3^6; //Enable (EN) pin
unsigned char commands[]={0x38,0x0E,0x01,0x06,'\0'}; //Command to be sent to LCD
char name[]={"ECE Rocks"}; //String to be displayed on LCD
void delay(unsigned int time) //Time delay function
{
unsigned int i,j;
for(i=0;i
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
20/26
}
void lcdcmd(unsigned char value) //Function for sending values to the command register of LCD
{
P2=value;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
return;
}
void display(unsigned char value) //Function for sending values to the data register of LCD
{
P2=value;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
return;
}
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
21/26
void main()
{
int i,j;
for(i=0;commands[i]!='\0';i++) //Sending string to LCD
{
lcdcmd(commands[i]);
delay(msec);
}
for(j=0;name[j]!='\0';j++)
{
display(name[j]);
delay(msec);
}
while(1)
{
lcdcmd(0x1C); //Shift the entire display to right
delay(75);
}
}
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
22/26
PROTEUS DESIGNED CIRCUIT DIAGRAM
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
23/26
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
24/26
RESULT (SCREEN SHOTS OF RUNNING PROJECT)
-
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
25/26
CONCLUSION
The project was easy to make. The designing and coding of the project was not also much difficult.
However, the components are not readily available in electronics market. The LCD was run short in market
and finally found from old stock of a shop. Most of the microcontrollers available in market are out of order
and there is no replace offered by shop keeper of it. Therefore, we wasted our money for
4microcontrollers and finally the fifth one we purchase was a good microcontroller.
One thing that we got from our experience is that simulation made on proteus is not accurate. When we
simulated the circuit on proteus, the time delay observed was approx. 8 sec. However, practically it is 0.5
sec.
Once the microcontroller is programmed, then the Connections on bread board were not difficult to make.
However initially the LCD didntshow any display. We checked all the components. The components were
in perfect order. After much thought we changed the value of resistance on rheostat which changed the
brightness of LCD. Hence finally the string is displayed and then it moved dynamically to left. In nut
shell, the project is accomplished after a little difficulty in the end and the HEX file is executed well such
that the cursor appears on LCD screen, the cursor increments further such that the string Welcome to
RCETappears. After the string appeared, it moves to left. After a delay of 0.5 sec., the string blinks again
and then move to right and then there comes another delay. This routine continues for an infinite span oftime unless the power supplied to the circuit is disconnected.
APPLICATIONS:
The project have many applications we may see in our daily life. Some of them are as follows:
The ticket booth LCD counters of banks.
Advertisement boards.
News displaying LCD boards installed on traffic signals.
Digital Clocks.
Flight timing displaying boardson airports.
http://www.engineersgarage.com/microcontrollerhttp://www.engineersgarage.com/microcontroller -
8/12/2019 A BRIEF INTRODUCTION TO 8051 MICROCONTROLLER
26/26
REFERENCE
http://www.engineersgarage.com
en.wikipedia.org
http://vediktronics.blogspot.in
http://vj86.hubpages.com
http://www.slideshare.net
http://www.slideshare.net
The 8051 Microcontroller And Embedded Systems Using Assembly And C, 2/E by mazidi
http://www.engineersgarage.com/http://www.engineersgarage.com/http://vediktronics.blogspot.in/http://vediktronics.blogspot.in/http://vj86.hubpages.com/http://vj86.hubpages.com/http://www.slideshare.net/http://www.slideshare.net/http://www.slideshare.net/http://www.slideshare.net/http://www.slideshare.net/http://www.slideshare.net/http://vj86.hubpages.com/http://vediktronics.blogspot.in/http://www.engineersgarage.com/