Using ADC features in PIC18F45K20 Microcontrollers & Interfacing to LCD

Purpose: The purpose of this lab is to learn how the ADC operates. This lab contains the following parts:

  1. Programing ADC Unit in the PIC
  2. Creating Random Values Using Assembly Code

Parts Required:

Useful Links:

Procedure:

Part 0 - LCD Display

Purpose: In this section you learn how to interface the PIC with an LCD device - nothing to submit for this section; just do it!

  1. Read about how to interface the PIC to your LCD. Correction: In the schematic make sure you connect the Vo to ground (you can do this directly or use a resistoror); connect VDD to 5V and connect VSS to ground.
  2. Setup the PIC-LCD circuit as shown here. (See the correction note above!)
  3. Implement the PIC-LCD C code. Review the configuration setup.
  4. Make sure the LCD operates properly.

Part I.A - Programing ADC Unit in the PIC and displaying the input on an LCD

Purpose: In this section review how we incorporate the LCD and interrupt functionalities.

  1. Review the available code for implementing an interrupt.
  2. Make sure you understand why/how the given code works to enable interrupts work.

Part I.B - Programing ADC Unit in the PIC and displaying the input on an LCD

Purpose: In this section you learn how to code the ADC module in the PIC (use LCD to display).

  1. Review the demo board's Layout and see how the potentiometer is connected to the chip.
  2. Read Section 19 in Data Sheet for PIC18F46K20 very carefully.
  3. Carefully review the example on page 381 & Section 12.3 of the textbook. You can also read about how ADC in PIC operates.
  4. On your prototype board build a circuit such that it contains a potentiometer, an LCD, and the PIC chip. The potentiometer must be connected to Power and GND of the PIC chip.
  5. Write a program such that by changing the potentiometer on the board, the output of the 10-bit ADC (ADRESH/L) changes. You must display the exact voltage value (in decimal) on an LCD display. Your displayed value should be very close to what you read form the multimeter. Use RA0 as you input (optional). Clearly show all the register settings in PIC.
  6. You can use the ADC example C code.
  7. You can set the acquisition time to 48 usec (Taqu-time) and set conversion time to 4 usec (TAD = 4usec).
  8. What to submit: Just make sure it works!

Part II - Working with the LCD

Purpose: In this section you learn how to manipulate the displayed values on the LCD.

  1. Change your program in Part I such that if the input analog signal is equal or above a certain value the display shows HIGH in the second row (line), otherwise the LCD displays LOW. The actual input value must be displayed on the first line of the LCD.
  2. What to submit:
    1. Complete diagram of the circuit; all power lines and programming lines, as well as used IO GPIO ports must be shown clearly on paper. You must use a Circuit Drawing Tool (Digikey).
    2. Submit the flowchart for the program.
    3. Show all the configuration bits in the program - take a snapshot of your configuration portion of your code.
    4. Simulate an op-amp-based circuit such that any input within the range of 0-3V can be converted to about 0-5V. You should show the scope results for both input and output. Show the schematic. Make sure the measurements are clearly shown on your scope snapshot. Explain the results. You can use https://easyeda.com/ or http://www.mouser.com/MultiSimBlue/ to run your simulation.

PROJECT IDEA - Just think about these (nothing to submit!)

Now that you have learned about interfacing the PIC to an LCD and how to configure the ADC peripheral, it is possible to interface your PIC to various sensors using analog interfaces.

  1. Read about how ADC in PIC operates and how you can interface it to an ultrasonic or accelerometer sensor.
  2. Interface the PIC to the accelerometer or ultrasonic sensor.
  3. You can use the ADC example C code.
  4. Change the code to display the results on an LCD.

_________________ Up to hear! - Ignore these___________________

Part III - Generating Random Numbers

Purpose: In this section you learn how to generate random values on the LCD.

  1. Write a program such that every time you press a button, two random numbers between 1-6 are generated and displayed each corner of the first row of the LCD display. In the middle of the second row you should display the "mean" to one decimal place. For example assume in the first try the two random numbers are 1 and 5 then the mean should be 6/2=3. Assume you press the switch again and you get two new numbers, say 3 and 4. Thus, the new mean should be (1+5+3+4)/4=13/4=3.25 --> 3.3. Remember, the program should work for ever unless the power is removed.
  2. What to submit: Submit the flowchart.

Part IV - Combining two Programs

Purpose: In this section you just combine part II and III! The basic idea is that when one presses the button, the LCD goes to a second page and displays the random numbers and the mean value. When the button is released, the first page of the LCD display the analog input value. Make sure the circuit works. Nothing to submit. Note: The key to get this section to work is modular coding. Use subroutines when possible. I only check this part in class!

_________________ old stuff - Ignore these___________________

Part I - Programing ADC Unit in the PIC

Purpose: In this section you learn how to code the ADC module in the PIC (use LCD to display).

  1. Review the demo board's Layout and see how the potentiometer is connected to the chip.
  2. Read Section 19 in Data Sheet for PIC18F46K20 very carefully.
  3. Carefully review the example on page 381 & Section 12.3 of the textbook.
  4. On your prototype board build a circuit such that it contains a potentiometer, a 7-Segment, and the PIC chip. The potentiometer must be connected to Power and GND of the PIC chip.
  5. Write a program such that by changing the potentiometer on the board, the output of the 10-bit ADC (ADRESH/L) changes. You must display the ADC register value on a 7-Segment device. That is, as the potentiometer value changes, you must display a value between 0 and 9 on the 7-Segment. When the potentiometer reaches its maximum value, the display should be 9.
  6. You must make sure that you set the acquisition time to 48 usec (Taqu-time) and set conversion time to 4 usec (TAD = 4usec).
  7. Draw your circuit.
  8. Clearly show all the register settings in PIC.

Part II - Creating Random Values

Purpose: In this section you learn how to use shift registers to create an 8-bit random value.

  1. Carefully read P.16 of Every Practical Electronics. Make sure you understand how to generate an 8-bit random number. Here are a few good references: Generation of PRBS Using Shift Registers;
  2. Implement an 8-bit random number generator using an assembly code.
  3. Display the resulting random number on a 7-Segment. HINT: this can be done by assuming any binary number between 0 to 24 is ZERO on the 7-Segment; any binary number between 25 to 49 is ONE, and so on.
  4. Include a flowchart in your submission. Bad flowcharts with receive ZERO. There is no partial credit!

 

Write a program such that by changing the potentiometer on the board, the output of the 10-bit ADC (ADRESH/L) changes. You must display the ADC register value on an LCD device. That is, as the potentiometer value changes, you must display a value between 0 and 9 on the 7-Segment. When the potentiometer reaches its maximum value, the display should be 9. Use RA0 as you input.