Microcontroller Exp To Write 6 To 8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

MICROCONTROLLER 8051

· PRACTICAL - 8 • .
Demonstration and study of microcontroller 8051
kit.
Th eor y:
1. A microcontroller 8051 is a complete
computer system built on a single chip.
2. It contains all components like Process
or (CPU), RAM, ROM , Serial port, Parallel
por t, Interrupt logic, Tim er etc. on chip.
·
3. A microcontroller saves cost, saves pow
er consumption and makes the circuit compact.
8051 is an 8-bit microcontroller.
4. On-Chip ROM = 4 KB (Program mem
ory).
5. On-Chip RAM = 128 Bytes (Data mem
ory).
6. Fou r 8 bit bi-directional I/0 ports.

RAM
External memory 4K
Interrupt 128 bytes
control (64 K) program memory
control \ SFR l

CPU

Timer 0
41/0 ports Timer 1
serial

G
(32 llnes)
Input/Output
' (

t 80&1 mlcrocontroller.
Fig, 1. e1ock diagram o
P/30 L_ _ _ _ __ __ _
7 . Serial port.
ounters ~Tim ers) .
8 _ Two 16 bit up-c
q . lt supports interrupt s with twP-k vl'I
prio rit y·
. . H hik rli o ncs , MP3
10. Power saving mod es .
. app \',an~-c~, su l·h ti~ washinp. mal' hines. m 1uo w r1 v c '> , "> .
ed m
\ l . It is us
players etl' .

Fig. 2. 8051 trainer kit.


progress of learning and developing designs
This 8051 trainer kit is proposed to smooth the kit can
J' MC L' from Intel and NXP. This 8051
trainer kit could act as a standalone unit, the
has an opti on to connect
1::. ·:: programmed and eval
uated without using PC. This 8051 trainer kit is
;..,c ·-, 1Ol / 104 keyboard , to enter user program
s in assembl y languages . Serial communication
gned as to
AJ i te ved using 8051 . It also supports
C and assembly language using PC . It's desi
1d.:. iliw e on-board programmer for
NXP 8051 MCU through ISP on serial port.

Ftatuc~ :
1. Operati ng frequt;nc y : IO MH z crystal
l) fo r MC U
2. 40-pi n lC ba,f.;t ! 4')-pin ZIF socket (optiona
3. 32 KB SRAM for user data
4. 32 KB EEPROM for monitor program
5. 2xl6 Char LCD display
6. 24 1/0 pins for (8255)
p,actlcals

7. 32 1/0 pins for 8051 (MCU-P89V 51RD2) P/31

8. 40-pin FRC connector for bus extension


9. 20-pin FRC connector add-on interface from 8255
10. 9-pin DB connector for UART (RS232) interface
11. ISP programmin g for (MCU-P89V 51RD2)
12. 101 PC type keyboard to enter user address/data commands
13. Separate jumper for INT/EXT memory selection
14. Baud rate (Seven different selectable baud rates from 150 to 9600)
15. 8051 microcontro ller with ISP features
16. In circuit programmin g and serial communication through PC
17 . E2PROM with 12 C interface with capacity of 4K
18. RTC with battery back.7.lp
19. One + 5 V relay with isolated O/Ps
20. All interrupts available on header
21. l 6x2 LCD 8 I/Ps from DIP switches
22 . 8 O/Ps available on LED's
23. 4 multiplexed 7-segment displays
24. Win Xp/7 /8/10 based driver software for programming in C external reset switch
25 . On board buzzer.

Power supply requiremen t :


1. +/- 5 V/1 A
2. + /- 12 V/1 A
Steps for program execution on microcontroller 8051 kit :
1 . Connect RS232 serial cable from PC to microcontroller kit.
2. D es1·gn tu.e
1-.. • ·te code on KEIL software in C or Assembly language on PC.
reqms1 ·
3 . Convert the .c or .asm file into the HEX file.
4. Open PLASH MAGIC software.
5. Browse for the location of HEX file ·
6. Start burning the program into microconlrol ler kit.
7. Wait for the uploading a nd finishing.
8. .
After gettmg message o f "'FINISHED " • press reset hutton on the kit to run the program
on board.
P/32
.11 PRACTICAL - 9 . ?'?
ller board.
Testing of general input/output on microcontro
will
devices on microcontroller 8051 kit, we
Theory : To test the input/output ports and in
program of LCD interface in which ; there are four ports PO, Pl, P2 and P3
perform the
8 pins , making them 8-bit port s. All the ports upon RESET are configured
µC8051 each uses port, it must
s. To use any of these ports as an input
as output, ready to be used as output port
be programmed .
ller.
Pin configuration of 8051 /8031 microcontro
I
P1.0 40 Vee
PU 2

P1.2 3 PO.1 (AD1) \I

4 PO.2 (AD2)
P1.3
/~ ' P1 .4 5 PO.3 (AD3)

f P1.5 6 PO.4 (AD4)

34 PO.5 (ADS)
P1.6 7 8 I
P1.7 8 0 33 PO.6 (A06 ) j
RST 9 5 I 32 ·PO.7 (A07 ) _j
'I
10
1 31 EAN PP
( (RXD) P3.0
I 30 ALE/PROG
(TXD) P3.~ 11
8
12 , 29 PSEN c_
I
(INTO) P3.2 0
3 28 P2.7 (A15) ~
-
I _,
i 1NT1) P3.3 13

(TO) P3.4 14 1 27 P2.6 (A14)


I
(T1) P3.5 26 P2.5 (A13)

(WR) P3.6 25 P2 .4 (A12)


' I
- (RD) P3.7 24 P2.3 (A11)

c-·,XTAL2 18 23 P2.2 (A10)

XTAL1 19 22 P2.1 (A9)

GNO 20 21 P2 .0 (AB)
I

Fig. 1. Pin configuration of 8051.


. (pms. 32 - 39) I
Port O : Port O .occupies a total. of 8 pms · t can be used for input or
output. To use the pms of port o as b th .
°
mput and output ports, each pm .
resisto Th' . must be connected
externa11Y to a 10 k ohm pull-up
p r. is ts due to th e f;act that PO is an open drain,
nl'k
u 1 e 1, P2 and P3. Ope n drain is a t . the same way that open
erm used for MOS h"ips m c
Practicals

collector is use d for TT L chi ps. Wi


th ext ern al pul l-up resi stor s con nec
P/3 3 I
configured as an out put por t. For ted upo n rese t, por t 0 is
exa mp le , the foll owi ng cod e will
por t 0 the alte rna ting val ues 55H and con tinu ous ly send out to
AA H
MO V A,# 55H
BA CK : MO V PO.A
AC AL L DE LA Y
CP L A
STh1P BA CK

Port O as Input : Wi th resi stor s


connec ted to por t 0 , in ord er to
port must be pro gra mm ed by writing 1 mak e it an input, the
to all the bits. In the following cod
first as an inp ut por t by wri ting e, por t 0 is con figu red
l ' s to it and then dat a is rec eiv ed
Pl. from the por t and sen t to

PO.O t---t11 ----- +-- -+-- - + - - - + - - - t - - - +


- - - - + --
P0.1
P0.2 1 - - - - --- --- +- --+ p
8 --- +-- -+- --+ -- 0
P0.3 1 - - - - - - -......,.- + -
0 P0.4 1- -- -- -- -- -1-
--- +-- -+- --+ -- r
--+ --- +- --- - t
5 PO.S 1 - - - - - - - - - ---
--.. ....- -+- --+
P0.6 i - - - - - - - - - - - - -- -- +---
1 P0.7 1--- -
- - - - - - - - - -- -- +- -
0

Pull-up resistors = 10 k

Fig. 2. 8051 1/0 ports.


MO V A, #OFFH A = FF hex
MO V PO , A mak e PO an input por t
BACK: MO V A, PO get data from PO
MO V Pl , A sen d it to por t 1
SJMP BA CK
Dual role of port O : Por t 0 is also
designated as ADO - AD 7, allo win g
both address ~.rui data.. Wh en con nec it to be used for
ting an 8051 /31 to an external mem
both add ress and data . The 805 l mul ory , por t 0 pro vid es
tiplexes address and data thro ugh por
indicates if PO has add ress or dat a . t 0 to sav e pin s . AL E
Wh en AL E = 0, it pro vides data
== 1 it has add ress and dat a with DO - D7 . but when AL E
the help of a 74LS373 latch .
Port 1 : Por t 1 occ upi es a tota l of
8 pim, (pins l thro ugh 8) . It can
output. In con tras t to por t 0, this be use d as input or
por t does not need any pull-up resi
stors since it alre ady has
.- -
pull-up resistors internall . co nfi gu red as an ou tpu
y. Upon reset, po rt 1 ts t po rt. Fo r ex am ple ,
the following code will co AAh
ntinuously send ou t to po 1 the alt ern ati ng values
rt 55h &
MOY A. #SSH ; A = 55 hex
BACK: MOV P 1. A ; sen
d it to Port l
ACALL DELAY : call delay routine
CPL A ; make A= O
SJMP BACK
Port l as input : To make
port 1 an input po rt, it mu
l to all its bits . In the st be pro gra mm ed as suc
following code, po rt 1 is h by wr~t~ng
l · s to it. then data is rec co nfi gured first as an inp ut po
eived from the port and rt by wn tm g
saved in R7 , R6 & R5.
MOV A. #OFFH : A= FF HEX
r-.,10\7 Pl . A ; make P 1 an input po rt
by writing all l's to it
M OV A. Pl ; get data from Pl
MOV R7. A ; save it in register R7
ACALL DELAY ; wait
MOV A , Pl ; get another data fro m P
1
M OY R6. A ; save it in register R6
ACALL DELAY ; wait
M OV A. Pl ; get another data from P
1
MOV RS , A ; save it in register R5
Port 2 : Po rt 2 occupies
a total of 8 pins (pins 21
Just lik e Pl , P2 does not - 28). It ca n be us ed as
need any pull-up resistors inp ut or ou tpu t.
Up on reset, po rt 2 is co since it already has pull-u
nfigured as an output po p resistors internally.
out continuously to po rt rt. Fo r ex am ple , the fol low
2 the alternating values 55 ing co de wi ll sen d
toggle continuously. h and AA H. Th at is all
the bit s of po rt 2
MOV A, #SSH ; A = 55 hex
BA CK : MOY P2, A ;
send it to Po rt 2
ACALL DELAY ; call delay routine
CPL A ; make A = O
SJMP BACK

_Po~ 2 a~ input : T~ ma
ke port 2 an. input, it mu
~11 its bits. In _the f~llow,~g st pro gra mm ed as su ch
code, port 2 1s _configured by wn tm g 1 to
1t. Th en data 1s received fro first as an input po rt by
m that port and 1s sent to wr iti ng 1's to
MOY A, #0FPH
Pl co nti nu ou sly .
; /. = PP hex
MOV P2 , A ; make P2 an input port by
writing all l's to it
Practicals
BACK: MOV A, P2 ; get data from P2 P/35

MOV Pl, A ; send it to portl


SJMP BACK ; keep doing that
Dual role of port 2 : In systems based on the
8751, 8951 and D55000. P2 is used as
simple 1/0. However , in 8031-based systems,
port 2 must be used along with PO to provide
the 16-bit address for the external memory. As
shown in pin configuration 8051. port 2 is also
designed as AS - A15, indicating the dual function.
Since an 8031 is capable of accessing 64K
bytes of external memory, it needs a path for
the 16 bits of the address. While PO provides
the lower 8 bits via AO - A7, it is the job of
P2 to provide bits AS - A15 of the address. In
other words, when 8031 is connected to external
memory, P2 is used for the upper 8 bits of
the 16 bit address and it cannot be used for I/0.

Port 3 : Port 3 occupies a total of 8 pins, pins 10


through 17. It can be used as input or
output. P3 does not need any pull-up resistors,
the same as Pl and P2 did not. Although, port
3 is configured as an output port upon reset.
Port 3 has the additional function of providing
some extremely important signals such as interrupt
s. This information applies to both 8051 and
8031 chips.

Port 3 alternate functions

P3 BIT Function PIN


P3.0 RXD 10
P3.l TXD 11
P3.2
--
INTO 12
P3.3
--
INTl 13
P3.4 TO 14
P3.5 TI 15
P3.6
-
WR 16
P3.7
-
RD 17
Functions of port 3
P3.0 and P3. l are used for the RxD and TxD
serial communication signals. Bits P3.2 and
P3.3 are set aside for external interrupts. Bits
P3.4 and P3.5 are used for timers 0 and 1.
Finally, P3. 6 and P3. 7 are used to provide the
WR and RD signals of external memories
connected in 8031 based systems.
\
Example : Seven segment display interfacing with
microcontroller 8051.
I To test the output ports and devices on the microcon
is interfaced with the 8051. To display numeric valu
First, we will interface a seven segment to 8051
troller board, the seven segment display
es we nonnally use seven segment displays .
and display a single digit decimal counter
(0 - 9).
Eagle's PLC & Microcontrollers

P/36 I name 7 segmen ts imp Y ·


.
l there are 7 LED segments
.
Seven segment display : Well, the 11er.
' .
, easies t interfaces to a m1crocontro
yed
After LEDs, these are the d'
arranged as shown in Fig. 3. 1a ·
There is also a decimal point or dp . It is used when decimal digits like 5.1 etc are tsp

Fig. 3.

Since. these are basically LEDs arranged as a group they can either have the anode
in
common or cathode thus they are named as common anode/common cathode display s.
n
1. Common cathode : In this type of segments, all the cathode terminals are made commo
and tied ro GND . Thus , the segments a tog need a logic high signal (5 V)
in order to glow.
n
2. Common anode : In this type of segments, all the anode terminals are made commo
in order to
and tied to VCC (5 V). Thus, the segments a to g need a logic low signal (GND)
glow .

Common cathode a b c d e f g

a
f
b C d e f g
Common anode

Fig. 4.
seven
Below table shows the binary /hex values for displaying the digits on common anode
~gmeru display.

Digit h g I e d C b a Hex value


0 1 1 0 0 0 0 0 0 OxCO
J 1 1 J 1 l 0 0 1 OxF9
2 1 0 1 0 0 1 0 0 0xA4
3 1 0 1 1 0 0 0 0
4 1
OxBO
0 0 1 l 0 0 l
5 1 ()
Ox99
0 J ()
0 l 0
6 l () 0
Ox92
0 0 0 l 0
7 1 1 1 1
Ox82
I 0 0 0
8 1 0 0 0 OxF8
0 0 0 0
9 I 0 0 l Ox80
0 0 0 0 Ox90
practlcala
Hardware connection : Bel ow image sho P/3_7 I
ws the hardware connection as per the
tabl e.
-; _ :--tJ I
,; 1 '

-
!
C . d . ·I -
.
'B h
.I CO M/S ,
P2.0 P2. l P2. 2 P2. 3 -
- P2. 4 P2. 5 P2. 6 P2. 7 vcc

. 5 7 seg men t display interfacing


F 19 . . circuit with 8051.

Program code
#include < reg 5 l.h >
• d int ms count)
void dela y _ms (un sign e -
{
uns igne d int i ,j;
for (i =0 ~ i<m s_c oun t;i+ +)

{
for (j =0~ J· < 100·' J. + +)

}
}
Int main( )
{ bO O 99 Ox92 Ox8 2.0x f8,0 x80 ,0x90} ;
Oxf9 ' Oxa4,0x. , x ' '
cha r seg_ co d e l ] -- {o xcO'
int i;
Eagle's PLC & Mlcrocontrollers
P/38
while(l)
{
for (i - O; < = 9; i + +) // loop to display 0-9
{
P2 = seg_code[i];
Delay _ms(lOOO);
}
}
}

. __]l PRACTICAL - 10 • ri
Controlling of LEDs using microcontroller program.
Theory : Microcont roller boards LED in 8051 trainer board works by turning ON a LED,
and then turning it OFF and then looping back to START. However, the operating speed of
microcont roller is very high, so the flashing frequency will also be very fast to be detected by
human eye.

LIGHT EMI'ITING DIODE :


Light Emitting Diode (LED) is the most commonly used components, usually for displaying
pins digital states. Typical uses of LEDs include alarm devices, timers and confirmat ion of user
input such as a mouse click or keystroke.

INTERFA CING LED : Fig. 1 shows how to interface the LED to microcont roller. As you
\ can see the anode is connected through a resistor to GND and the cathode is connected to
the microcont roller pin. So, when the port pin is HIGH the LED is OFF and when the port pin
is LOW the LED is turned ON.
LD6
Mlcrocontroller j(j(
port pin
R25
2.2 k

Fig. 1. Interfacing LED to mlcrocontroller.

INTERFA CING LED WITH 8051 : LED in 8051 trainer board works by turni ON
a LED and then turning it OFF and then looping back to START · However , the Operat'mgngspeed
. . .
of microcont roller is very high, so the tlashmg frequency will also be very fast to be detected
by human eye .
Practicals
Pin assignment with 8051 L P/39
Point LEDs 8051 lines LED selection
Digital LEDl P3 .0
outputs LED2 P3 . l
LED3 P3.2 LED1
A1 330E
LED4 P3 .3 • ~# Vvv J11,
LED5 P3.4 Make pin high - LED On
Make pin low - LED Off
LED6 P3 .5
LED7 P3 .6
LEDS P3.7
. . .
C1rcwt diagram to interface led with 8051
vcc
C11
LED1
j(j(
U7 ~
LED2
C j(j(
zC!)
LED3
17
j(j(
P3.7/RD ,-..,:-:-- ~ . . . . . J
16
P3.67WA t-:-:o-- ~ , - - ,
14
~5-~;-- ......
P3.5/T1 t-1 LED4 R18
P3.4/TD t--:i-;:;-~ ~ - - - - , j(j(
VCC P3.3/lfm 13 '----~--,
P3.2/INT0 1 121 LEDS .______,.....,,.,""~
P3.1/TXD t-;-,;,. -~c__. ,
-.:...=.:.-
~l
I
3
l1 10 µF
P3.0/RX D 1-=
10 j(j(
LED6
j(j( 330E
9 8051
R T
~ ~ RST LED7
,.__,r--- - ~
j(j(
R8 E
AL:-:-:
ALE r.3=0~ =
19 X1
8K2 PSEN r=---'-'S=E=N LEDS
X1 EA 1431--
1_ A .____ _
;;;;;;..;
E ...,_._'Jf_ _ .....J

□ 18 X2
10 MHz
C18 C19
~ 22PF

Fig. 2.

-
Assembly program to On and Off LEDs using 8051
MEMORY ADDRESS OPCODE MNEMONICS
~

9100 74 55 Ll:MOV A, #FF


9102 7C MOV BO. A

....__ 9104 12 91 OF LCALL DELAY


}'/ 40 - --
p MNEMONICS
-·-- ··
..
ME MORY ADDRESS OPCODE
MO V A, #00
9107 74 00
MO V BO, A
9109 7C
LCA LL DE LA Y
910b 12 91 OF
SJM P Ll
910D 80 F9
DEL AY : MO V R5 , #05
910 F 7D 05
H3 MO V R4, #FF
9111 7C FF
7B FF H2 MO V R3, #FF
9113
DB FE Hl: DJN Z R3 , Hl
9115
DC FA DJN Z R4, H2
9117
DD F6 DJN Z R5 , H3
9119
22 RET
I 911B
L
C Lan gua ge Program :
#inc Jude < reg5 l .h >
all bits of P3
#de fi neL ED P3 // LED 's are connected to
vo!ctDELA Y _ms(unsignedint ms_Count)
-(

unsignedint i ,j;
fo r(i =0; i < ms_Cou nt;i + +)
f
l

for(j =0; j < lOO;j + + );


\
f
I
f
int1 11c1in( )
J
ut
P3 = (Oxff < < LED); II Configure POR T3. 0 to POR T.7 as outp
while (1)
f
I

P3 = (Ox ff< <LE D); I/ Tur n ON Led ' s con nec ted to P3
DEL AY ms(lOOO); // Wait for som e time
P3 = (OxOO< < LED); // Tur n OFF Led con nec ted to P3
DEL AY _ms(lOOO); I I Wai t for som e time
)
J

returnO;
}

You might also like