MPLAB - Lab Exercise 1 by Up1H11j


									MCC18LAB - UART Lab Exercise

  1. To create a program to use the PIC 18F452 UART
  2. To understand the use of serial I/O using a UART
  3. To use a library of ‘user written’ C functions

Tasks - Read the whole of this lab exercise now!

1. Copy the files UART.h, UART.c to your homespace.

2. Read through the list of functions provided in uart.h and uart.c( this has the
   actual UART implementation code). Read the notes at the bottom of this
   sheet now!

3. Produce a program that simply prints a message out of the PIC18F452
   serial port.

4. In an endless loop increment a variable and print out the variable in
   decimal and hexadecimal to the serial port.

5. Modify the previous program to prompt the user to enter the 'S' key before
   starting the loop. (Hint use UART_Getchar(void))

6. Modify the previous program to pause while executing the loop if the 'P'
   any key is pressed and to restart when the 'R' key is pressed. (Hint use
   UART_Kbhit(void)and UART_Getchar()functions.)

Copy UART.c, UART.h to the folder containing your C file. [The testUart.c file shows a simple
example of using the UART routines, it is not required in your use of the UART routines.]

To use the UART functions in your program :-
    1. Place #include “UART.h” at the beginning of your C source file, after the other
        #includes. Notice the quotes(“) instead of the angle brackets (< >) to include non-
        system C functions.
    2. Add the UART.c file to your project.
    3. To use the UART function you must call the UART_Init() function once at the
        beginning of your program.
    4. Look at the comments in the UART.h and UART.C files for a description of the
        functions available.
    5. The standard C function itoa() will be needed to convert an integer to its ASCII
        representation. This will require the header file <stdlib.h> to be included in your C
        source file. This will require the declaration of a small character array to hold the
        resulting ASCII characters. See the testUART.c file for an example of using the atoi()

18FXX2.PDF on the system
Lecture Notes/slides.
The UART routines on the system

To top