You are on page 1of 49

Interfacing with 8051

LED Interfacing to Microcontroller


common cathode
Calculate the value of Delay ??
org 0h delay: mov r0,#03h
ljmp main l1: mov tmod,#01h
mov th0,#00h
org 100h
mov tl0,#00h
main: mov p2,#00h setb tr0
acall delay here: jnb tf0,here
mov p2,#0ffh clr tf0
acall delay clr tr0
sjmp main djnz r0,l1
end ret
Common Anode
Debug the Code . . .
org 0000h delay: mov r0,#03h
jmp Start l2: mov tmod,#01h
mov th0,#00h
org 0100h
mov tl0,#00h
Start: mov a,#0ffh setb tr0
l1: mov p2,a here: jnb tf0,here
acall delay clr tf0
dec a clr tr0
sjmp l1 djnz r0,l2
END ret
7 segment display
Common Anode
org 0h delay: mov r0,#4
sjmp main
l1: mov r1,#255
org 10h
db l2: mov r2,#255
0c0h,0f9h,0a4h,0b0h,099h,092h,082h,0f8h,080h,98h
here: djnz r2,here
org 30h
main: mov dptr,#0010h
djnz r1,l2
l3: mov a,#00h djnz r0,l1
movc a,@a+dptr ret
mov p2,a
acall delay
inc dptr
mov a,dpl
cjne a,#1ah,l3
sjmp main
end
Common Cathode
org 0h delay: mov r0,#4
sjmp main l1: mov r1,#255
org 10h l2: mov r2,#255
db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,67h
here: djnz r2,here
org 30h
djnz r1,l2
main: mov dptr,#0010h
l3: mov a,#00h
djnz r0,l1
movc a,@a+dptr ret
mov p2,a
acall delay
inc dptr
mov a,dpl
cjne a,#1ah,l3
sjmp main
end
Multiplexed 7 segment
ORG 0H NEXT5: CLR TF0 CJNE A,#0AH,NEXT3
MAIN: MOV DPTR,#MY CJNE R5,#0CH,NEXT6 MOV @R0,#0
MOV TMOD,#11H ACALL VALUE NEXT1: NOP
MOV TH0,#0H NEXT6: SJMP LOOP NEXT2: NOP
MOV R5,#0 NEXT3: NOP
MOV TL0,#0H VALUE: MOV R0,#10H
MOV A,@R0 NEXT: MOV @R0,A
SETB TR0 CLR TF0
INC A
CJNE A,#0AH,NEXT MOV TH0,#0H
LOOP: MOV R7,#077H
MOV TL0,#0H
MOV R6,#04H MOV @R0,#0
MOV R0,#10H MOV R5,#0H
INC R0
HERE: MOV A,R7 RET
MOV A,@R0
MOV P2,A INC A
RL A DELAY: MOV TH1,#0DCH
CJNE A,#0AH,NEXT1 MOV TL1,#0
MOV R7,A
MOV A,@R0 MOV @R0,#0 SETB TR1
MOVC A,@A+DPTR INC R0 HERE3: JNB TF1,HERE3
MOV P1,A MOV A,@R0 CLR TR1
ACALL DELAY INC A CLR TF1
INC R0 CJNE A,#0AH,NEXT2 RET
DJNZ R6,HERE MOV @R0,#0 ORG 0090H
JNB TF0,NEXT5 INC R0 MY:DB 0c0h,0f9h,0a4h,0b0h,099h,092h,082h,
INC R5 MOV A,@R0 0f8h, 080h,98h
INC A END
3 x 3 keypad
label5: mov a,r1 mov a,#08h
org 0000h
cjne a,#0ddh,label6 movc a,@a+dptr
mov dptr,#data1
label1: mov p1,#0feh mov a,#04h mov p2,a
mov r1,p1 movc a,@a+dptr label10: mov p1,#0f7h
mov a,r1 mov p2,a mov r1,p1
cjne a,#0eeh,label2 label6: mov a,r1 mov a,r1
mov a,#00h cjne a,#0bdh,label7 cjne a,#0e7h,label11
movc a,@a+dptr mov a,#05h mov a,#09h
mov p2,a movc a,@a+dptr movc a,@a+dptr
label2: mov a,r1 mov p2,a
mov p2,a
cjne a,#0deh,label3
label7: mov p1,#0fbh label11: mov a,r1
mov a,#01h
movc a,@a+dptr mov r1,p1 cjne a,#0d7h,label12
mov p2,a mov a,r1 mov a,#0ah
label3: mov a,r1 cjne a,#0ebh,label8 movc a,@a+dptr
cjne a,#0beh,label4 mov a,#06h mov p2,a
mov a,#02h movc a,@a+dptr label12: mov a,r1
movc a,@a+dptr mov p2,a cjne a,#0b7h,label13
mov p2,a mov a,#0bh
label8: mov a,r1
label4: mov p1,#0fdh movc a,@a+dptr
cjne a,#0dbh,label9
mov r1,p1 mov p2,a
mov a,r1 mov a,#07h
cjne a,#0edh,label5 movc a,@a+dptr label13: ljmp label1
mov a,#03h mov p2,a org 100h
movc a,@a+dptr label9: mov a,r1 data1: db 0f9h,0a4h,0b0h,099h,092h,082h,0f8h,080h,
mov p2,a cjne a,#0bbh,label10 090h,0c0h,0c0h,0c0h
END
Types of Displays
16×2 LCD module
• 16×2 LCD module is a very common type of LCD module that is used in 8051
based embedded projects.
• It consists of 16 rows and 2 columns of 5×7 or 5×8 LCD dot matrices.
• The module were are talking about here is type number JHD162A which is a very
popular one .
• It is available in a 16 pin package with back light ,contrast adjustment function
and each dot matrix has 5×8 dot resolution.
• The pin numbers, their name and corresponding functions are shown
in the table below.
VEE pin is meant for adjusting the contrast of the
LCD display and the contrast can be adjusted by
varying the voltage at this pin.
This is done by connecting one end of a POT to the
Vcc (5V), other end to the Ground and connecting
the center terminal of the POT to the VEE pin.
As shown in the below diagram
• The JHD162A has two built in registers
namely data register and command
register.
• Data register is for placing the data to be
displayed , and the command register is to
place the commands.
• The 16×2 LCD module has a set of
commands each meant for doing a
particular job with the display. (commands
explained later)
• High logic at the RS pin will select the data
register and Low logic at the RS pin will
select the command register.
• If we make the RS pin high and the put a
data in the 8 bit data line (DB0 to DB7) , the
LCD module will recognize it as a data to be
displayed . If we make RS pin low and put a
data on the data line, the module will
recognize it as a command.
16×2 LCD module commands.
16×2 LCD module has a set of preset command instructions.
Each command will make the module to do a particular task.
The commonly used commands and their function are given in the table below.
• R/W pin is meant for selecting
between read and write modes. High
level at this pin enables read mode
and low level at this pin enables write
mode.
• E pin is for enabling the module. A
high to low transition at this pin will
enable the module.
• DB0 to DB7 are the data pins. The data
to be displayed and the
command instructions are placed on
these pins.
• LED+ is the anode of the back light LED
and this pin must be connected to Vcc
through a suitable series current
limiting resistor. LED- is the cathode of
the back light LED and this pin must be
connected to ground.
LCD initialization
The steps that has to be done for initializing the LCD display is given
below and these steps are common for almost all applications.
Sending data to the LCD
Interfacing LCD
STEPPER MOTOR INTERFACING

27
• Stepper motor is an electromechanical device that
rotates through fixed angular steps when digital
inputs are applied. It is suitable for precise position,
speed and direction control which are required in
automation system.
• The angle through which stepper motor rotates with a
fixed angle for each digital data is called step angle.
• Different stepper motor has different step angle. The
more frequently used stepper motor has step angle of
0.9 degrees and 1.8 degrees.
Depending on the sequence applied to stepper motor,
it can be classified in two category:
a. 4- Step sequence or full step sequence
b. 8- Step sequence or half step sequence

28
Calculations:
1. Total no. of steps for 360 degree completion
if step angle = 1.8 degree then 360/1.8 = 200
i.e. 200 steps are required to complete one rotation
2. RPM = revolution per minute ( i.e how many
rotation per minute of 200 steps)
Ex: 50 RPM hence
Time of one revolution in msec = (1/RPM) * 60*1000
= (1/50)*60*1000
= 1200msec
3. Step Sequence –
a) Half step b) full step
29
HALF STEP
30
FULL STEP

31
Interfacing with 8051
Debug the code…
org 0000h
jmp Start
org 0100h
Start: mov r3,#50
mov a,#00110011b
l1: mov p2,a
rr a
acall delay
djnz r3,l1
here: sjmp here
delay: mov r0,#255
l2: mov r1,#255
l3: djnz r1,l3
djnz r0,l2
ret
END
org 0000h
jmp Start
org 0100h
Start: mov r3,#20
mov r4,#10
mov a,#00110011b
l1: mov p2,a
rr a
acall delay
djnz r3,l1
l4: rl a
Debug the code… mov p2,a
acall delay
djnz r4,l4
here: sjmp here
delay: mov r0,#255
l2: mov r1,#255
l3: djnz r1,l3
djnz r0,l2
ret
END
DAC (Digital to analog Conversion)

35
Interfacing circuit example
Proteus Circuit (TVref=+12V)
Debug the output Window WRT code!!
Calculations –Vref=+6V i.e total VREF = 12V
a square wave 2V per division*6 div = 12V PtoP
starting at 00H = -6V & ending at FFH = 255D =
255*0.047V = 12V
Time division 5 DIV * 50us = 250(TON/TOFF)us
total time = 500us
Frequency = 1/500us = 2Khz.

39
Homework
Considering VREF as 12 volts and DAC is interfaced at
PORT 2. Write an assembly language program to
a) Forward saw tooth wave of 12v peak to peak
b) Reverse saw tooth wave of 12v peak to peak
c) Triangular Wave of 12V peak to peak
d) Square wave of 5v peak to peak clammed at 5V OF 1KHZ
FREQUENCY
E) Sine wave

40
ADC0808/0809
IN0-IN7: Analog Input channels
D0-D7: Data Lines
A, B, C: Analog Channel select lines;
A is LSB and C is MSB
OE: Output enable signal
ALE: Address Latch Enable
EOC: End of Conversion signal
Vref+/Vref-: Differential Reference
voltage input
Clock: External ADC clock input
Clock Circuit
• The ADC 0808 IC requires clock
signal of typically 550 kHz,
which can be easily derived
from an Astable multi-vibrator
constructed using the shown
circuit
Interfacing of ADC0808 with 8051 in Proteus
Debug the code!!
start equ P3.5 setb start
eoc equ P3.6 acall delay
sel_a equ P3.1 clr start
sel_b equ P3.2 jnb eoc, $ ; $ means jump to same location
sel_c equ P3.3
mov A, adc_data
mov p2,A
adc_data equ P1
acall delay
org 0H
acall delay
setb eoc
sjmp main_loop
clr start delay: mov r0,#255
djnz r0,$
main_loop: mov adc_data, #0FFH ret
setb sel_a end
clr sel_b
clr sel_c
Memory Mapping of 8051
• Memory interfacing is used to provide more memory space to
accommodate complex programs for more complicated systems.
• Types of memories which are most commonly used to interface with
8051 are RAM, ROM, and EEPROM.
• 8051 can access 64kB of external memory. It can be explained as-
total number of address lines in 8051 are 16, therefore it can access
2^16 = 65535 locations i.e. 64kB

• Note: 2^n=number of memory locations n = number of address lines


Some of the RAM IC's are
given as:
• 1. IC 6108 -> 1k x 8bits
• 2. IC 6208 -> 1k x 8bits
Some of the ROM IC's are
given as:
• 1. IC 2708 -> 1k x 8bits
• 2. IC 2716 -> 2k x 8bits
Design a minimum system to interface the
following specification:
1. 32kB of RAM using 2 x 16kB RAM IC
2. 32kB of ROM using 2 x 16kB ROM IC
Decoding Technique
• There are two type of interfacing:1. Partial decoding: In this type of
decoding not all the address lines are utilized in the circuit (they are
left as unused pins). Ex: In an interface of 4kB memory only A0-A11
address lines are utilized, whereas the remaining A12-A15 address
lines are unused.
• 2. Complete decoding (exhaustive decoding): In this type of
decoding, all the address lines are utilized in circuit for some or the
other use (i.e. all pins are exhausted). Ex: In an interface of 4kB
memory only A0-A11 address lines are utilized, whereas the
remaining A12-A15 address lines are used in Memory selection logic
or as any other control signals.

You might also like