Professional Documents
Culture Documents
(ECE515)
EXPERIMENT 3
1.0 OBJECTIVES
2.0 PROCEDURE
2.1 PART A
If the left pushbutton is clicked, the left LED is switched on and the right LED is switched off.
The seven-segment LED will display “1”. If the right pushbutton is clicked, the right LED is
switched on and the left LED is switched off. The seven-segment LED will display “2”.
2.2 PART B
Design a program to blink LEDs in 1 second. First, the left LED is switched on and the right LED is
switched off. After 1 second, the left LED is switched off and the right LED is switched on and the
program continue to blink the LEDs.
3. Based on the flowchart and the main program below, write a 1 second delay subroutine.
4. The instruction was wtite in notedpad++
5. The program was run and test by using ARMSim#.
1
3.0 RESULTS
3.1 PART A
START
Button is pressed
Left or right
button
Flowchart 1: PART A
2
Figure 1: The instruction writing in NotePad++
3
Figure 3: when Left black button is pushed
The seven-segment display number “1” and the left turn On
4
Figure 5: The main program of the instruction
The SWI 0x202 is SWI code for black pressed button. CMP is Compare instruction. The CMP R0,
#0x02 is to compare the value of register R0 with the value of #0x02 for the left black button if the
button is pressed. Next is BEQ. The BEQ is branch Equal. If the Register R0 is same to Value of register
R0 then the instruction will run the subroutine of LEFT_BUTTON Subroutine. If the right black button
is pressed then the value of register R0 is same to the value of right black button then the program will
run the RIGHT_BUTTON subroutine. To make a program is always in closed loop, use the instruction
B again. Only execute when there have a input from user or called as interrupt.
5
3.2 PART B
START
LEFT LED ON
(OUTPUT)
DELAY FOR
1 SECOND
RIGHT LED ON
(OUTPUT)
DELAY FOR
1 SECOND
Flowchart 2: PART B
6
Figure 9: the instruction written in Notepad++
The program above showed to display the data in LCD. The MOV R0, #4 is to make space at Column
as much as 4 from the left. The MOV R1, #1 is to skip 1 row from the bottom. The LDR R2,
=MyString. The address of MyString is load into register R2. The SWI 0x204 is the code for LCD in
ARMSim. The MOV R0, #4 is to make space at Column as much as 4 from the left. The MOV R1,
#1 is to skip 1 row from the bottom. The LDR R2, =MyString2. The address of MyString2 is load into
7
register R2. This instruction will be repeated if the words start to the new row. The SWI 0x204 is the
code for LCD in ARMSim.
Figure 12: result for LED blink and display the words
The result of the program executed in figure above to display the word “WELCOME TO THE
CLASS” and “LED BLINKING IN 1 SECOND”
The instruction is MOV R0, #0x02. The value of #0x02 is left code for left LED to light up. The SWI
0x201 is code for LED in ARMSim. The instruction BL MyDelay is Branch to MyDelay as subroutine.
Then instruction of subroutine will be executing till finish. In subroutine, MyDelay is to make the one
led on and other on off. The register R7 load with value 20000 then the value of 20000 will decrement
until zero. The BNE is Branch not equal to zero. The instruction will decrement until the value of
register R7 equal to zero if not the instruction will have repeated. When value of register R7 is equal to
zero the instruction MOV PC, R14 is execute. The register R14 is link Register to restore the last address
when subroutine called. The register R14 is to go back to main program above. Then the instruction for
left LED, MOV R0, #0x01 will executed and left LED will be Off and right LED on for 1 second. The
process of turn on was same to Left LED on.
8
4.0 DISCUSSION
In result part A, the program was written according the situation given in procedure and
the designer of the flowchart is designed based on that situation. The flowchart designed easier to
understand in order to create the program. In this part A, the experiment is performed to display the
number on the seven- segment, Red Led by pressed the black button. All the components above in
simulation ARMSim is used in this part. These components have own SWI code in order to turn on
them. For part A, the situation given is to display number ‘1’ on seven-segment and left red led on when
the left black button is pressed and to display the number ‘2’ and right red led on when the right black
button is pressed. In order to turn on the left or right for both either led or the black button the value of
0x02 and the value of 0x01 need to move into the register. The value of 0x02 is to left side and the value
of 0x01 is for the right side. These values need to move into register R0 for both side of their program.
The main program is to check the value which is if the left black button is pressed, the
instruction will execute the left black button subroutine cause the value of the register R0 and the value
of the left button is equal, the instruction will be doing the subroutine. The operation will be doing same
if the right black button is pressed. But the seven-segment will display number ‘2” and right led will
turn on. The red led turn on is to show the black button is pressed.
The data of the seven-segment need to introduce in .data at the bottom of the instruction.
The data is important because these data will load into register and will display the seven-segment. In
order to turn on the seven-segment, every one-segment of seven-segment have own value, for this part
to display number ‘1’ the data or value of this number is 0x40 | 0x20. These can be seen in figure 8
above in result. To turn the red led only introduced the SWI code for Red led only and move the value
these values #0x02 and #0x01 either to turn on the left side or the right side. In the main program the
branch again is to let the program always waiting for the new input user or interrupt the black button in
order to create a changing on display of the seven-segment. If there is no input the display will not
changes, and it remain until there is an input from user.
For part B, the flowchart is designed to ease the work and to easy understand the flow of
the program. For this part B the program is given but the delay for one second not given. The delay that
required is blinking the led for one second but not blinking together but one by one. The experiment is
to turn on the left red led for one second and turn it off and the right red led turn off and then left red
led turn on then continue until the simulation is stopped. To construct the delay for one second the
explanation in figure 13 in result above. The delay here is subroutine the instruction doing the subroutine
until finished then move to the main program. The value of 20000 that load into register is the value for
countdown for 1 second with subs with #1 until get zero then the instruction will move to PC R14 where
the to turn to main program. For turn on the left and the right-side red led the value need to move into
the register which is the value 0x02 for left side and 0x01 for the right side. For The continuing blinking
is the program must not have SWI 0x11. If the code is put in the instruction the program will stop. The
move PC R14 is also needed to restore the address when the subroutine is called.
For display the words on the display in ARMSim the SWI code needed to introduce. The
SWI code for LCD is SWI 0x204. The instruction of the LCD can be seen in figure 11 in result above.
According to ARMSim user guided the LCD display has X position coordinates form 0-39 that mean
the column has 40 and can put in 40 characters for one row and for Y position coordinates form 0-14.
That mean the row have 15 rows. In this experiment the value #4 move into register R-0 is to skip four
columns from the left and the value #1 move into Register R1 is to skip one row from the top. To display
the word on the display the data need to be load into the register and the data must introduced in .data
at below of the instruction. The asciz is the code for ASCII code for alphabets and numerical.
9
5.0 CONCLUSION
For the conclusion from this lab experiment both part, part A and part B, the students gain the
knowledge on how to write instruction for branch and the subroutine and how that instruction executes
the instruction. Then they also learns on how to design the flow chart by given the situation besides
learn to writing the program for part a and for part learn to write the delay for one second.in this
experiment is difference from experiment one and two. From doing this experiment the student need to
observe the output on the plugin view. ARMSim user guided is referred to write the program because
the ARMsim output and input have their own code need to be introduced in the program in order to use
the input or output components.
10