|
Lab InstructionsIn this lab assignment you will learn how to interface a Microchip PIC 16F877 to a terminal which contains a keyboard and a CRT display. The amount of hardware required to complete the lab will be fairly small (a 16F877, SP233A transceiver, a clock "can", and a few resistors and capacitors), but there will be a substantial amount of software to write and debug. A discussion of the assignment and a recommended procedure for completing the work is given below. If you have additional questions, please ask the TAs. Please get started on the assignment early. Review the lecture material and remember that there is a online quiz 2/9/04-2/11/04. Demos for Lab 1 will be held 2/19/04-2/20/04. TasksFor this lab you should complete the following tasks.
ProcedureThe best way to complete the tasks listed above is through a divide-and-conquer approach. If you have completed the introductory lab exercise, you have learned that the MPLAB-ICD can be very helpful in identifying and fixing design bugs. I also highly recommend the use of MPSIM to test the functionality of your software. Step 1: System start-up / Writing to Port BAfter reviewing the lecture notes for the lab and reading the assigned sections in the data sheet and Peatman, I suggest the following simple task: write a three bit value to Port B to illuminate three LEDs. As discussed in lecture, consider the issues that must be addressed to accomplish this [setting the Reset vector at 0000h to jump to the start of code, configuring the data direction register (TRISB), and writing an three-bit value to the Port B data register (PORTB), address 0006h]. Consider using the MPLAB-ICD for single-stepping to test your hardware in addition to programming your 16F877. Step 2: Reading from Port AOnce you have verified that your 16F877 starts up correctly from reset and is writing a value to Port B that you have hard-coded in the program, change it to echo the three data bits from Port A to the three LEDs attached to Port B. This requires the configuration of Port A using the TRISA and ADCON1 registers. Step 3: Configuring the UARTAs mentioned in lecture, several registers must be configured in order to get the UART working correctly. These registers include TXSTA, RCSTA, and SPBRG. Before attempting to read or write an eight-bit data value from/to the UART, make sure these registers have been set to the correct value. Pay particular attention to setting the baud rate generator correctly for 9600 baud communication. Check the lecture notes, Chapter 11 of Peatman, and the 16F877 data sheet for more detail on setting the baud rate generator. Step 4: Reading a character from the terminal keyboard and writing it to the terminal displayAs an initial step to verify the correct operation of the UART, it is desirable to program the 16F877 to READ a character from the terminal keyboard and then immediately send the character back to the terminal display (CRT) unchanged. If you run into difficulty in performing this test, consider hard-coding a character into your code and transmitting it the display before attempting to read a character. Note that for this assignment you will be using polling instead of interrupts to determine the status of the receive and transmit buffers. This indicates that your code should repetitively check the full/empty bits in register PIR1 for transmission/receipt of UART data rather than using interrupts to indicate when the resources are free. To convert ASCII values received from the terminal to numbers, use a simple calculation to determine the value of the character (don’t write a if statement with 8 different cases). Step 5: Putting it all togetherI suggest an incremental approach to completing the lab. One solution is to have one partner focus on the hardware setup including Ports A and B while the other partner writes software to configure and use the USART. The MPLAB-ICD can be used to single-step the 16F877 if you run into difficulty. Things to keep in mindOften it may appear that hardware is not working the way that is expected. An initial reaction would be to assume that the hardware is broken and needs to be replaced. Before going to find the TA keep the following questions in mind:
GradingQuizFor the pre-demo quiz I will ask each student individually a few general questions about the main concepts used in the lab (e.g., UART operation and basic PIC properties) as well as issues encountered during implementation. It is expected that each team member has an understanding of all components of the lab. DemonstrationThe demonstration should show communication between the 16F877 and the terminal via the MAX232 part. The specific tasks to be presented are listed above in the "Tasks" section. The 16F877 and MAX232 part should be populated on the breadboard along with a 4 MHz clock "can" which is used to drive the 16F877 clock. It is OK to use the MPLAB-ICD for debugging but the 16F877 should be populated separately on the board for final check-off. Lab ReportIn addition to the demo a complete final report for each two-person lab group has to be turned in. Specific sections in the report include:
The overall lab report should be 5-8 pages long (not including the schematics and code). Please type the report – you may draw the schematics by hand (using a ruler J) if you prefer. |
|