EC7412: MICROCONTROLLER AND INTERFACING LABORATORY
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT 1
Presentation Slides:
www.sathieshkumar.com/tutorials
Presented By,
Dr. V. Sathiesh Kumar Department of Electronics Engg.,
MIT-Anna University
Overview 1. Basic assembly language program using 8086 2. 8255-Programmable peripheral interface 3. Stepper Motor Interfacing 4. Traffic Light Control System 5. DAC Interface using DAC0808 6. ADC Interface using ADC0804
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
2
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
8086 Architecture:
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
3
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
8086 Pin Details:
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
4
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
Procedure to enter a program
1. Switch on the 8086 kit, Type A and enter.
2. Type in the starting address and press enter. Example: A8000
3. Enter the mnemonics.
Procedure to input data or view the output data
1. Type M input/output address and press enter key. Example: M8150
2. Update the locations with desired bytes.
Procedure to execute the program
1. Press reset key.
2. Type G starting address of code and press enter key. Example: G8000
3. Press RES Key
4. Check the output data after execution of the program.
Key Functions
RES (RESET) : This key allows the user to terminate any activity and return to an
initialized state.
Procedure to view the program
1. Type U starting address of code and press enter key. Example: U8000
2. To view next instruction, press Space Bar
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
5
8086 Programming: Addition of two 16-bit numbers
# BEGIN 1000H
MOV AX,1212
MOV BX,1212
ADD AX,BX
MOV SI,1200
MOV [SI],AX
HLT //Program End
// ANSWER-> 1200 = 24H, 1201 = 24H
# BEGIN 1000H
MOV SI,1200
LODSW
MOV BX,AX
LODSW
ADD BX,AX
MOV DI,1300
MOV [DI],BX
HLT // Program End
//INPUT-> 1200=13H, 1201=13H, 1202=14H, 1203=14H ANSWER-> 1300=27H, 1301=27H
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
6
8086 Programming: Subtraction of two 16-bit numbers
# BEGIN 1000H
MOV SI,1200
LODSW
MOV BX,AX
LODSW
SUB BX,AX
MOV DI,1300
MOV [DI],BX
HLT // Program End
//INPUT-> 1200=08H, 1201=08H, 1202=04H, 1203=04H ANSWER-> 1300=04H, 1301=04H
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
7
8086 Programming: Multiplication of two 16-bit numbers
# BEGIN 1000H
MOV SI,1200
LODSW
MOV BX,AX
LODSW
MUL BX
MOV DI,1300
MOV [DI],AX
INC DI
INC DI
MOV [DI],DX
HLT // Program End
//INPUT-> 1200=03H, 1201=03H, 1202=02H, 1203=00H ANSWER-> 1300=06H, 1301=06H
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
8
8086 Programming: Division of two 16-bit numbers
# BEGIN 1000H
MOV DX,0000
MOV AX,0006
MOV CX,0002
DIV CX
MOV DI,1300
MOV [DI],AL
INC DI
MOV [DI],AH
INC DI
MOV [DI],DX
HLT // Program End
//INPUT-> AX=0006H, CX=0002H ANSWER-> 1300=03H, 1301=00H, 1302=00H (REMAINDER)
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
9
8086 Programming: Largest no in an array
# BEGIN 1000H
MOV SI,1200
MOV CL,[SI]
INC SI
MOV AL,[SI]
DEC CL
LOOP: INC SI
CMP AL,[SI]
JNB LOOP1
MOV AL,[SI]
LOOP1: DEC CL
JNZ LOOP
MOV DI,1300
MOV [DI],AL
HLT // Program End
//INPUT-> 1200=06H (COUNT), 1201=02H, 1202=AAH, 1203=F0H, 1204=89H, 1205=F4H, 1206=0AH
//ANSWER-> 1300=F4H
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
10
8086 Programming: Smallest no in an array
# BEGIN 1000H
MOV SI,1200
MOV CL,[SI]
INC SI
MOV AL,[SI]
DEC CL
LOOP: INC SI
CMP AL,[SI]
JB LOOP1
MOV AL,[SI]
LOOP1: DEC CL
JNZ LOOP
MOV DI,1300
MOV [DI],AL
HLT // Program End
//INPUT-> 1200=06H (COUNT), 1201=02H, 1202=AAH, 1203=F0H, 1204=89H, 1205=F4H, 1206=0AH
//ANSWER-> 1300=02H
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
11
8086 Programming: Fibonacci Series
# BEGIN 1000H
MOV CL,10
MOV BL,00
MOV DL,01
MOV DI,1300
MOV AL,DL
LOOP: ADD AL,BL
MOV [DI],AL
INC DI
MOV BL,DL
MOV DL,AL
DEC CL
JNZ LOOP
HLT // Program End
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
12
8086 Programming: Factorial of a number
# BEGIN 1000H
MOV CL,04
MOV AL,01
MOV BL,01
LOOP: MUL BL
INC BL
DEC CL
JNZ LOOP
MOV DI,1300
MOV [DI],AX
HLT // Program End
// ANSWER-> 1300=18H
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
13
8086 Programming: Ascending order
# BEGIN 1000H
MOV DX,[5000]
LOOP3: MOV CX,DX
MOV SI,5002
LOOP2: MOV AX,[SI]
CMP AX,[SI+02]
JL LOOP1
XCHG [SI+02],AX
XCHG [SI],AX
LOOP1: ADD SI,0002
LOOP LOOP2
DEC DX
JNZ LOOP3
INT 3 // BREAKPOINT
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
14
8086 Programming: Descending order
# BEGIN 1000H
MOV DX,[5000]
LOOP3: MOV CX,DX
MOV SI,5002
LOOP2: MOV AX,[SI]
CMP AX,[SI+02]
JGE LOOP1
XCHG [SI+02],AX
XCHG [SI],AX
LOOP1: ADD SI,0002
LOOP LOOP2
DEC DX
JNZ LOOP3
INT 3 // BREAKPOINT
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
15
8086 Programming: Matrix Addition
# BEGIN 1000H
MOV CL,09
MOV SI,1200
MOV DI,1300
LOOP: MOV AL,[SI]
MOV BL,[DI]
ADD AL,BL
MOV [DI],AL
INC DI
INC SI
DEC CL
JNZ LOOP
HLT
//INPUT: 1200 02H, 02H, 02H 1300 02H, 02H, 02H OUTPUT
1203 03H, 03H, 03H 1303 03H, 03H, 03H 1300 04H,04H,04H
1206 04H, 04H, 04H 1306 04H, 04H, 04H 1303 06H,06H,06H
1306 08H,08H,08H
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
16
8255 Programmable peripheral interface (PPI):
1. Is used to give the CPU access to programmable parallel I/O
2. 24 Input/Output pins (PORTA, PORTB, PORTC) in all
3. D0-D7 data bus lines are available to read/write data into the ports or control register
using RD and WR.
4. Address lines A1 and A0 allow to successively access any one of the ports or the
control register.
5. CS is used to enable 8255 chip
6. On Reset, all the ports are initialized as input line
A1 A0 PORT SELECTED
0 0 PORTA
0 1 PORTB
1 0 PORTC
1 1 Control Register
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
17
Modes of 8255 Programmable peripheral interface (PPI):
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
18
Bit set/reset mode (BSR Mode):
1. Applicable only to PORTC
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
19
Input/Output mode (I/O Mode):
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
20
8255 Pin Details:
EC7412: MICROCONTROLLER INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
21
Stepper Motor Interfacing:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
• Applications: Disk drives, Dot matrix printers and in robotics
• Step angle: Minimum degree of rotation associated with a single step
• 8086 Address for 8255 Interface
A
B
A
B
Control Word (Clockwise)
0 1 1 1 0x07
1 0 1 1 0x0B
1 1 0 1 0x0D
1 1 1 0 0x0E
+12 V
A
A
B
B
Socket Connections
Control word register 0xFF26
PORTA 0xFF20
PORTB 0xFF22
PORTC 0xFF24
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
22
Stepper Motor Interfacing:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
A
B
A
B
Control Word (Clockwise)
0 0 1 1 0x03
1 0 0 1 0x09
1 1 0 0 0x0C
0 1 1 0 0x06
A and B are generated using NOT gate
PA2 is for supply to the coil or motor
PA2
PA1
A
PA0
B
Control Word
(Clockwise)
1 0 0 0x04
1 0 1 0x05
1 1 1 0x07
1 1 0 0x06
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
23
Stepper Motor Interfacing:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
MOV DX,FF26H //Load DX with the address of control register
MOV AL,80H //Enable I/O mode
OUT DX,AL
START: MOV DX,FF20H //Move the address of PORTA to DX
MOV AL,05H //Start the clockwise rotation sequence
OUT DX,AL
CALL DELAY
MOV AL,07H
OUT DX,AL
CALL DELAY
MOV AL,06H
OUT DX,AL
CALL DELAY
MOV AL,04H
OUT DX,AL
CALL DELAY
JMP START
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
24
Stepper Motor Interfacing:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
DELAY SUBROUTINE:
MOV BX,0010H
L2: MOV AL,FFH
L1: NOP
NOP
NOP
NOP
DEC AL
JNZ L1
DEC BX
JNZ L2
RET
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
25
Stepper Motor Interfacing:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
MOV DX,FF26H //Load DX with the address of control register
MOV AL,80H //Enable I/O mode
OUT DX,AL
START: MOV DX,FF20H //Move the address of PORTA to DX
MOV AL,04H //Start the anti-clockwise rotation sequence
OUT DX,AL
CALL DELAY
MOV AL,06H
OUT DX,AL
CALL DELAY
MOV AL,07H
OUT DX,AL
CALL DELAY
MOV AL,05H
OUT DX,AL
CALL DELAY
JMP START
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
26
Stepper Motor Interfacing:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
DELAY SUBROUTINE:
MOV BX,0010H
L2: MOV AL,FFH
L1: NOP
NOP
NOP
NOP
DEC AL
JNZ L1
DEC BX
JNZ L2
RET
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
27
Traffic Light Control System:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
EG1 EG2 EG3
EY
ER
WR
WY
WG1 WG2 WG3
SR
SY
SG
1
SG
2
SG
3
NG
1
NG
2
NG
3
NY
NR
EAST
WEST
NORTH SOUTH
R1B
P2B
R1B
P2B
R2C P1C
P1C R2C
P2A
R1A
P2A
R1A
R2D P1D
R2D P1D
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
28
Traffic Light Control System:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
P1D P2A P1C P2B R2C R1A R2D R1B
PEDESTRIAN CONTROL LED-PORTB (Address:0x21H)
B0 B7
0- LED OFF
1- LED ON
X- Don’t Care (0 or 1)
NR &SR
ER & WR
EY & WY
NY & SY
NG3 &SG1
NG2 & SG2
EG2 & WG2
EG3 & WG1
A0 A7
TRAFFIC CONTROL LED-PORTA (Address:0x20H)
TRAFFIC CONTROL LED-PORTC(Address:0x22H)
X X X X X X SG3 & NG1
EG1 & WG3
C0 C7
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
29
Traffic Light Control System:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
R R
P
P
R R
R R
R R
R R
R R
P
P
R
R
R
R
R
R
R
R
R R
R R
R
R
R
R
R R
R R
R
R
R
R
P P
P P
R
R
R
R
1 2 3
4 5 6
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
30
Traffic Light Control System:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
MOV AL,80H //I/O Mode
MOV DX,FF26H // Load DX with address of control word register
OUT DX,AL // Control word register=0xFF26
LOOP: MOV AL,0FH // For pedestrian
MOV DX,FF22H
OUT DX,AL
MOV AL,4DH // For green leds in N-S direction
MOV DX,FF20H
OUT DX,AL
CALL DELAY // Sequence delay
CALL AMBER // Amber delay
MOV AL,8BH // For stopping N-S direction & starting in E-W direction
MOV DX,FF20H
OUT DX,AL
CALL DELAY
CALL AMBER
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
31
Traffic Light Control System:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
MOV AL,49H // For free left in all sides & stopping E-W direction
MOV DX,FF20H
OUT DX,AL
MOV AL,01H // For right turn in N-S direction
MOV DX,FF24H
OUT DX,AL
CALL DELAY
MOV AL,00H // For Amber signal
MOV DX,FF24H
OUT DX,AL
CALL AMBER
MOV AL,89H // For stopping vechicles in N-S direction
MOV DX,FF20H
OUT DX,AL
MOV AL,02H // For right turn in E-W direction
MOV DX,FF24H
OUT DX,AL
CALL DELAY
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
32
Traffic Light Control System:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
MOV AL,00H
MOV DX,FF24H
OUT DX,AL
MOV AL,30H
MOV DX,FF20H
OUT DX,AL
MVI CL,04H
CALL DELAYSUB // For Amber delay
MOV AL,C0H // For stopping vehicles in all direction
MOV DX,FF20H
OUT DX,AL
MOV AL, F0H // Green signal for pedestrian
MOV DX,FF22H
OUT DX,AL
MVI CL,10H
CALL DELAYSUB
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
33
Traffic Light Control System:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
MOV AL,30H
MOV DX,FF20H
OUT DX,AL
MOV CL,08H
CALL DELAYSUB
JMP LOOP
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
34
Traffic Light Control System:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
AMBER SUBROUTINE:
MOV AL,39H // For amber signal in all directions
MOV DX,FF20H
OUT DX,AL
MOV CL,08H
CALL DELAYSUB
RET
DELAY SUBROUTINE:
MOV CL,40H
CALL DELAYSUB
RET
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
35
Traffic Light Control System:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
DELAYSUB SUBROUTINE:
L3: MOV BL,FFH
L2: MOV AL,FFH
L1: NOP
DCR AL
JNZ L1
DCR BL
JNZ L2
MOV AL,CL
JZ OUT
DCR CL
JNZ L3
OUT: RET
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
36
DAC Interface:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
DAC 0808 is a 8-bit DAC
Binary weighted DAC and R/2R ladder type
DAC0808 (8-bit) provides 256 discrete voltage or current levels of output
7 6 5 3 04 2 1( )2 4 8 16 32 64 128 256
out ref
D D D D DD D DI I
2refI mA
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
37
DAC Interface:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
38
DAC Interface:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
SQUARE WAVEFORM GENERATION
MOV AL,80H // I/O mode
MOV DX,FF26H // Load DX with control word register address
OUT DX,AL
START: MOV AL,FFH // Logic high level
MOV DX,FF20H // Load DX with PORTA address
OUT DX,AL
CALL DELAY
MOV AL,00H // Logic low level
OUT DX,AL
CALL DELAY
JMP START
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
39
DAC Interface:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
SQUARE WAVEFORM GENERATION
DELAY SUBROUTINE:
MOV BL,05H
L1: MOV CL,FFH
L2: DEC CL
JNZ L2
DEC BL
JNZ L1
RET
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
40
DAC Interface:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
SAWTOOTH WAVEFORM GENERATION
MOV AL,80H // I/O mode
MOV DX,FF26H // Load DX with control word register address
OUT DX,AL
START: MOV AL,00H // Initialize AL register
MOV DX,FF20H // Load DX with PORTA address
L1: OUT DX,AL
INC AL
JNZ L1
JMP START
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
41
ADC Interface:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
1 1606
1.1 1.1 10 150
11.65
f kHzRC k pF
t sf
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
42
ADC Interface:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
Vref/2 (V) Vin (V) Step Size (mV)
Not connected 0 to 5 5/256=19.53
2.0 0 to 4 4/256=15.62
1.5 0 to 3 3/256=11.71
1.28 0 to 2.56 2.56/256=10
When Vref/2 is not connected (open), Vref/2 is measured at 2.5 V for Vcc=5V
Step Size (Resolution) is the smallest change that can be discerned by an ADC
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
43
ADC Interface:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
MOV DX,FF26H // Load DX with the address of control register
MOV AL,90H // CWR for PORTA as Input , PORTB & C as Output
OUT DX,AL
MOV DX,FF24H // PORTC is enabled for WR
MOV AL,FFH
OUT DX,AL
MOV AL,00H // WR must be a low to high transition
OUT DX,AL
MOV AL,FFH
OUT DX,AL
CALL DELAY // Delay routine
MOV DX,FF20H //Load DX with the address of PORTA
IN AL,DX // Read the ADC value from PORTA
INT 3 // Breakpoint
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
44
ADC Interface:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
DELAY SUBROUTINE:
MOV CX,FFFFH
L1: NOP
NOP
DEC CX
JNE L1
RET
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT
45
Summary:
EC7412: MICROCONTROLLER AND INTERFACING LABORATORY 8086
Architecture and pin details of 8086 microprocessor
Basic assembly language programming using 8086 microprocessor
Architecture and pin details of 8255
Stepper motor interfacing
Traffic light control system
DAC interface using DAC0808
ADC interface using ADC0804
Dr. V. SATHIESH KUMAR Department of Electronics Engineering, MIT