单片机代写-LAB 4
时间:2021-02-18
LAB 4 Page 1
© Copyright David Elmo Ross 2019
NAME: _______________________________ STUDENT ID #: ______________________________

LAB 4: DigitalOut, DigitalIn, RGB LEDS, and Pushbuttons

LAB SECTION: A B C D E F G H I J K L M N O P
OBJECTIVES:
1. Export a program into the MBED Compiler, and correct any errors of logic or coding, then RUN it.
2. Export the program to MCUXpresso
2. MODIFY your flashing LED program so that RED GREEN and BLUE LEDS flash on/off in
sequence.
3. Use ANSI Escape Sequences to SHOW the current Colour of the LEDS on the PC SCREEN.
Back Ground: 1. You should know the basics of how a light emitting diode works.
2. You should also know about current limiting resistors required by leds.
3. You should know the HARDWARE specifics of the
LED INTERFACE for FRDM-K64.
4. You should know how to use the
DigitalOut and DigitalIn Class.
5. You should also know the SOFTWARE specifics for using the
INTERNAL and EXTERNAL LED
LAB 4 Page 2
© Copyright David Elmo Ross 2019
Procedure:
1. Click on THIS LINK to import a version of the program below into the MBED Compiler
2. When the program shown above runs, all leds are OFF. While you hold down just the LEFT PUSH
BUTTON the RED LED flashes. While you hold down just the RIGHT PUSH BUTTON, the
GREEN LED flashes. When NO pushbuttons are pressed, then the LED will be OFF.

This is NOT what happens when you run the Program you imported. But do NOT make any
changes to it. We will export it to MCUXpresso, to find out why it doesn’t work the way it should.
LAB 4 Page 3
© Copyright David Elmo Ross 2019
2. CLONE the program that you imported, and then DELETE the MBED library from the
cloned project, and then COPY and PASTE an MBED library that has CLASSES to the
cloned project. The Project that you had on LAB 3 Part 5 has such a library.
3. EXPORT the Cloned Project without changing it to MCUXPresso.
4. Then IMPORT it into MCUXpresso and use the BLUE BUG to download it onto the FRDM-K64.
5. After the Download is complete what colour is the RGB led? _______
What two colours when mixed together, make up this colour? ____________ and __________.
4. When you STEP OVER the instruction:
led_red = led_green = 1;
Describe the two changes to the original colour after this instruction is executed.
__________________________________________________________________________
Why does this happen? (Hint: Which led is shut off first?)
__________________________________________________________________________
5. When the cursor is on the line: if ( left_pb == 1 ) press the STEP OVER, and note that the
code inside this if statement is executed - EVEN THOUGH THE LEFT PUSHBUTTON was
NOT pressed.
6. If you keep pressing STEP OVER, you will see that ONLY the code in the line if ( left_pb == 1 )
is executed.
7. While the cursor is on the line: if ( left_pb == 1 ) HOLD DOWN the LEFT PUSHBUTTON
and you will see that it the code now goes into the else part of the code which will cause the LED
to turn YELLOW. This is because the RED LED was NOT shut off.
8. Now CLICK on the RED SQUARE button to TERMINATE ALL
DEBUG Sessions.
9. Change the line if ( left_pb ==1 ) to if ( left_pb == 0 ) , and if ( right_pb == 1) to if (right_pb == 0)
10. Now hit the BLUE BUG button, click on the necessary launch line (twice),
then OK for the changes you made, then CLICK the RESUME (F8). This time you should see
the program run properly.
LAB 4 Page 4
© Copyright David Elmo Ross 2019
11. What colour do you get when you mix:
RED and GREEN? ___________ RED and BLUE __________

GREEN and BLUE ___________ RED GREEN and BLUE __________
12. Click on THIS LINK and import this program into MBED.
13. COMPILE IT on MBED. Make sure that you have PUTTY started, then drag and drop the BIN file
to DAPLINK.
14. Hold the FRDM-K64 up to the PUTTY screen and see that the colours on the LEDS match those
on the PUTTY SCREEN.
15. If you comment out the // fflush(stdout); statement in the position function, why do the colours on the
leds and the PUTTY screen not synchronize?

______________________________________________________________
16. Click on THIS LINK , and import this program into MBED.
17. COMPILE IT on MBED. Make sure that you have PUTTY started, then drap and drop the BIN file
to DAPLINK.
18. The PUTTY display will change depending on WHICH pushbutton you press. You can even push
BOTH pushbuttons at the same time.
19. You will find that the statement: printf(“\e[45m”); in this program makes the colour
MAGENTA when you push a pushbutton.
20. Referring to ANSI ESCAPE SEQUENCES, for BACKGROUND colours, change the program
so that when the LEFT pushbutton is pressed, it shows RED instead of MAGENTA, and when
the RIGHT pushbutton is pressed, it shows BLUE instead of MAGENTA.





















































































学霸联盟


essay、essay代写