ECE383: Microcomputers â Lab 7 PIC24 System Startup, expanded
Transcription
ECE383: Microcomputers â Lab 7 PIC24 System Startup, expanded
ECE383: Microcomputers – Lab 7 PIC24 System Startup, expanded PIC24 System Printed Circuit Board, and LCD interfacing Goals: The goals of this lab are to introduce students to a PIC24-based hardware system, interfacing an LCD display, and C programming of the PIC24 system. 1. Introduction This lab introduces basic PIC24 system, C programming of that system, and interfacing of a liquid crystal display (LCD). The tasks in this lab are: • • • • • On an NI ELVIS breadboard, construct a modified version of the PIC24HJ32GP202 reference system given in Chapter 8 of the textbook. Use bootloader software to download and execute a program in the PIC24 system. Construct an expanded PIC24 system schematic and PCB layout incorporating an LCD display. Expand the PIC24HJ32GP202 reference system on the NI ELVIS breadboard to include an LCD display. Implement LCD programming tasks using the C language. Read through the entire lab and scan any supplied files before starting work. The reporting requirements have you verify operations performed by the PIC24 system and corresponding C programs. 2. TASK 1: Wiring a Basic PIC24 system For this task you will construct a basic PIC24 system on the ELVIS protoboard. The PIC24 system to wire is given in Figure 1. Figure 1. Basic PIC24 System. 1|Page • • • • Wire the PIC24 system according to the diagram given in Figure 1. o Use wiring guidelines given in lab 1 for this circuit. o Consult datasheets for any components you might have questions about. o The 3.3V output from the LM2937-3.3 voltage regulator should be attached to all power rails on the ELVIS protoboard. o The GND connection on the ELVIS protoboard should be attached to all the GND rails on the ELVIS protoboard. o The TA will provide you with a PIC24 programmed with the bootloader software. Show your wired breadboard to the TA. Do not apply power to it before the TA has checked it. Remove the PIC24 from the board before applying power to the ELVIS protoboard. Turn on the power switch to the ELVIS unit and the ELVIS protoboard. Your power LED should come on. Configure the ELVIS multimeter to measure voltage. Use the multimeter to verify that the breadboard power rails have approximately 3.3 V. TA check: Show the TA the wired PIC24 system and the measurement of voltage on all ELVIS protoboard power rails. 3. TASK 2: Downloading a Program with the Bootloader • • • • • • • Plug your PIC24 back into the board. Ensure that you have your USB-to-Serial cable plugged into the board and into your PC. Start up the Bully Bootloader on your PC. Select the COM port for USB-To-Serial cable. If you do not know the COM port number, then use the ‘Device Manager’ under Control Panel->System->Hardware->Device Manager to see a list of serial ports. Click on a serial port, and will see a description of the PORT – the USB-to-Serial manufacturer should be labeled as ‘FTDI’ with location ‘on USB Serial Converter’. Select the 57600 baud rate in the bootloader window, and click the ‘Open Port’ checkbox to open the port. Copy the chap8 files from the text library to a suitable directory on your PC hard disk. Start MPLAB. Open the project echo.mcp (note: you must start MPLAB first, then open the project file – do not open the project file by double-clicking on it since it does not have a workspace file with it). Compile the echo.mcp project. This project reads a character from the serial port, increments it, and echoes it back (so ‘1’ is echoed as ‘2’, ‘a’ as ‘b’, etc.). Use the HexFile button in the bootloader to browse to the echo.hex file produced during compilation. Click on the ‘MCLR# and Prgrm’ button in the bootloader to download the program into your PIC24 μC (you should see some text appear in the lower window indicating that the program is downloading). Test the echo.c program functionality by using the ‘Send’ button to send some text to the PIC24 μC. You should see it echoed back, with the characters incremented by 1. Modify the echo.c program to increment the character by 2 instead of by 1. Verify this operation and capture a screenshot of its execution. TA check: Show the TA the operation of the modified echo.c program. Use a screen capture tool to capture output windows and include them in your lab report. Include your source language programs in your lab report. 2|Page 4. TASK 3: Expanded PIC24 System with LCD Display Using PCB Artist, create an expanded PIC24 system as shown in Figure 2 below. You may use your schematic from the previous lab as a starting point for this design. For this task you will incorporate an LCD interface (4-bit mode) to the basic PIC24 system. The LCD module used in this lab is HDM16216L-5 from Hantronix. It allows character output in 2 lines with 16 characters per line. This LCD supports both 4-bit and 8-bit interfaces. The datasheet for this LCD module can be found here: http://www.hantronix.com/down/16216l5.pdf. The LCD interface is divided into control lines (E, R/W#, RS), data lines (D7:D0) and power (VDD, VSS, VL, K, A). The 4-bit interface mode used in this lab is used to reduce the number of connections between the PIC24 and LCD module, allowing 4 transfer lines to be used (D7:D4) and the rest (D3:D0) to be unused. Figure 2 shows a PIC24 to LCD interface for a HDM16216L-5 using the HD44780 LCD controller. Additional description can be found in Chapter 8 of the textbook (pages 302-306). The HDM16216L-5 component is located in the ece383 PCB Artist library on the class website. Figure 2. Expanded PIC24 System Schematic. 3|Page The LCD display requires pullup resistors (R3a-R3g in Figure 2) on the data and control lines to operate properly. Use the RA8C component from the discrete library for this component. This component will correspond to an eight resistor pack in a single inline pin (SIP) package available in the lab. We will only be using seven of the eight available resistors in the component. TA check: Show the TA the schematic design. Use a screen capture tool to capture the schematic window and include it in your lab report. An example screenshot is given below. 5. TASK 4: PIC24 System Printed Circuit Board Layout For this task we will create a printed circuit board layout from the PIC24 schematic created as a part of task 3. The board size should be 100mm x 80mm. The board part number should be “ECE383-LAB7” and the Revision Number should be “001”. These parameters can be set through the PCB wizard. Use your experience from previous labs to create a PCB similar to the diagram shown in Figure 3 below. Figure 3. PIC24 System Printed Circuit Board. TA check: Show the TA the printed circuit board you completed. Include a printout of your PCB in your lab report. 4|Page 6. TASK 5: Interfacing the LCD Display to the PIC24 System For this task you will interface an LCD display (4-bit mode) to the PIC24 system constructed in task 1. The LCD requires a 5V power supply (to be provided by the NI ELVIS), and therefore needs special consideration in wiring to the Microstick operating at 3.3V. Logic voltage level translation can be accomplished by using the open drain configuration and pull-up resistors. In addition, all “digital only” pins on PIC24 are 5V tolerant. Wire the LCD as follows: • Wire all data connections as shown in Figure 2: o Pins RB[5:8] on the PIC24 should be connected to D[4:7] on the LCD module (U3 on the schematic) leaving D[0:3] on the LCD module unconnected. o Lines D[4:7] should also be pulled up to +5V using a resistor bank. Pin 1 on the resistor bank is designated with a black dot on the component. All resistors are connected internally to pin 1. Remaining pins on the resistor pack represent the remaining terminal for all resistors in the component. o VBB (Vss) on the LCD module should be connected to ground (GND). o VDD on the LCD module should be connected to 5V (from NI ELVIS). o The VDD – VL voltage difference determines the intensity of the characters displayed on the LCD. VL can be connected to the wiper terminal of a thumbwheel potentiometer, with another lead on the potentiometer connected to the VDD node and the other connected to ground. In our setup, we will connect VL to ground for maximum intensity. TA check: Show the TA the LCD interfaced to the PIC24. Include a picture (from a cell phone) of the LCD interfaced to the PIC24 in the report. 7. TASK 6: Character String Output to LCD For this task we will use and modify the lcd4bit.mcp project. • • • • • Copy the chap8 files to a suitable directory on your PC hard disk. Start MPLAB. Open the project lcd4bit.mcp. Modify the lcd4bit.c code to use open drain configuration for all pins connected to the LCD and configured as outputs (data lines, R/W, etc). Using “lcd4bit.c” as a starting point, create a program that is capable of displaying your first and last name on the LCD screen as well as your email address. o Write a function that displays your first and last name on the top line of the LCD, moves the cursors to the bottom line (1st position) of the LCD, then writes your email address on the bottom line of the LCD. o The characters should scroll across the display (moving right to left) at a rate of 200 ms. Compile and download the program to the PIC24 system as in Task 2. TA check: Show the TA the operation of the program. Include your source language programs in your lab report. Include a picture (from a cell phone) of the LCD displaying your name. 5|Page 8. TASK 7: Counter Output to LCD For this task, you will implement a counter with a visual output to the LCD. • • • Using the project lcd4bit.mcp as a basis, create a new project named counter_LCD.mcp. For this task, you will create a program (counter_LCD.c) that will output an incremental counter to the LCD screen as follows: o Upon initialization of the program, output a character string “000” to the LCD screen. o When SW2 is pressed and released, the number on the LCD screen should increment by 1. o Once program counts to “20”, the number of the LCD screen should change back to “000” and begin incrementing again on the press and release of SW2. An interrupt service routine should be programmed to handle the state changes of the pushbutton. Code from the project button_semaphore.mcp in the chap9 directory should be useful. TA check: Show the TA the operation of the counter_LCD.c program. Include your source language program in your lab report. Include a picture (from a cell phone) of the LCD displaying your counter values (one picture will suffice). 9. Laboratory Report No later than a week from the day the lab is performed, provide the TA a printed copy of the lab report following the ECE383 Lab report Template given on the class website. Each lab group will submit one joint lab report to the TA. Your report should have the reporting requirements needed for Tasks 1-7. The TA will take off a significant number of points (15 points from total lab grade) if your C source does not have the required comments. 10. GRADING POLICY 1. 2. 3. 4. 5. 6. 7. 8. Completion of Task 1 with results included in lab report (15%) Completion of Task 2 with results included in lab report (10%) Completion of Task 3 with results included in lab report (10%) Completion of Task 4 with results included in lab report (10%) Completion of Task 5 with results included in lab report (15%) Completion of Task 6 with results included in lab report (15%) Completion of Task 7 with results included in lab report (15%) Completeness, quality, and correctness of the lab report (10%) 6|Page