Experiment 3 Final
Experiment 3 Final
GROUP EVALUATION FORM Laboratory 3: Interfacing with Ports using EMU8086 Section: EL1 Lab Schedule: Monday 6:00-9:00 Date Performed: February 7, 2010 Date Submitted: February 14, 2010 Exercises Prog Problems Teamwork Evaluation Grade
Stepper Motor Port 7 (byte) 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. The motor can be half 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. The best way to make full step is to make two half steps. 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. Robot The Robot is controlled by sending data I/O Port 9. First byte (Port 9) is a Command Register. Set values to this port to make robot do something. Supported Values: Deximal Value 0 1 2 3 4 Binary Value 00000000 00000001 00000010 00000011 00000100 Action Do nothing. Move Forward. Turn Left. Turn Right. Examine. Examines an object in front using sensor. When robot completes the task, result is sent to Data Register and Bit #0 of Status Register is set to 1. Switch On a Lamp. Switch Off a Lamp.
5 6
00000101 00000110
Second byte (Port 10) is a Data Register. This register is set after robot completes the Examine command: Decimal Value 255 0 7 8 Binary Value 11111111 00000000 00000111 00001000 Meaning Wall Nothing Switched-On Lamp Switched-Off Lamp
Third byte (Port 11) is a Status Register. Read values from this port to determine the state of the robot. Each bit has a specific property.
Description Zero when there is no new data in Data Register, one when there is new data in Data Register. Zero when robot is ready for next command, one when robot is busy doing some task. Zero when there is no error on last command execution, one when there is an error on command execution (when robot cannot complete the task: move, turn, examine, switch on/off lamp).
IV. Procedure: 1. Compile and execute TRAFFIC.asm code. 2. Give a short description on what is happening. ______________________________________________________________ ______________________________________________________________ ______________________________________________________________ ______________________________________________________________ 3. Make some changes so that only the number 0 green light is on, and write the code made. 4. Compile and execute STEPPER.asm. 5. Indicate what happens to the Stepper motor. How many times did it turn and what direction? ______________________________________________________________ ______________________________________________________________ ______________________________________________________________ ______________________________________________________________ 6. Compile and execute ROBOT.asm code. 7. What happens to the mobot? ______________________________________________________________ ______________________________________________________________ ______________________________________________________________ ______________________________________________________________ 8. When the bulb is lighted off and vice versa, what does the mobot do? ______________________________________________________________ ______________________________________________________________ ______________________________________________________________ ______________________________________________________________ V. Data and Results 2. Give a short description on what is happening.
There are 4 different situations happen at a time. We are asked to choose from 1 to 4. Each number corresponds to a traffic light off one side of the road. For example, if we choose 1, one side of the road will turn off and the other three will turn on. Same applies to the other inputs but with different traffic light. 3. Make some changes so that only the number 0 green light is on, and write the code made. MOV AX, 0000000000000001 OUT 4, AX 5. Indicate what happens to the Stepper motor. How many times did it turn and what direction? It turned 8 times and it rotated in clockwise direction. 7. What happens to the mobot? It moves randomly. We cannot predict where the mobot would go whether it goes up, down, left or right. It also stops and then walks. 8. When the bulb is lighted off and vice versa, what does the mobot do? When the bulb is off, the mobot turns it on and vice versa. VI. Programming Problems: 1. Consider a bridge that connects Lane 012 and Lane 678. A stepper motor controls the bridge. A clockwise rotation of the stepper motor closes the bridge and a counter clockwise rotation opens the bridge. The traffic light will denote if a vehicle can pass thru the bridge or not. A red light means the bridge is closed therefore vehicles cannot pass thru the bridge while a green light signifies bridge is open. Write as assembly code that will simulate this scenario. 2. Write an assembly code that will control the robot to turn OFF all lamps. Assume there are only three lamps on the arena. Obstacles must be present such as wall. Answer Codes: #1.
#MAKE_BIN# #CS=500# #ip=0# MAIN: JMP START DISP: LEA DX,[MSG] MOV AH,9 INT 21H
RET ;-----------------------------------------------; first retracion mode ;Green light, bridge down ONE: MOV AX,CS MOV DS,AX MOV SI,0 MOV CX,5 ACT1: MOV AL,datCCW[SI] OUT 7,AL ADD SI,1 LOOP ACT1 MOV AX,0104H OUT 4,AX CALL MAIN ;------------------------------------------------;second retraction mode ;red light bridge up TWO: MOV AX,0041H OUT 4,AX MOV AX,CS MOV DS,AX MOV SI,0 MOV CX,4 WHILE: MOV BL,0 LOOP WHILE MOV CX,5 ACT2: MOV AL,datCW[SI] OUT 7,AL INC SI LOOP ACT2 CALL MAIN ;-----------------------------------------------;main command line START: CALL DISP MOV AH,1 INT 21H CMP AL,'1'
JE ONE CMP AL,'2' JE TWO END: MOV AH,4CH INT 21H ;motor and light actions datCW db 001b db 011b db 110b db 000b datCCW db 100b db 110b db 011b db 000b ; initial display MSG DB 13,19,'<Press any key to exit>',13,10, 'Enter Bridge Retraction Signal(1 or 2?): $'
#2. #MAKE_BIN# #CS = 500# #DS = 500# #SS = 500# #SP = FFFF# #IP = 0# R_PORT EQU 9 eternal_loop: CALL WAIT_ROBOT MOV AL, 4 OUT R_PORT, AL CALL WAIT_EXAM IN AL, R_PORT + 1 CMP AL, 0 JE cont CMP AL, 255 JE cont
CMP AL, 7 JNE lamp_off CALL SWITCH_OFF_LAMP JMP cont lamp_off: NOP cont: CALL RANDOM_TURN CALL WAIT_ROBOT MOV AL, 1 OUT R_PORT, AL CALL WAIT_ROBOT MOV AL, 1 OUT R_PORT, AL JMP eternal_loop WAIT_ROBOT PROC busy: IN AL, R_PORT+2 TEST AL, 00000010b JNZ busy RET WAIT_ROBOT ENDP WAIT_EXAM PROC busy2: IN AL, R_PORT+2 TEST AL, 00000001b JZ busy2 SWITCH_OFF_LAMP PROC MOV AL, 6 OUT R_PORT, AL RET SWITCH_OFF_LAMP ENDP RANDOM_TURN PROC MOV AH, 0 INT 1Ah
XOR DH, DL XOR CH, CL XOR CH, DH TEST CH, 2 JZ no_turn TEST CH, 1 JNZ turn_right MOV AL, 2 OUT R_PORT, AL RET turn_right: MOV AL, 3 OUT R_PORT, AL no_turn: RET RANDOM_TURN ENDP
0's. There are different functions so as to enter number from 1-12 such as performing a green light if such a number 1 is inputted where as the logic 1 would represent different numbers. The same operation will function for the red light whereas if we chose a number from 1-12 to be green light, for example 5, we are suppose to use a different number in assigning for the red light. In this function, there is a motor that would function for a certain number of time where the input changes from time to time.
This kind of experiment lets us practice in creating algorithm for interfacing. If we are to understand the basics of these programming, we are to let our mind be exercised in creating algorithms. In the future, we are to make different interfaces which could help us in our income in our life.
Howard Tan Our group has used three virtual devices in this experiment. The three virtual devices have different characteristics and functions. The traffic light is a device that is used to simulate the real traffic light. The output is dependent on the input values. In this part of the experiment, we were asked to input values 1 to 4in which these values have corresponding functions when inputted. The stepper motor is a device programmed in which it has 4 functions but only one function at a time is performed. The four functions are clockwise (CW), counter-clockwise (CCW), clockwise full step (CW_FS), and counter-clockwise full step (CCW_FS). The robot is a device that functions just like an ordinary machine. It executes a specific program that is programmed in it.
We were able to understand the concept of interfacing the outside world using ports. We were also able to apply the port interfacing concepts using IO devices. The objectives of this experiment were met.