17
GROUP EVALUATION FORM Laboratory 3: Interfacing with Ports using EMU8086 Group No: 1 Section: EL1 Lab Schedule: Monday 6:00- 9:00 Group Members Date Performed: February 7, 2010 1. De Jesus, Jayson Date Submitted: February 14, 2010 2.Orteza, JB Exercises 3.Tan, Howard Prog Problems 4. Tingjuy, Charles Teamwork Evaluation Grade EVALUATION: (for lab instructor only) Exercises (50%)

Experiment 3 Final

Embed Size (px)

DESCRIPTION

IO devices and ports

Citation preview

Page 1: Experiment 3 Final

GROUP EVALUATION FORMLaboratory 3: Interfacing with Ports using EMU8086

Group No: 1 Section: EL1 Lab Schedule: Monday 6:00-9:00

Group Members Date Performed: February 7, 2010

1. De Jesus, Jayson Date Submitted: February 14, 2010

2. Orteza, JB Exercises

3. Tan, Howard Prog Problems

4. Tingjuy, Charles Teamwork

Evaluation Grade

EVALUATION: (for lab instructor only)

Exercises (50%)

Page 2: Experiment 3 Final

Programming Problems (50%)

LABORATORY NO. 3Interfacing with Ports using EMU8086

I. Objective To understand the concept of interfacing the outside world using ports. To apply the port interfacing concepts using IO devices.

II. Coponents to be borrowed PC power cords (2) Keyboard Mouse EMU8086

III. Conceptual Framework

For this exercise, virtual devices will be used to understand the concept of interfacing with external devices using ports. These virtual devices are available in EMU8086 software. Discussion of each device is provided below: (source: Emu8086 Help Option)

Devices are available from: “Virtual Devices” menu of the emulator.

Traffic Lights - Port 4 (word)

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.

Page 3: Experiment 3 Final

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

For example:

MOV AX, 0000001011110100bOUT 4, AX

*For the output: Refer to the figure below…

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.

Page 4: Experiment 3 Final

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 Binary Value Action0 00000000 Do nothing.1 00000001 Move Forward.2 00000010 Turn Left.3 00000011 Turn Right.4 00000100 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.

5 00000101 Switch On a Lamp.

Page 5: Experiment 3 Final

6 00000110 Switch Off a Lamp.

Second byte (Port 10) is a Data Register. This register is set after robot completes the Examine command:

Decimal Value Binary Value Meaning255 11111111 Wall0 00000000 Nothing7 00000111 Switched-On Lamp8 00001000 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.

Bit Number DescriptionBit #0 Zero when there is no new data in Data Register, one when there

is new data in Data Register.Bit #1 Zero when robot is ready for next command, one when robot is

busy doing some task.Bit # 2 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?

____________________________________________________________________________________________________________________________

Page 6: Experiment 3 Final

____________________________________________________________________________________________________________________________

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, 0000000000000001OUT 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:

Page 7: Experiment 3 Final

#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,4WHILE: MOV BL,0 LOOP WHILE MOV CX,5 ACT2:

Page 8: Experiment 3 Final

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?): $'

Page 9: Experiment 3 Final

#2. #MAKE_BIN##CS = 500##DS = 500##SS = 500##SP = FFFF##IP = 0#R_PORT EQU 9

Page 10: Experiment 3 Final

eternal_loop:

CALL WAIT_ROBOT

MOV AL, 4OUT R_PORT, ALCALL WAIT_EXAM

IN AL, R_PORT + 1

CMP AL, 0JE cont

CMP AL, 255JE cont

CMP AL, 7JNE lamp_off

CALL SWITCH_OFF_LAMPJMP cont lamp_off: NOP

cont:CALL RANDOM_TURNCALL WAIT_ROBOT

MOV AL, 1OUT R_PORT, ALCALL WAIT_ROBOT

MOV AL, 1OUT R_PORT, ALJMP eternal_loop

WAIT_ROBOT PROC

busy: IN AL, R_PORT+2TEST AL, 00000010bJNZ busy RETWAIT_ROBOT ENDP

WAIT_EXAM PROC

Page 11: Experiment 3 Final

busy2: IN AL, R_PORT+2TEST AL, 00000001bJZ busy2

SWITCH_OFF_LAMP PROCMOV AL, 6OUT R_PORT, ALRETSWITCH_OFF_LAMP ENDP

RANDOM_TURN PROC

MOV AH, 0INT 1Ah

XOR DH, DLXOR CH, CLXOR CH, DHTEST CH, 2JZ no_turnTEST CH, 1JNZ turn_right

MOV AL, 2OUT R_PORT, AL

RETturn_right:MOV AL, 3OUT R_PORT, ALno_turn:RETRANDOM_TURN ENDP

Page 12: Experiment 3 Final
Page 13: Experiment 3 Final

VII. Analysis and Conclusion

Charles Tingjuy

From the given experiment, it is obviously understood that Emu8086 assembler is a whole new and more fun environment for the world of assembly programming. It is with direct association to the microprocessor 8086 as it emulates in a software manner the given codes in the command module. The assembler also shows what could possibly happen in robots, displays, motors, etc. when a given code is executed and it is shown virtually from the emulators virtual devices tab.

For the first task, the concept of traffic lights in intersecting lanes is being executed where each traffic light has 3 bits where each bit represents a red, yellow and a green light respectively where the binary code 1 means that the corresponding color is lit up. In total of 4 traffic lights means there are 12 lights in all resulting to 12 bits for the system. For the stepper motor, the concept from the previous task is done where 3 bits represent the way the motor is turned either in a clockwise rotation or vice versa.

For the robot, as observed from the given codes, its motion depends on what it senses. If there is a wall right in front of him, he turns to another direction. If a closed or lighted bulb is in front of him, he lights the bulb or closes it respectively. Putting all these three together, with some codes will result to a cool daily applied thing. For example, combining the stepper motor for a draw bridge and the traffic light will result to a traffic system for a river draw bridge. For the robot, well, the only task assigned was to close all lighted bulbs.

JB Orteza

Experiment 3 allows us to fully understand how the EMU8086 works. It allows us to emulate a given program. It shows virtual devices such as robots, motors and other devices.

For the first part of the experiment, we were asked to run a traffic light. Each light corresponds to a certain arrangement of 1’s and 0’s in the 12 low bits which enables us to control and manipulate the order of the traffic lights. As a result, only one traffic light can be turned off when emulated.

For the second part of the experiment, we were asked to run the stepper motor file. It is the same thing as the first one wherein each rotation is represented by 3 bit-bode. The stepper motor can turn either in a clockwise or counter clockwise rotation.

For the last part, the mobot acts based on its program. In the robot file, the mobot actually moves randomly. It either stops or moves and can either turn on or off a light bulb. In the practice problem, we have been able to program the mobot wherein when it senses a turned-on light bulb, the mobot will turn it off.

Jayson De Jesus

In this experiment, we are to use different virtual devices each differ in characteristic or functions. One of which is the traffic light. As in real traffic light, in such, we are to enter 4 inputs ranging from 1-4 to have an output. We are to manipulate 12 bits that are shown through 1's and

Page 14: Experiment 3 Final

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.