Sie sind auf Seite 1von 6

Dire Dawa Institute of Technology

Department of Electrical and Computer Engineering


ECEg4161: Microcomputer and interfacing
Lab Experiment No – 6: IN and OUT Instructions
1. The emulator has different I/O devices such as LED display, stepper motor, traffic light
and robot. The port address of the devices is:
LED display port address 199
Stepper motor port address 7
Traffic light port address 4
Robot port address 9, 10, and 11

The following program is used to display values in registers to LED display, before you run the
program open the LED display from the virtual devices of the emulator window. The display
counts in decimal, while the accumulator count in hexadecimal.

1. MOV AX, 00H;

START: OUT 199, AX

INC AX

JMP START

HLT

2. Write a program that count (increment) and display values from 0 to 10 and then
decrement from 10 to 0 in the LED display.
2. Stepper motor

The Stepper Motor is controlled by sending data to I/O Port 7. Stepper Motor is electric motor
that can be precisely controlled by signals from a computer. The motor turns through a precise
angle each time it receives a signal. By varying the rate at which signal pulses are produced, the
motor can be run at different speeds or turned through an exact angle and then stopped.

This is a basic 3-phase stepper motor, it has 3 magnets controlled by bits 0, 1 and 2. Other bits
(3…7) are unused. When magnet is working it becomes red. The arrow in the left upper corner
shows the direction of the last motor move. Green line is here just to see that it is really rotating.

1
The motor can be half stepped by turning on pair of magnets, followed by a single and so on.

The motor can be full stepped by turning on pair of magnets, followed by another pair of
magnets and in the end followed by a single magnet and so on.

Half step is equal to 11.25 degrees.

Full step is equal to 22.5 degrees.

The motor can be turned both clock-wise and counter clock-wise direction.

1. The program below will do three clock-wise and counter clock-wise half steps:
a. MOV AL, 001b; initialize [full – step]
OUT 7, AL
MOV AL, 011b; half step 1
OUT 7, AL
MOV AL, 010b; half step 2
OUT 7, AL
MOV AL, 110b; half step 3
OUT 7, AL
b. MOV AL, 100b; initialize [full - step]
OUT 7, AL
MOV AL, 110b; half step 1
OUT 7, AL
MOV AL, 010b; half step 2
OUT 7, AL
MOV AL, 011b; half step 3
OUT 7, AL
2. Write a program to rotate the stepper motor 45° clock – wise direction first, then 45°
counter clock – wise direction using half steps.

Method - 1

a. MOV AL, 001b; initialize [full - step]


OUT 7, AL

2
MOV AL, 011b; half step 1- CW
OUT 7, AL
MOV AL, 010b; half step 2- CW
OUT 7, AL
MOV AL, 011b; half step 1- CCW
OUT 7, AL
MOV AL, 001b; half step 2- CCW
OUT 7, AL
MOV AL, 110b; half step 3- CCW
OUT 7, AL
MOV AL, 010b; half step 4- CCW
OUT 7, AL

Method – 2

b. MOV AL, 110b; half step 1 – CW


OUT 7, AL
MOV AL, 100b; half step 2 – CW
OUT 7, AL
MOV AL, 011b; half step 3 – CW
OUT 7, AL
MOV AL, 010b; half step 4 – CW
OUT 7, AL
MOV AL, 011b; half step 1 – CCW
OUT 7, AL
MOV AL, 001b; half step 2 – CCW
OUT 7, AL
MOV AL, 110b; half step 3 – CCW
OUT 7, AL
MOV AL, 010b; half step 4 – CCW
OUT 7, AL
3. The program below will do three clock-wise and counter clock-wise full steps:

3
a. MOV AL, 001b;
OUT 7, AL
MOV AL, 011b;
OUT 7, AL
MOV AL, 110b;
OUT 7, AL
MOV AL, 001b;
OUT 7, AL
b. MOV AL, 100b;
OUT 7, AL
MOV AL, 110b;
OUT 7, AL
MOV AL, 011b;
OUT 7, AL
MOV AL, 100b;
OUT 7, AL
4. Write a program to rotate the stepper motor 90° clock – wise direction first, then 90°
counter clock – wise direction using full steps.
3. Traffic Lights

The traffic lights are controlled by sending data to I/O port 4. There are 12 lamps: 4 green, 4
yellow, and 4 red.

You can set the state of each lamp by setting its bit

1 – The lamp is turned on

0 – The lamp is turned off

Only 12 low bits of a word are used (0 to 11), last bits (12 to 15) are unused.

1. Write the following program and open the traffic light from the virtual devices menu and
then see the effect of the program.
MOV AX, all_red
OUT 4, AX
MOV SI, OFFSET situation
NEXT:
MOV AX, [SI]
4
OUT 4, AX
CALL No_operation
ADD SI, 2; next situation
CMP SI, sit_end
JB NEXT
MOV SI, OFFSET situation
JMP NEXT
RET
situation DW 0000001100001100b;
s1 DW 0000011010011010b;
s2 DW 0000100001100001b;
s3 DW 0000010011010011b;
sit_end = $
all_red EQU 0000001001001001b;
Nooperation:
NOP;
NOP;
RET
2. Write the following program using another method and open the traffic light from the
virtual devices menu and then see the effect of the program.
MOV AX, all_red;
OUT 4, AX;
NEXT:
MOV AX, 30CH;
OUT 4, AX;
CALL No_Operation
CALL No_Operation
MOV AX, 69AH;
OUT 4, AX
CALL No_Operation
MOV AX, 861H;
OUT 4, AX
CALL No_Operation
CALL No_Operation
MOV AX, 4D3H;
OUT 4, AX
CALL No_Operation
JMP NEXT
all_red EQU 0000001001001001b;
No_Operation:
NOP;
5
NOP;
RET

Observation

Conclusion

Das könnte Ihnen auch gefallen