Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (9.59 MB, 687 trang )
576
Microprocessors
ledflash.c hex file named ledflash_hspll.hex that was produced using the
PIC18 configuration options found in the config.h file, which has the HSPLL oscillator option enabled. The crystal will not oscillate until the PIC18
is programmed with a hex file that has the correct configuration bit settings
for using an external crystal as a clock source.
2. Apply power via your wall transformer and use a multimeter to verify that
you have 5 V to your PIC18. Use the oscilloscope and verify that your
crystal is producing a sinusoidal waveform, and that the reset button produces a low true pulse on the Vpp/MCLR# pin when pressed. Verify that
the LED on port RB1 flashes after power is applied.
Serial Port Verification
ON THE CD
1. Use the wire wrap tool available from the TA and wire the DB9 connector
to the 5-pin header you have used to bring the TX, RX, and Gnd signals off
board. Use a serial cable and connect your board to the serial port of a PC.
Have the TA program your PIC with the echo.c program. This program
reads a character from the serial port, increments it, and then echoes it
back using a baud rate of 19200. Thus, an “a” typed from the keyboard
echoes as “b”, “b” as “c”, and so on. Use HyperTerminal or some other serial port terminal program to verify that the asynchronous serial interface
on your board is working. If it does not work, use the serial port debugging
tips in Section 9.7 and the debugging checklist at the end of this appendix
to isolate the problem.
2. Have the TA program your PIC with the serial bootloader program (bootload_hspll.hex).
3. Compile the ledflash.c program using the PICC-18 compiler and use the
“–a200” flag to produce a hex file that is compatible with the bootloader
(the resulting hex file has the default name of ledflash.hex). The companion
CD-ROM contains a pre-compiled ledflash.c hex file named
ledflash_hspll_a200.hex that was produced using the “–a200” compiler flag
and the PIC18 configuration options found in the config.h file. Use the Jolt
or Colt bootloader (Appendix F) to download either the ledflash.hex file or
the ledflash_hspll_a200.hex file into your PIC18 and verify its operation.
Appendix E: Suggested Laboratory Exercises
577
Current Measurement and reset.c Test
1. Compile the reset.c program and download it into your PIC18F242 system.
Exercise the reset.c program in the same manner as shown in Figure 8.12.
2. Fill in the current measurements for Figure E.4 using the directions in the
following steps. See the prototyping hints at the end of this appendix for instructions on how to measure current using a multimeter.
3. To measure the 7805 current draw, disconnect its +5 V output from the
rest of the circuit and put the ammeter in series with the 9 V input terminal.
4. To measure the current draw of the power LED, determine the difference
in current draw when the power LED is inserted in the circuit, and when it
is removed. To calculate the expected current draw, use the equation I =
V/R; where V = Vdd 0.7 V and R = 470 . The measured and computed values will differ somewhat because the pin driver and LED add extra
resistance to the circuit.
5. To determine the current draw of the PIC in normal operation, place the
PIC in sleep mode via the menu choice of the reset.c program and record
the difference in total current draw. Determine the expected current draw
for the PIC normal mode operation using the Typical IDD vs. FOSC over
VDD (HS/PLL mode) graph in the PIC18 datasheet. Note: the X-axis is the
external crystal frequency.
6. Measure the current draw of the Maxim 202/232 chip by measuring the
input current of the Vdd pin or by noting the difference in current draw
when the chip is removed from the protoboard.
7. The expected total current draw of your board is the sum of the expected
current draw of the individual components.
8. The configuration bits of the PIC18 must be changed to make HS current
measurements. These instructions assume that the current program in the
PIC18 is the reset.c program. Use the Jolt “Read All” command to read all
of the PIC18 program memory contents and current configuration bit settings. Change the FOSC configuration to HS, and use the “Program Config” option to program the new configuration bit setting. After changing
the configuration bits you will need to set the baud rate to 4800, as the
PIC18 is now operating at one-fourth the clock frequency of the HS/PLL
mode. Measure the total board current draw and the PIC current draw in
the same manner as before. The expected PIC18 current draw can be found
in the typical IDD vs. FOSC over VDD (HS mode) graph in the PIC18
datasheet. You should discover that the PIC18 in HS/PLL mode consumes
about 4x the current of HS mode as it is operating 4x faster.
578
Microprocessors
FIGURE E.4 Current measurements for experiment 6.
E.8 EXPERIMENT 7: LED/SWITCH IO AND INTRODUCTION TO
ASYNCHRONOUS SERIAL IO (CHAPTERS 8, 9)
This experiment has the student implement a LED/Switch IO problem using a
finite state machine approach. The student is also introduced to the status bits of
the PIC18 USART module.
Prelab
1. Figure E.5 contains an LED/switch IO problem assignment. For your
assigned problem, draw a state chart similar to that of Figure 8.20 and
make a good faith effort to implement the C code using the same structure
as in Figure 8.21 (the ledsw1.c file can be used as a starting point).
2. Draw the RS232 waveform for an 8-bit data value, 1 start, 1 stop bit, LSb
sent first. The 8-bit data value is based on the last digit of your Student ID
as follows: 0) “e”, 1) “F”, 2) “n”, 3) “S”, 4) “3”, 5) “Z”, 6) “z”, 7) “#”, 8) “u”,
9) “p”. Use an ASCII table to determine the 7-bit value of your character
(the 8th bit is zero).
3. Demo to the TA a spreadsheet that calculates the bit time in microseconds
for any baud rate from 2400 to 115200. Recall that a bit time is equal to one
over the baud rate, and that a microsecond is 10-6 seconds.
Appendix E: Suggested Laboratory Exercises
579
FIGURE E.5 LED/switch IO assignment.
4. Demo to the TA a spreadsheet that calculates the value to be written to the
SPBRG register given an oscillator frequency value, a target baud rate, and
either high-speed or low-speed baud rate mode. The PIC18F242 datasheet
section titled “USART Baud Rate Generator” should prove helpful.