0% found this document useful (0 votes)
23 views31 pages

Overview of 8051 Microcontroller Features

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views31 pages

Overview of 8051 Microcontroller Features

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Introduction to Microcontroller 8051

The most universally employed set of microcontrollers come from the 8051 family. 8051
Microcontrollers persist to be an ideal choice for a huge group of hobbyists and experts. In the
course of 8051, the humankind became eyewitness to the most ground- breaking set of
microcontrollers. The original 8051 microcontroller was initially invented by Intel. The two
other members of this 8051 family are-

 8052-This microcontroller has 3 timers & 256 bytes of RAM. Additionally it has all the
features of the traditional 8051 microcontroller. 8051 microcontroller is a subset of 8052
microcontroller.
 8031 - This microcontroller is ROM less, other than that it has all the features of a traditional
8051 microcontroller. For execution an external ROM of size 64K bytes can be added to its
chip.

8051 microcontroller brings into play 2 different sorts of memory such as - NV- RAM,
UV - EPROM and Flash.

8051 is the basic microcontroller to learn embedded systems projects.

FEATURES OF 8051

8051 microcontroller is an eight bit microcontroller launched It


is available in 40 pin DIP (dual inline package). It has 4kb of ROM (on-
chip programmable space) and 128 bytes of RAM space which is inbuilt, if desired 64KB of
external memory can be interfaced with the microcontroller. There are four parallel 8 bits ports
which are easily programmable as well as addressable. An on-
chip crystal oscillator is integrated in the microcontroller which has crystal frequency of
12MHz. In the microcontroller there is a serial input/output port which has 2 pins. Two
timers of 16 bits are also incorporated in it; these timers can be employed as timer for i
nternal functioning as well as counter for external functioning.

The microcontroller comprise of 5 interrupt sources namely- Serial Port


Interrupt, Timer Interrupt 1, External Interrupt 0, Timer Interrupt 0, External Interrupt 1.

The programming mode of this micro-controller includes GPRs (general purpose registers),
SFRs (special function registers) and SPRs (special purpose registers).
INTERNAL ARCHITECHURE OF 8051 MICRO-CONTROLLER

1. ALU

All arithmetic and logical functions are carried out by the ALU.
Addition, subtraction with carry, and multiplication come under arithmetic operations.
Logical AND, OR and exclusive OR (XOR) come under logical operations.

2. Program Counter (PC)

A program counter is a 16-bit register and it has no internal address. The basic function of
program counter is to fetch from memory the address of the next instruction to be executed. The
PC holds the address of the next instruction residing in memory and when a command is
encountered, it produces that instruction. This way the PC increments automatically, holding the
address of the next instruction.
3. Registers

Registers are usually known as data storage devices. 8051 microcontroller has 2 registers,
namely Register A and Register B. Register A serves as an accumulator while Register B
functions as a general purpose register. These registers are used to store the output of
mathematical and logical instructions. The operations of addition, subtraction, multiplication and
division are carried out by Register A. Register B is usually unused and comes into picture only
when multiplication and division functions are carried out by Register A. Register A also
involved in data transfers between the microcontroller and external memory.
PIN DIAGRAM OF 8051 MICRO-CONTROLLER

Fig. Pin Diagram of 8051


PINOUT DESCRIPTION

Pins 1-8: Port 1 Each of these pins can be configured as an input or an output.

Pin 9: RS A logic one on this pin disables the microcontroller and clears the contents of most
registers. In other words, the positive voltage on this pin resets the microcontroller. By applying
logic zero to this pin, the program starts execution from the beginning.

Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions:

Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication
output.

Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication
clock output.

Pin 12: INT0 Interrupt 0 input.

Pin 13: INT1 Interrupt 1 input.

Pin 14: T0 Counter 0 clock input.

Pin 15: T1 Counter 1 clock input.

Pin 16: WR Write to external (additional) RAM.

Pin 17: RD Read from external RAM.

Pin 18, 19: X2 X1 Internal oscillator input and output. A quartz crystal which specifies
operating frequency is usually connected to these pins. Instead of it, miniature ceramics
resonators can also be used for frequency stability. Later versions of microcontrollers operate at
a frequency of 0 Hz up to over 50 Hz.

Pin 20: GND Ground.

Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are
configured as general inputs/outputs. In case external memory is used, the higher address
byte,
i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of 64Kb is
not used, which means that not all eight port bits are used for its addressing, the rest of them are
not available as inputs/outputs.
Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it
every time the microcontroller reads a byte from memory.

Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address
byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the
external register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state of P0 and
uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous
logic state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by
means of only one additional (and cheap) integrated circuit. In other words, this port is used for
both data and address transmission.

Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. It means that even there
is a program written to the microcontroller, it will not be executed. Instead, the program written
to external ROM will be executed. By applying logic one to the EA pin, the microcontroller will
use both memories, first internal then external (if exists).

Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as
general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin
is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0).

Pin 40: VCC +5V power supply.


Introduction to Microcontroller Lab

Microcontroller Lab is mainly used with 15EE52 course. The Lab has following equipments.

Software tools used

1. Keil uVision 5
2. Flash Magic

Application of Microcontroller in Day to Day Life Devices:

 Light sensing & controlling devices


 Temperature sensing and controlling devices
 Fire detection & safety devices
 Industrial instrumentation devices
 Process control devices

Application of microcontroller in Industrial Control Devices:

 Industrial instrumentation devices


 Process control devices
Tools used in Microcontroller Lab

1. Keil Micro vision 3


Procedure to start up with Keil Micro Vision 3
Starting Micro vision 3
Click on keil Micro Vision icon on the desktop

b) Loading a project into Micro Vision 3


Click on Project menu, Select Close Project if any Projects are Present or Select New
Project from
the drop – down menu. Enter the filename and Click on OK
Double Click on ATMEL from the wizard then select AT89c51 and Press OK
Micro vision 3 will load 8051 Microcontroller Projects file and Display as :
c) Editing and Assembling

Type the program in the work space window. Now save the file and right click source
group 1
Select Add files to group source group Let the files be in ASM.
Select the corresponding file from the list and click OK.

To assemble select build target, if no error(s) are found the output window will display.

(0) Error(s) , (0)Warning (s).

If error(s) are found then select Rebuild Target and then the Programmer will find it easy
to correct the error(s).
d) Debugging
To debug Click on debug button.

For memory display, select Memory window icon under View option. Enter the bytes(s)
at memory window (address). Now Click on Run button to run the program continuously. After
debugging ends the value will be stored in registers memory and will also be displayed in
memory window.
2. Flash Magic

Generally we use ISP (In System Programming) when it comes to micro controllers
with flash [Link] of the basic software for such purpose is FLASH MAGIC .
Steps:
1. Click on the icon “flash magic”.

2. Following window will appear.


[Link] in this window select the following

COM Port: COM 1

Baud Rate: 9600

Device: 89LV51RD2

Select the option “Erase all Flash”.


4. Click on “browse” and select the .hex file to be loaded on the chip.

5. Click on “start” and following window will appear and it will ask

“reset the device into ISP mode now”.

6. Now press the “reset” switch which is on flash board.

7. Now the software starts programming the device.


8. After completion of loading .hex file into chip, it will show as “finished”.

9. Now press “reset” switch from flash board and the device starts executing the program loaded in
it.
1a) Write an ALP to move a block of data from one internal memory location to other.

Label Opcode and Operands Comments


ORG 0000H

LJMP 8000H

ORG 8000H
MOV R0,#30H ;r0=30h i.e. initial block memory location
;r1=40h i.e. block memory location where data has to
MOV R1,#40H
transfer
MOV R2,#05H ; load counter as 05h (n) in register r2
;copy the contents of memory location pointed by register
NEXT: MOV A,@R0
r0 into A
;copy the contents of register A into memory location
MOV @R1,A
pointed by reg r1
INC R0 ;increment register r0
INC R1 ;increment register r1
DJNZ R2, NEXT ;decrement register r2 if not equal to zero jump to next
LCALL 0003H ;end of asm file

INPUT OUTPUT
1b) Write an ALP to move a block of data from one external memory location to other

Label Opcode and Operands Comments


ORG 0000H

LJMP 8000H

ORG 8000H
MOV R0,#04H ;load the counter as 04h (n) in register r0
MOV R1,#81H ;higher byte of initial block=81h in register r1
MOV R2,#85H ;higher byte of memory location where data has;to
transfer=85h in reg r2
MOV R3,#00H ;lower byte of both initial and final block=00h in register r3
UP: MOV DPH,R1 ;DPH=contents of register r1
MOV DPL,R3 ;DPL=contents of register r3
MOVX A,@DPTR ;copy the contents of memory location pointed by DPTR
into reg A
MOV DPH,R2 ;dph=contents of register r2
MOVX @DPTR,A ;copy the contents of reg A into memory location pointed
by reg dptr
INC R3 ;increment register r3
DJNZ R0,UP ;decrement register r0 if not equal to zero jump to up
LCALL 0003H ;end of asm file

INPUT OUTPUT

2 Arithmetic instructions: Addition, subtraction, multiplication and division.


Square and cube operations for 16 bit numbers.
2a) Write an ALP to find addition of two 8 bit numbers.
2b) Write an ALP to find subtraction of two 8 bit numbers.
2c) Write an ALP to find multiplication of two 8 bit numbers.
2d) Write an ALP to find division of two 8 bit numbers.
2e) Write an ALP to square of a 8 bit numbers.
2f) Write an ALP to cube of a 8 bit numbers.
2g) Write an ALP to find addition of two 16 bit numbers.
2h) Write an ALP to find subtraction of two 16 bit numbers.
2i) Write an ALP to square of a 16 bit numbers.
2a) Write an ALP to find addition of two 8 bit numbers.

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H ;dptr=contents of 8500h
MOVX A,@DPTR ;get the lower byte from memory location 8103h in register
A
MOV R0,A ;store in register r0
INC DPTR ;increment dptr
MOVX A,@DPTR ;get the lower byte from memory location 8101h in register
A
ADDC A, R0 ;add first lower byte and second lower byte
JNC NEXT ;jump if no carry to here
INC R5 ;if carry then increment register r5
NEXT MOV DPTR,#9001H ;DPTR=9001h
:
MOVX @DPTR,A ;dptr=store the lower byte in memory location 9101h
MOV A,R5 ;store the contents of r5(carry) in register A
DEC DPL ;decrement DPL i.e. DPTR=9000h
MOVX @DPTR,A ;store the carry in memory location in 9000h
LCALL 0003H ;end of asm file

INPUT OUTPUT
2b) Write an ALP to find subtraction of two 8 bit numbers.

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H ;dptr=contents of 8500h
MOVX A,@DPTR ;get the lower byte from memory location 8500h in register
A
MOV R0,A ;store in register r0
INC DPTR ; increment dptr
MOVX A,@DPTR ;get the lower byte from memory location 8501h in register
A
SUBB A,R0 ;sub content of r0 from a
JNC NEXT ;jump if no carry to here
INC R5 ;if carry then increment register r5
NEXT: MOV DPTR,#9001H ;DPTR=9001h
MOVX @DPTR,A ;dptr=store the lower byte in memory location 9001h
MOV A,R5 ;store the contents of r5(carry) in register A
DEC DPL ;decrement DPL i.e. DPTR=9100h
MOVX @DPTR,A ;store the carry in memory location in 9100h
LCALL 0003H ;end of asm file

INPUT OUTPUT
2c) Write an ALP to find multiplication of two 8 bit numbers.

Label Opcode and Operands Comments


ORG 0000H

LJMP 8000H

ORG 8000H
MOV DPTR,#8500H ;dptr=8500h
MOVX A,@DPTR ;store the number in register a from memory location
8500h
MOV B,A ;copy the number in register B
INC DPTR ;dptr=8501h
MOVX A,@DPTR ; store the number in register a from memory location
8501h
MUL AB ;multiply A and B
INC DPTR ;increment DPTR
MOVX @DPTR,A ;store the higher byte in memory location in 8501h
MOV A,B ;copy the contents of register b in register a
INC DPTR ;increment DPTR
MOVX @DPTR,A ;store the lower byte in memory location 8502h
LCALL 0003H ;end of asm file

INPUT OUTPUT
2d) Write an ALP to find division of two 8 bit numbers.

Label Opcode and Operands Comments


ORG 0000H

LJMP 8000H

ORG 8000H
MOV DPTR,#8500H ;dptr=8501h
MOVX A,@DPTR ;store the number in register a from memory location
8500h
MOV B,A ;copy the number in register B
DEC DPL ; dptr=8500h
MOVX A, @DPTR store the number in register a from memory location 8501h
DIV AB ;divide A by B
MOV DPTR, #9500H ;increment DPTR
MOVX A, @DPTR ;store the quotient in memory location in 8501h
MOV A,B ;store the reminder in register b
INC DPTR ;increment DPTR
MOVX @DPTR,A ;store the reminder in memory location 8502h
LCALL 0003H ;end of asm file

INPUT OUTPUT
2g) Write an ALP to find addition of two 16 bit numbers.

Opcode and
Label Comments
Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8503H ;dptr=contents of 8503h
MOVX A,@DPTR ;get the lower byte from memory location 8503h in register A
MOV R1,A ;store content of A in register r1
MOV DPTR,#8501H ;dptr=contents of 8501h
MOVX A,@DPTR ;get the lower byte from memory location 8501h in register A
ADD A, R1 ;A=A+R1
MOV DPTR,#9002H ; DPTR= 9002h
MOVX @DPTR,A ; 9002H=A
MOV DPTR,#8502H ; DPTR= 8502h
MOVX A,@DPTR ;A= content of 8502h
MOV R2,A ; R2=A
MOV DPTR,#8500H ; DPTR= 8500h
MOVX A,@DPTR ; A=content of 8500H
ADDC A, R2 ;A=A+R2+C
JNC NEXT ;jump if no carry to next
INC R7 ;if carry then increment register r7
NEXT: MOV DPTR,#9001H ;DPTR=9001h
MOVX @DPTR,A ;dptr=store the lower byte in memory location 9001h
DEC DPL ;decrement DPL i.e. DPTR=9000h
MOV A,R7 ; A=R7
MOVX @DPTR,A ;store the carry in memory location in 9000h
LCALL 0003H ;end of asm file

INPUT OUTPUT
2h) Write an ALP to find subtraction of two 16 bit numbers.

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8503H ;dptr=contents of 8503h
MOVX A,@DPTR ;get the lower byte from memory location 8503h in register
A
MOV R1,A ;store content of A in register r1
MOV DPTR,#8501H ;dptr=contents of 8501h
MOVX A,@DPTR ;get the lower byte from memory location 8501h in register
A
SUBB A, R1 ;A=A+R1
MOV DPTR,#9002H ; DPTR= 9002h
MOVX @DPTR,A ; 9002H=A
MOV DPTR,#8502H ; DPTR= 8502h
MOVX A,@DPTR ;A= content of 8502h
MOV R2,A ; R2=A
MOV DPTR,#8500H ; DPTR= 8500h
MOVX A,@DPTR ; A=content of 8500H
SUBB A, R2 ;A=A+R2+C
JNC NEXT ;jump if no carry to next
INC R7 ;if carry then increment register r7
NEXT: MOV DPTR,#9001H ;DPTR=9001h
MOVX @DPTR,A ;dptr=store the lower byte in memory location 9001h
DEC DPL ;decrement DPL i.e. DPTR=9000h
MOV A,R7 ; A=R7
MOVX @DPTR,A ;store the carry in memory location in 9000h
LCALL 0003H ;end of asm file

INPUT OUTPUT
3a) Write an ALP to generate Hex up counter.

Opcode and
Label Comments
Operands
ORG 0000H
LJMP 8000H
ORG 8000H
MOV A,#00H ;load the accumulator with 00H
UP: LCALL DELAY ;call delay
INC A ; increment accumulator by 1
CJNE A,#40H,UP ;compare accumulator with 40h if not equal jump up
LCALL 0003H ; end
DELAY: MOV R0,#0FFH ; load r0 by FFH
BACK1: MOV R1,#0FFH ; load r1 by FFH
BACK: MOV R2,#0FFH ; load r2 by FFH
HERE: DJNZ R2,HERE ; decrement r2 if not equal to zero jump here
DJNZ R1, BACK ;decrement r1 if not equal to zero jump Back
DJNZ R0,BACK1 ;decrement r0 if not equal to zero jump Back1
RET ;return to main

INPUT OUTPUT
6a) Write an ALP to convert hexadecimal number to decimal number.

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H ;dptr=8500h
MOVX A,@DPTR ;copy the contents of memory location pointed by DPTR into
register A
MOV B,#64H ;B=64H
DIV AB ;division A/B
INC DPTR ;increment DPTR=8501H
MOVX @DPTR,A ;copy the contents of memory location pointed by DPTR into
register A
MOV A,B ; move the content of B into A register
MOV B,#0AH ;Store the number 0AH into register B
DIV AB ; division A/B
INC DPTR ; increment DPTR=8502H
MOVX @DPTR,A ; store the contents of register A in memory location pointed
by DPTR
INC DPTR ;increment DPTR=8503H
MOV A,B ;move the content of B into A register
MOVX @DPTR,A ; store the contents of register A in memory location pointed
by DPTR
LCALL 0003H ;end of asm file

INPUT OUTPUT
6b) Write an ALP to convert decimal number to hexadecimal number.

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H ;dptr=8500h
MOVX A,@DPTR ;copy the contents of memory location pointed by DPTR
into reg A
MOV B,#64H ;B=64H
MUL AB ;multiply A and B
MOV R2,A ;store the contents of A in register r2
INC DPTR ;increment DPTR=8501H
MOVX A ,@DPTR ;copy the contents of memory location pointed by DPTR
into register A
MOV B,#0AH ;Store the number 0AH into register B
MUL AB ; division A/B
MOV B,R2 ;store the contents of R2 in register B
ADD A,B ;add register A and B
MOV B,A ;store the contents of A in register B
INC DPTR ; increment DPTR=8502H
MOVX A,@DPTR ; copy the contents of memory location pointed by DPTR
into register A
ADD A,B ;add register A and B
INC DPTR ;increment DPTR=8503H
MOVX @DPTR,A ; store the contents of register A in memory location
pointed by DPTR
LCALL 0003H ;end of asm file

INPUT OUTPUT
6c) Write an ALP to convert packed BCD number to ASCII number.

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H ;dptr=8500h
MOVX A,@DPTR ;store the contents of memory location pointed by DPTR
into register A
MOV R0,A ;move the content of A to r0.
ANL A,#0FH ;make logical AND function with register A and immediate
data 0FH
ORL A,#30H ;make logical OR function with register A and immediate
data 30H
INC DPTR ;increment DPTR
MOVX @DPTR,A ;save the result in memory location 8501H
MOV A,R0 ;get the once again BCD number in register A
ANL A,#0F0H ;make logical AND function with reg A and immediate
data 0F0h
SWAP A ;swap the contents of register A
ORL A,#30H ;make logical OR function with reg A and immediate data
30H
INC DPTR ;increment DPTR
MOVX @DPTR,A ;save the result in memory location 8502H
LCALL 0003H ;end of asm file

INPUT OUTPUT
6d) Write an ALP to convert ASCII number to BCD number

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV DPTR,#8500H ;dptr=8500h
MOVX A,@DPTR ;store the contents of memory location pointed by DPTR
into reg A
ANL A,#0FH ;make logical AND function with register A and immediate
data 0FH
MOV B,A ;store in register B
INC DPTR ;increment DPTR
MOVX A,@DPTR ;get the second ASCII number in reg A from memory
location 8501H
ANL A,#0FH ;make logical AND function with reg A and immediate
data 0F0h
SWAP A ;swap the contents of register A
ORL A,B ;make logical OR function with register A and B
INC DPTR ;increment DPTR =8502H
MOVX @DPTR,A ;save the result(BCD Number.) in memory location 8502H
LCALL 0003H ;end of asm file

INPUT OUTPUT

You might also like