Está en la página 1de 8

ALGORITHM

The Algorithm implemented in the 8085 microprocessor kit to drive the DC


Motor is as shown:

1) Busy Wait for a Key Press

2) Detects a Key Pressed

3) Identify the Key

4) Passes Control to the Appropriate Subroutine

5) go back to 1 unless the Exit Key was identified in step 3


Assembly Code and Listing

0001 0000
0002 0000 .ORG 2000h
0003 2000 31 00 29 LXI SP, 2900H ;Initialise the
Stack Pointer
0004 2003 3E 08 MVI A,08h
0005 2005 20 RIM
0006 2006 CD 32 20 KBREAD: CALL RDKBD ;READ KEYBOARD
FUNCTION
0007 2009
0008 2009

;USING THE KEYBOARD AS JOYSTICK :The following key patterns are


used

; 9-->The BOT will be driven toward the Front


; 4-->The BOT will be turned toward the Left
; 6-->The BOT will be turned toward the Right
; 1-->The BOT will be driven backward
; 5-->The Exit Code. This will result into Program
Termination

; 9
; 4 5 6
; 1

;Given below is the assembly code that checks the key-value. This is
analogous to switch-case programming structure in C
0023 2009 FE 09 CPI 09h ;compare with
key value 09
0024 200B CC 00 21 CZ FRONT ;If matched
call the subroutine FRONT
0025 200E CA 06 20 JZ KBREAD ;Go back to
Read the Keyboard
0026 2011
0027 2011
0028 2011 FE 01 CPI 01h ;compare with key
value 01
0029 2013 CC 1E 21 CZ BACK ;If matched call
the subroutine BACK
0030 2016 CA 06 20 JZ KBREAD ;Go back to
Read the Keyboard
0031 2019
0032 2019 FE 06 CPI 06h ;;compare with
key value 01
0033 201B CC 3C 21 CZ RIGHT ;If matched call
the subroutine RIGHT
0034 201E CA 06 20 JZ KBREAD
0035 2021
0036 2021 FE 04 CPI 04h
0037 2023 CC 5A 21 CZ LEFT
0038 2026 CA 06 20 JZ KBREAD
0039 2029
0040 2029 FE 05 CPI 05h
0041 202B CA 31 20 JZ EXIT;If Key 5 was
pressed Exit
0042 202E C3 06 20 JMP KBREAD
0043 2031
0044 2031 76 EXIT: HLT
0045 2032

;Subroutines FRONT , BACK , RIGHT , LEFT are described below


;These Subroutines interface the 8085 kit with the DC Motor
Interfacing Driver IC ( we have used L293D )via the 8255 chip.

; 8255 INTERFACING CHIP HAVE BEEN USED IN MODE 0(ZERO) FOR


OUR APPLICATION

;PORT B has been used by our application for Output .So the A register
has been initialised with the control word 90H

; A ---> 10010000
; The data sent via the control port XX03H .Here XX=00

; The data to be sent to the output port for the SUBROUTINE FRONT
is A0H (10100000) [ Refer to the L293D Pin Configuration]
; The data to be sent to the output port for the SUBROUTINE BACK is
50H(01010000)
;The data to be sent to the output port for the SUBROUTINE RIGHT
is 60H(01100000)
;The data to be sent to the output port for the SUBROUTINE LEFT is
90H(10010000)

;This data is sent via the control port XX02H . Here XX=00
;For each subroutine C has been initialised as a counter, with initial
value of 50 .
;This has to be manipulated during the TESTING PHASE to get the
desired accuracy

0069 2035
0070 2035
0071 2035 .ORG 2100H
0072 2100
0073 2100
0074 2100 FRONT:
0075 2100 ; Save the machine registers by pushing them
inside the stack.
0080 2100 F5 PUSH PSW
0081 2101 C5 PUSH B
0082 2102 00 NOP
0083 2103 D5 PUSH D
0084 2104
0085 2104 3E 90 MVI A,90H ;Control
word
0086 2106 32 03 00 STA 0003H ;Control
Port
0087 2109 0E 50 MVI C,50H ;Counter
value
0088 210B
0089 210B 3E A0 MVI A,0A0H;Output Data
0090 210D 32 02 00 STA 0002H ;Data transferred
to the 8255

;Once a value is set at PORT B wait till the counter reduces to Zero
;Reset the PORT B after the work is done

0095 2110 0D LOOP_F: DCR C


0096 2111 C2 10 21 JNZ LOOP_F
0097 2114
0098 2114 3E 00 MVI A,00H ;Reset
0099 2116 32 02 00 STA 0002H
0100 2119
0101 2119 ;Job is done.Restore the machine register
before passing the control to the Calling Function
0102 2119
0103 2119 D1 POP D
0104 211A 00 NOP
0105 211B C1 POP B
0106 211C F1 POP PSW
0107 211D C9 RET ;Return the Calling
Function
0108 211E
0109 211E
0110 211E
0111 211E F5 BACK: PUSH PSW
0112 211F C5 PUSH B
0113 2120 00 NOP
0114 2121 D5 PUSH D
0115 2122
0116 2122 3E 90 MVI A,90H ;Control word
0117 2124 32 03 00 STA 0003H ;Control Port
0118 2127 0E 50 MVI C,50H ;Counter value
0119 2129
0120 2129 3E 50 MVI A,50H;Output PORT B
0121 212B 32 02 00 STA 0002H
0122 212E
0123 212E ;Decrement to Zero
0124 212E 0D LOOP_B: DCR C
0125 212F C2 2E 21 JNZ LOOP_B
0126 2132
0127 2132 3E 00 MVI A,00H;Reset PORT B to
Zero
0128 2134 32 02 00 STA 0002H
0129 2137
0130 2137 D1 POP D
0131 2138 00 NOP
0132 2139 C1 POP B
0133 213A F1 POP PSW
0134 213B C9 RET
0135 213C
0136 213C F5 RIGHT: PUSH PSW
0137 213D
0138 213D C5 PUSH B
0139 213E 00 NOP
0140 213F D5 PUSH D
0141 2140
0142 2140 3E 90 MVI A,90H ;Control word
0143 2142 32 03 00 STA 0003H ;Control Port
0144 2145 0E 50 MVI C,50H ;Counter value
0145 2147
0146 2147 3E 60 MVI A,60H;Output Data
0147 2149 32 02 00 STA 0002H
0148 214C 0D LOOP_R: DCR C
0149 214D C2 4C 21 JNZ LOOP_R
0150 2150 3E 00 MVI A,00H
0151 2152 32 02 00 STA 0002H
0152 2155
0153 2155 D1 POP D
0154 2156 00 NOP
0155 2157 C1 POP B
0156 2158
0157 2158 F1 POP PSW
0158 2159 C9 RET

0163 215A F5 LEFT: PUSH PSW


0164 215B
0165 215B C5 PUSH B
0166 215C D5 PUSH D
0167 215D
0168 215D 3E 90 MVI A,90H ;Control word
0169 215F 32 03 00 STA 0003H ;Control Port
0170 2162 0E 50 MVI C,50H ;Counter value
0171 2164
0172 2164 3E 90 MVI A,90H;Output Data
0173 2166 32 02 00 STA 0002H
0174 2169
0175 2169 0D LOOP_L: DCR C
0176 216A C2 69 21 JNZ LOOP_L
0177 216D 3E 00 MVI A,00H
0178 216F 32 02 00 STA 0002H
0179 2172
0180 2172 D1 POP D
0181 2173 C1 POP B
0182 2174 F1 POP PSW
0183 2175 C9 RET
0184 2176

También podría gustarte