Microcontroller Exp To Write 6 To 8
Microcontroller Exp To Write 6 To 8
Microcontroller Exp To Write 6 To 8
· 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' .
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
4 PO.2 (AD2)
P1.3
/~ ' P1 .4 5 PO.3 (AD3)
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
GNO 20 21 P2 .0 (AB)
I
Pull-up resistors = 10 k
_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
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.
-
!
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
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.
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
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
~
unsignedint i ,j;
fo r(i =0; i < ms_Cou nt;i + +)
f
l
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;
}