Unit-10 Applications and Design of Microcontroller Based Systems_Technical
Unit-10 Applications and Design of Microcontroller Based Systems_Technical
No step 4
Yes step 7
7. Find key code and display the key pressed on 7-segment display.
(By grounding one scan line at a time and checking return lines for any one line
to go to 'O' level. )
8. Go to step 1.
Program :
org lookup_table_address
db 30h, 31h, 32h, 33h, 34h, 36h, 36h, 37h,
38h, 39h,41h,42h,43h,44h,4 5h,46h
org program_start_address
beg: mov Pl #Of h; configure lower 4 lines of port 1 as i/p
mov dptr,#lookup_table_addr ess ; initialise dptr with
; lookup_table_addr.
aga: mov a, Pl
anl a, #Ofh
cjne a, #Ofh,aga ; check for key released
lcall delay ; call delay routine for key debounce
agal: mov a, Pl
anl a, #Ofh
cjne a,#Ofh, go ; check for key pressed
ljmp agal
go: lcall delay ; call delay routine for key debounce
mov a, Pl
anl a, #Ofh
cjne a,#Ofh, gol ; is key really pressed?
ljmp agal
gol: mov rl, # Olh ; initialise counter 1
mov rO, #Oefh ; store word for column selection
movr3, #04h ; initialise column counter
aga3: mov Pl, rO ; select only 1 column
mov a, Pl ; get the status of return lines
jnb acc.O,display ; check bit O and if it is O jump to display
inc dptr ; increment lookup_table pointer
jnb acc.1,display ; check bit 1 and if it is 1 jump to display
inc dptr ; increment lookup_table pointer
inb acc.2,display ; check bit 2 and if it is 2 jump to display
inc dptr ; increment lookup_table pointer
jnb acc.3,display ; check bit 3 and if it is 3 jump to display
inc dptr ; increment lookup_table pointer
mov a, rO ; get the word for column selection
®
TECHNICAL PUBLICATIONS - An up thrust for knowledge
Microprocessors and Microcontrollers 13 • 27 Applicatio ns and Design of Microcontroffer Based Systems
Review Questions
3
4
2}
:
Analog
inputs
Analog
5
inputs
6
7 ~} Mdress
soc
EOC ALE
D83 D87
CLK 085
Vee 084
REF+ 080
GND REF
D81 D82
Operation
ADC 0808/0809 has eight input channels, so to select desired input channel, it is
necessary to send 3-bit address on A, B and C inputs. The address of the desired
channel is sent to the multiplexer address inputs through port pins. After at least 50 ns,
this address must be latched. This can be achieved by sending ALE signal. After another
2.5 µs, the start of conversion (SOC) signal must be sent high and then low to start the
conversion process. To indicate end of conversion ADC 0808/0809 activates EOC signal.
The microprocessor system can read converted digital word through data bus by
enabling the output enable signal after EOC is activated. This is illustrated in Fig. 13.5.2.
A
B
C
~ Address
-- 50 nsl--
x
ALE /
l-25 µs.j
~ ()
soc ~
EOC "
))
/
>-
(
)
Interfacing
.
Fig. 13.5.3 show s typical interfacing circu
microcontroller system. it for ADC 0808 with micr opro cess or/
Analog
Inputs 1K
0.01 µF
7414
I
12V
2K
2K 6.8V
+ 10mF
1µF solid
Tantalum
10 K
Oscillator
~~\ ~~ ~~ ~ - . ~ ' ,:_, 'v. ,. +5 V AOC 0808
' :-.; "' :-.: "=''
CH7 IN7
CLOC K
07
06
05
Vee 04 Port 0 of
+REF D3 8051
-REF D2
D1
GND DO
Fig. 13.5.4
After at least 50 ns, this address must be latched. This
can be achieved by sending
ALE signal. After another 2.5 µs, the start of conversion
(SOC) signal mus t be sent high
and then low to start the conversion process. To
indicate end of conversion (EOC)
(AOC 0808/0809) activates EOC signal. The 8051 pins
P2.0 and Pl.3 are connected to
EOC and SOC pin of 0808/0809.
After conversion is over, 8-bit digital data is available on
Do thro ugh D 7 lines. The
8051 accepts this data through port 0.
Program
CLR P1 .3 ; Make SOC low
CLR P1.4 ; Make ALE low
MOV PO, #OFFH ; Configure port O as inpu t
MOV P2, #OFFH ; Configure port 2 as inpu t
BACK : MOV DPTR, #OCOOOH ; Initialize mem ory poin ter
When the WR input goes low, the internal successive approximation register (SAR) ~s
reset. As long as both CS and WR remain low, the analog to digital converter ~ill
remain in its reset state. One to eight clock periods after CS or WR makes a low-to-high
transition, conversion starts. The INTR signal is held high during conversion proc~ss.
After conversion, INTR goes low which is used as end of conversion signal. By makillg
CS and RD signals low, an output can be read through DBo to DB7 data signals.
®
TECHNICAL PUBLICATIONS - An up thrust for knowledge
Microprocessor and Microcontrollers 13 - 33 Applications and Design of Mlcrocontroller Based Syste ms
Analog Inputs
V in(-)
V 1n(- l
- +5V
(a)
(b)
-
Fig. 13.5.6 Ways to use differential inputs
Clock Sign al
ADC 0804
The ADC 0803/0804/0805 requires a clock
source ranging 100 kHz to 1460 kHz for CLKR
operation. The clock signal can be applied
external or it can be generated with an RC
circuit, as shown in the Fig. 13.5.7. When the
RC circuit, show n in Fig. 13.5.7 is used to
generate the clock, the clock frequency is
given as,
F - 1 Fig. 13.5.7 Clock circuit
clock - 1.1 RC
+SV
POT
150 pF
ADC 0803/0804/0805
Fig. 13.5.8
we get
The typical values are R =10 kQ and C =150 pF. With these values
is aroun d
appro ximat ely 606 kHz clock frequency. In such case, the conversion time
110 µs.
Following are the steps followed for data formation by the ADC0804 chip.
Step 1 : Make low to high pulse to pin WR to start the conversion.
is finished
Step 2 : Keep monitoring the INTR pin. If INTR is low, the conversion
and we can go to next step. If INTR is high, keep polling until it goes low.
Step 3 : After the INTR has become low. Make a high to low pulse to
the RD pin to
get the data out the ADC0804 IC chip.
AD Conversion Program
MOV Pl, #OFFH ; configure Portl as input
BACK: CLR P2.6 ; (Make WR = 0 and
SETB P2.6 ; Make WR = 1 to genera te start of
; conver sion pulse]
AGAIN : JB P2.7, AGAIN ; Wait for end of conve rsion
CLR P2.5 ; Enabl e read
MOV A,Pl ; Read data throug h port 1
SETB P2.5 ; Disabl e read after readin g data
SJMP BACK ; go for next conve rsion cycle
®
TECHNICAL PUBLICA T/ONS - An up thrust for knowledge
Microprocessor snd Mlcrocontrollers 13 • 35 Appl/cations and Design of Mlorocontroller Base
cs--- ,
d Systems
Data out
iNrn - - - - - - - - - - - -
Start conversion
1
RD _ _ _ _ _ _ _ _ _ _ _ _ _conv
End _ersio
__ n _;
::: 1;
Solution:
#include <reg51.b>
8bit ALE = Pl "'4;
8bit SC = Pl "'3;
8bit EOC = P2"' 0;
8bit ADDR_A = P1 "'O;
8bit ADDR_B = P1"' 1;
8bit ADDR_C = P1 "'2;
mPDATA = PO;
void main()
{
unsigned char value;
PDATA = OxFF; /* make PO an input * /
EOC = 1; /* make EOC an input * /
ALE= O; /* clear ALE * /
SC= O; /* clear SC */
wblle(1)
{
ADDR_C = O; /* C = 0 */
ADDR_B = O; /* B = 0 */
ADDR_A = O; I* A = 1(select channel O) */
Delay(1); /* delay for fast DS89C4x0 * /
ALE= 1; /* Latch the address */
Delay(1);
SC= 1;
Delay (l);
ALE = 0 ;
SC = 0; /* start conve rsion */
whlla (EOC ==l); /* wait for data conve rsion */
whlla (EOC = =O);
Delay (l);
value = PDATA; /* get the data* /
Conve rtAnd Displa y(valu e); /* Refer sectio n 10.6 */
}
}
Practical Applications
AD590 Vout
t t t - ---,'c~t:;;_:i----e INTR(21)
. ·: ~:,~·-:~--
The Fig. 13.5.11 shows the block diagram of AOC 0848. The AOC0844 and AOC0848
contain a 4-channel and 8-channel analog input multiplexer (MUX) respectively. Each
MUX can be configured into one of three modes of operation differential, pseudo
differential, and single ended. The specific mode is selected by loading the MUX address
latch with the proper address (Refer Table 13.5.1). Inputs to the MUX address latch
(MA0-MA4) are common with data bus lines (DB0-DB4) and are enabled when the RD
line is high. A conversion is initiated via the CS and WR lines. If the data from a
previous conversion is not read, the INTR line will be low. The falling edge of WR will
reset the INTR line high and ready the AID for a conversion cycle. The rising edge of
~ with RD high, strobes the data on the MA0/DB0-MA4/DB4 inputs into the MUX
address latch to select a new input configuration and start a conversion. If the RD line is
held low during the entire low period of WR the previous MUX configura tion is
retained, and the data of the previous conversion is the output on lines DBO-DB7. After
the conversion cycle (tc ~ 40µs), which is set by the internal clock frequency , the digital
data is transferred to the output latch and the INTR is asserted low. Taking CS and RD
low resets INTR output high and outputs the conversion result on the data 1.
(DB0-DB7). This is illustrated in the timing diagram shown in the Fig. 13.s.13 _ mes
The Fig. 13.5.12 shows the pin diagrams for ADC0844 and ADC0848.
®
TECHNICAL PUBL/CA TIONS - An up thrust for knowledge
Microprocessor and Microcontrol/ers 13 - 39 Applications and Design of Microcontroller Based Systems
The Table 13.5.1 (a) and 13.5.1 (b) show the ADC0844 and ADC0848 multiple xer
addressi ng.
RD 1 20 24
Vee RD 1 Vee
cs 2 19 WR CH1 2 23 cs
CH1 3 18 INTR CH2 3 ·- 22: WR
CH2 -11 . D80 / MAO CH3 c' 4 .•, .. - 21 iNTR
CH3 ,. ;16 D81 / MA1 tl.19
CH4 5·•·"· DB0 t MAO
CH4 D82 / MA2 CH5 D61 / MA1
AGND D83 / MA3 CH6 OB2 / MA2
VREF D84 CH7 D63/ MA3
(MSB) 087 D65 CHS OB4 / MA4
DGND OB6 AGND D65
(a) VREF OB6
DGND D87
(b)
MUX
mode
Pseudo
differential
h•:;n~,-
;_N
.... _._..,........
I MUX ~
. ~ · -~ ~ CS ::§,~~~
...~ . '+~~'•\~-..~~"'~
.! !~·: RO ~..;.,i..,,.,.
. ·
. ,~,.;:-;
~ •
·.·• ··,.,....,....,,, -,,;;w·/4,, ✓.;,:..,.;, ,.NP;•h/,)e-W.Y/, ✓;,,
MUX tn<lde
-,,;~ •-. _,__~ •
MA4 . , ;ta2
"" ,. ~
Mt.'; ~ ~ <\~L
%,,.,,
cwt· CH2 CH3 CH♦. .•.~-~ '-' ~~t~~ . . ~~•-,~~~~,,., , ,. . .. . ,
:- ~-·~ ~ "i~ T ~ :_~f._.ii__~_,.-~ ...
__
:.~_:_:_;_;_·:_r: ,~I...... ,. ·• .· . . . . .. Differential I'
t
'
~ '.
.L
'
:,,i·: x•t_.:. '
-~ j !,
t~ · ·. t.. tvt~:; ¥~:s It
If,~
t ... ·•
i .:irritti:it
E;:·•
l.
. --::~•:;::• ·,::~~--<~:,••:- .: ·
H ;3"11 .. ·""
~=~ _:, .
t~
If
H
: H ::
,. ,,.,,,,A#,:,.-ft,;¥-.':;Y~ ·""
<~~~l "::;,,•,~
1/. (";, ~~
X X . • V
!...-N~,,._,.._._,,..,,,,, ,_,~/;N,_,,w,,.,,.,,.,,,,MN,,.,;,,.,,,,,,i<,,,h-'Nk,
--- 1l --
l
\ I
l
\ I
rnffl
I
DBO - 0B7 -
MA0 -MA4
- - -
Tri - state
- - - -< .
DB0 - OB7 )
.
-
Fig. 13.5.13 Timing diagram for selecting the chan
nel and reading data from ADC0848
Steps to select the channel and read data from
ADC 0804
1. When CS = 0 and RD = 1 prov ide addr ess of chan
nel to be selected and appl y a
low-to-high WR puls e to latch the address.
2. Now whe n RD = 1 and WR = 1, check for INTR
signal to go low; low INTR
indicates end of conversion (EOC).
3. With INTR low, mak e CS= 0, WR = 1 and appl y
low goin g puls e on RD to get
data out on the data pins of AOC0848.
The Fig. 13.5.14 show s the interfacing of AOC0848 with
8051.
+5V
8051 ADC0848
'
;t i....
. /.•.•--:~ •,;::-· .
-----M
. ,· •.•· .- ..·,·
/i/i/. : PO.~ . 1 4 - ~ M . .b~ l:MA3' •· •· ·:· :cH4\t
?0~4,.(...
: _ _. MA4.. · 8fl ... PH!?
:: ~o~p·:,. .- -.. . : o.:v QHl.i ~
PO,:e O~·
__ __e_2_
.i_:;
;1----;/1NrR
:; ~,. . c1;1 ,
CHS .·
. AGNO
PG.NO.·
Solutio n :
CS BIT P2.4
RD BIT P2.5
WRBIT P2.6
INTR BIT P2.7
ORG OH
SETB INTR ; make INTR an input
SETB cs ; set Chip Select high
SETB RD ; set Read high
SETB WR ; set Write high
BACK :
MOV P0,#09H ; Channe l 2 address
NOP ; wait
CLR cs ; Chip Select (CS=O)
CLR WR ; write= LOW
NOP ; wait to make pulse width wide enough
NOP
SWTB WR ; latch the address and apply start convers ion
SETB cs ; de-sele ct the chip
MOV P0,#0F FH ; make PO an input
HERE:
JB INTR,HERE ; wait for EOC
CLR cs ; Chip Select (CS=0)
CLR RD ; read RD=0
NOP ; wait to make pulse width wide enough
NOP
SETB RD ; bring out digital data
MOV A,P0 ; get the digital data
SETB cs ; de-sele ct for next round
ACALL CONVERT ; convert to ASCII
ACALL DATA_DISPLAY ; display the data
SJMP BACK
Exampl e 13.5.5
Solutio n :
#includ e <reg61 .h>
■bit cs = P2 A 4;
■bit WR = P2 A 5;
■bit RD= P2 A 6;
■bit INTR = P2 ,.._ 7;
void main(vold)
TECHNICAL PUBL/CA TIONS® - An up thrust for knowledge
Microprocessor and Microcontrol/ers 13 - 43 Applications and Design of Mlcrocontroller Based Systems
{
umlgned char value;
INTR = 1; /* make INTR an input*/
cs = 1;
WR= 1;
RD= 1;
whlle(l)
{
PO= Ox09; /* Channel 2 addr */
CS= O; /* chip select */
WR=O; /* write = LOW */
Delay(); /* make pulse wide enough * /
WR= 1; /* L-to-H to latch addr */
cs= 1; /* de-select */
PO= OxFF; /* make PO an input */
while(INTR= =1); /* wait for EOC */
CS= O; /* chip select */
RD= O; /* make read low * /
Delay();
RD= 1; /* read the data */
value= PO; I* get the data */
cs= 1;
ConvertAndDisplay(value ); /* Refer section 10.6 */
}
}
VREF + : Reference voltage : This is a positive analog voltage reference ranges from
+ 2.5 to + 5.0 V.
Do : Data Output : The result of A/D conversion (D0 D9) is output on this pin. The
-
most significant bit D9 is shifted-out first through data output pin D 0 ,
CCLK : Clock Input : This dock input controls the successive approximation conversion
time interval, i.e. (A/D conversion rate). The dock frequency applied to this pin can be
between 700 kHz to 4 MHz.
The Fig. 13.5.16 shows the interfacing of ADC 1031 to 8051. As shown in the
Fig. 13.5.16, signals ScLK and CS are control by P2.0 and P2.l port output pins and serial
data from D0 output is accepted on Pin 3.0 of 8051.
+SV
ScLK
cs
i 'VI - - - Analog input
3 MHz GcLK
clock
Solution:
ORG OOOOH
CLR P2.1 Make CS = 0 to select ADC 1031
SETB P3.0 Configure P3.0 as an input
MOV R2, #2 Set counter to read MSB and MSB-1
CLR A Clear A
BACK!: SETB P2.0 Send falling edge on pin ScLK
CLR P2.0
MOV A, P3.0 Read data bit and save it as LSB of A
RLC A Shift left the received bit/s
DJNZ R2, BACKl Check if R2 = 0, if not go to BACK1
to read bit MSB-1
MOVRl, A Store the data in Rt
MOVR2, #8 Set counter to read lower byte
CLR A Clear A
®
TECHNICAL PUBL/CA TIONS - An up thrust for knowledge
Microprocessor and Microcontrollers 13 - 45 Appl/cations and Design of Microcontroller Based Systems
Review Question s
--
7. Explain interfacing of ADC 1031 to 8051 microcontroller.
.
AID converter with 8051 microcontroller"
18. Write short note on "interfacing of GT U : Win ter- 19, Mar ks 3
GN D -Vref
VEE +Vref
(MSB) A1 A8 (LSB)
A2 A7
A3 Ae,
A4 8 9 As
An th
TECHNICAL PUBLICA TIO Ns® - up rust for knowledge
Microprocessor and Microcontrollers 13- 47 Applications and Design of Microcontroller Based Systems
switches. It has eight input data lines A1 (MSB) through As (LSB) which control
the
positions of current switches.
MSB
LSB
A1 A2 A3 A4 As As A7 Aa
5 6 7 8 9 10 11 12
1
Range
control
VEE
'--y- -"
NPN Current source pair
Vee
2.5 K +5V
vref
2.5 K
8-bit
digit
input
R1s
2.5 K
15 pF
Vee
-15 V
Fig. 13.6.2 Typical circuit for DC 0808
11
!!t\%1t~Et~s:;~0~t; R0Cf;t:'i::.•:
current and at (111 ..·. . ... h binary
•·. .•. . ·- ---- ·
•· ...put 1t
.m -.
sm
. -: .. :.,: ;:.-·,,
t 9.92:
-·-:: :· . ·-
IDA.·· ··
;_ •. · .
The circuit shown in the Fig. 13.6.2 gives output in the unipolar range. When digital
input is OOH, the output voltage is O V and when digital input is FFH (1111 11 llh, the
output voltage is + 5 V. This circuit can be modified to give bipolar output.
®
TECHNICAL PUBLICATIONS - An up thrust for knowledge
Microprocessor and Mlcrocontrollers 13 - 49 Applications and Design of Microcontroller Based Systems
Fig. 13.6.3 shows th e circuit for giving output in the bipolar range. Here, resistor RB
(5 K) is connected between Vref and the output terminal of DAC 0808. This gives a
constant current source of 1 mA.
Vee
+5 V
5 13
R14 +SV
2.5 K vref
8-bit Ia l 5K -If ~
digital 1 mA
RB
5K
input
-10 A
15 pF 2.5 K
VEE
When binary input is 8OH, the output current I0 at pin 4 is 1 mA. By applying KCL
at node A we get,
- Is +I 0 +If = 0
Square Wave
e squ are wav e firs t we hav e to out put FF and the n 00 on por t 1 of 8051.
To gen erat frequency
ut to the DA C 0808. Acc ord ing to
The por t 1 is connected as an inp
the two out put s.
req uire men t del ay is pro vid ed bet wee n
Program :
MO V SP, #08 H ; Initialize Sta ck Poi nter
; Loa d all 1 s in Por t 1
1
4 MHZ
HO
Vcc
20
RST
Poo Ao -A15
R 8051 Po7
ALE Do- D7
PSEN
RD
PSEN
RD
P1o17 WR -WR
moomo
lHA
Y -A45
Vcc R
GND G
+5 V
2.5 K
14
2.5 K
2.5 K
DAC
0808
15
16 3 1 2
$2.5 KI
Fig. 13.6.4
Triangular Wave
To generate triangular wave we have to output data from 00 initially, and it should
be incremented upto FF. When it reaches FF it should be decremented upto 00.
Program:
MOV SP, #08H ;Initialize Stack Pointer
MOV RO, #00H
REPEAT: MOV P1, RO ;Send digital data to the input
; of DAC 0808
INC RO ;Increment digital data
CJNE RO #0FFHREPEAT :Check digital data for peak output if not repeat
REPEAT1: MOV P1, RO ;Send digital data to the input of DAC 0808
DJNZ RO, REPEAT1 ;Decrement digital data and
;check digital data for least
;output if not repeat.
LJMP REPEAT
Sine Wave
To generate sine wave we have to output digital equivalent values which will
represent sine wave as shown in the Fig. 13.6.5. Digital data 00H represents - 2.5 V. 7FH
represents 0 V and FFH represents + 2.5 V. The digital equivalent for sine wave can be
calculated as follows.
+2.5 V
180° 3600
i90°
FFH
80H
96H
ABH
COH FEH
D{H
-2.5 V
E2H
EFH|
F8H
Fig. 13.6.5
We know that sin ° = 0 and sin 90° = 1. The range sin 0° to sin 90° is distributed
over digital range of 7FH to FFH ie. (FFH - 7FH) 128 decimal steps. Therefore, taking
128 as a offset we can write,
Digital equivalent value (DEV) for sin x = (128 + 128 x sin x)
where x is a angle in degrees and digital value is in decimal.
Lookup table shows the digital equivalent values for sine wave.
Degrees Equation Digital Equivalent in Digital Equivalent in
Decimal Hex
INC DPTR
point to next lookup table entry
DJNZ RO, BEGIN Decrement counter and go to BEGIN
if not zerO
LUT: DB 80H,96H,ABH....
DB
DB 40H, 54H, 6AH, 80H
Note In above program we have to store entries from given lookup table instead of
aots.
Review Questions
Coil
Mounting
brackets
80000000o
The output current of 8051 microcontroller pins is not sufficient to drive the relay, or
solenoid. The relay/solenoid coil needs around 10 mA - 100 mA to be energized and
microcontroller's pin can provide a maximum of 1 - 2mA. For this reason, we have to
use driver such as the ULN2803 or a power transistor or a power MOSFET between the
microcontroller and the relay/solenoid as shown in the Fig. 13.7.2.
+V
+5 V +5 V 0000
Relay
Contact
S4.7K
8051
P1.0 Relay /solenoid
coil
ULN 2803
Freewheeling Relay
diode Contact
Relay / solenoid
coil
A stepper motor is a digital motor. It can be driven by digital signal. Fig. 13.8.1
shows the typical 2 phase motor interfaced using 8051. Motor shown in the circuit has
two phases, with center-tap winding. The center taps of these windings are connected to
the 12 V supply. Due to this, motor can be excited by grounding four terminals of the
two windings. Motor can be rotated in steps by giving proper excitation sequence to
these windings. The lower nibble of port 1 of the 8051 is used to generate excitation
Stepper
X, motor
P1.0
7407
0090
Yo
P1.1 +12V
7407
L
P1.2
7407
P1.3
7407
11 06HH
2 1 0
10 0AH
3 1
1 00 09H
1 0 0 07H
3 1 011 0 061
OEH
10 1 0AH
1 01 0 1 OBH
09H
8 00 1 ODH
1 1 05H
Program
MOV R0 # COUNT : Initialize rotation cCount
AGAIN: MOV DPTR, #ETC ; Initialize pointer to excitation code table
MOV R1, #04 Initialize counter to excitation code sequence
BACK: MOVX A, @DPTR Get the excitation code
MOVP1, A send the excitation code
LCALL DELAY : Wait for some timne
INC DPTR ; Increment pointer
DJNZ R1, BACK : Decrement R1; if not zero goto BACK
DJNZ RO, AGAIN ; Decrement RO; if not zero goto AGAIN
RET
ORG 3000H
ETC DB 05H,06H,0AH,09H; code sequence for clockwise rotation
Example 13.8.2 Write assembly language program to control conveyer belt using stepper
motor and 8051 controller. Belt moues continuousyat ateof1sten/sec. but stops for
5 sec. uhen external interruptoceturs and then contnues tomove.
Solution :
MAIN MOV IE, #1000 0001B Enable external interrupt 0
AGAIN: MOV DPTR,#ETC ; Initialize pointer to excitation code table
MOV R1, #04 ; Initialize counter to excitation code sequence
BACK: MOVX A, @DPTR ; Get the excitation code
MOV P1, A ; send the excitation code
MOVA,#14H : Initialize count = 20
LCALL DELAY ; Wait for 1sec
INCDPTR ; Increment pointer
DJNZ R1, BACK ; Decrement R1
; if not zero goto BACK
SJMP AGAIN ; Repeat
ORG 3000H
ETC DB 05H,06H, 0AH, 09H ; Code sequence for
Clockwise rotation
Example 13.8.3 Describe the 8051 connection to the stepper motor and a ALP to rotate it
continuously in both clockwise or anti-clockwise after selection of mode. Check direction
after completion of one complete sequence. GTU: Winter-08
Solution: Assume mode selection input is connected to Port 2.0. If mode selection input
is 1, rotate motor anti-clockwise; otherwise clockwise.
AGAIN: SETB P2.0 Configure P2.0 as an input
JB P2.0, SKIP Check mode selection
MOV DPTR, #ETC1 Initialize pointer to excitation code table
SJMP NEXT for clockwise rotation
C Program
#include <reg51.h>
unsigned char i;
void main()
P1 = 0x05;
Delay(100):
P1 = 0x06;
Delay(100);
P1 = 0x0A;
Delay(100);
P1 = x09;
Delay(100);
4 x 50 = 360° = 1 Rotations */
for (i=0; i< 50; i++) /* Rotate 1.8 x
P1 = 0x09;
Delay(100):
P1 = 0x0A;
Delay(100);
P1 = 0x06;
Delay(100);
P1 = 0x05;
Delay(100):
}
cnt)
void Delay(unsigned int
9+5 V
4.7 K4.7 K S4.7 K4.7 K
P1.0
P1.1 -00000000
P12
r0000000
P1.3
8051
ULN2003
Fig. 13.8.4
A CALL Delay
DJNZ RO,BACK
END
Review Questions
The Fig, 13.9.1 shows how de motor changes its direction of rotation when
the
polarity of power supply reverses.
TECHNICAL PUBLICATIONS - An up thrust for
knowledge
Microprocessor and Microcontrollers 13- 65
Applications and Design of Microcontroller Based Systems
M
M
SW o
SW 1
SW 2
SW3
Motor not
running
Fig. 13.9.2 Bidirectional control of DC motor
SW3 SW2 SWI SWO Motor rotation
ON OFF OFF ON Clockwise
OFF ON ON OFF Anticlockwise
W*wwwwwwww.
CLR P2.2
CLR P2.3
SETB P1.0 ;configure P1.0 as input
Check: JNB P1.0,Clockwise
CLR P2.0 :Make SWO OFF
SWTB P2.1 ;Make SW1 ON
SETB P2.2 :Make SW2 ON
CLR P2.3 :Make SW3 OFF
SJMP check
Clockwise: SETB P2.0 ;Make SWO ON
CLR P2.1 ;Make SW1 OFF
CLR P2.2 ;Make SW2 OFF
SETB P2.3 ;Make SW3 ON
SJMP check
END
25 %DC 4 Power
50 % DC Power
75 % DC Power
3T -
12 V
M
+5 V 1N4004
Decoupling
capacitor
330 2 ILD74
8051 OPTOISOLATOR
8 10 K
TIP 120
Darlington
2 7 Transistor
Pz: +12 V
S100 K
3 6
4 5
12 V
+5 V M
1N4004
Decoupling
capacitor
330 2 ILD74 D
8051 OPTOISOLATOR
10 K
IRF 521
2
P0
+12 V
S100 K
3
CTL = 0;
while(1)
if(SW =1)
CTL = 1;
Delay(75);
CTL = 0;
Delay(25);
else
CTL = 1;
Delay(50);
CTL = 0;
Delay(50);
}
void Delay(unsigned int value)
unsigned char i,j;
for(i=0; i<1200; i++)
for(j=0; j<value; j++);
Review Questions
1. For the interfacing diagram in (a), write a program to rotate DC motor in clockwise direction if
switch is ON and in anti-clockwise direction if the switch is OFF. GTU : Winter-17, Marks 4
8. Discuss how the speed and direction of DC motor canbe controlled using microcontroller.
GTU : Winter-19, Marks 7
DO0
TECHNICAL PUBLICA TIONS - An up thrust for knowledge