ME 333 Lab 2

From Mech
Jump to navigationJump to search

PCB Artist

You should be familiar with making a circuit schematic and PCB design in PCB Artist.

Demonstrate that you can build a PCB by editing the following: ...

PIC32: Basic I/O and debugging

In this lab you will practice interfacing your NU32 PIC32 board to simple circuits.

The goal of this lab is to design and breadboard a circuit that reads an analog voltage from a potentiometer and constantly outputs the value of the voltage on the LCD as well as turns on an LED when the reading is over a certain value. When a push button, external to your NU32 PIC32 board, is pressed, the PIC sends the value of the voltage at that moment to a PC via an RS232 to USB cable and is displayed on your computer screen. You will put together this code in sections. This code covers the following topics:

  • Digital Output
  • Digital Input
  • Analog Input
  • Writing to Parallel LCD
  • Communicating with PC with RS232
    • To begin, create a new folder called ME333_Lab2 on your computer.
    • Copy and Paste HardwareProfile.h, HardwareProfile_NU32.h and the procdefs.ld file from HelloWorld into this new project folder.
    • In MPLAB, create a new project called ME333_Lab2 and add the above files to the project. (You have to move procdefs.ld to the ‘Other Files’ folder).
    • Add the 2 include paths (as done in HelloWorld) and the constant PIC32_NU32.

Digital Output

  • In MPLAB, create a new file and save it as ME333_Lab2.c.
  • Add this source file to your project.
  • Copy and Paste the code on PIC32MX: Digital Outputs into this new source file.
  • This code currently turns on / off PINS D1-D4 depending on the user switch on your board. Change this to turn on / off pins A2 and A3 with the following modifications
    • change the #define to only use A2 and A3
    • change the initialization (TRISx and LATx) to only have A2 and A3 as digital outputs (What are the hex numbers you need for this?)
    • change the if statement to turn on A2 and turn off A3 when the user switch is pressed and otherwise turn on A2 and turn on A3. (Note that swUser is 1 when not pressed).
  • Circuit: You will need 2 LEDs and 2x 1k resistors. Create an LED circuit that has one end connected to 3.3 V and the other end connected to the pin. Do this for both A2 and A3. (This is a sink).
  • Build the Hex file (Build All) and program this on your board. Verify that A3 is on when the switch is not pressed and A2 is on when the switch is pressed.

You have now completed the Digital Output section.



Work out this lab in steps:

  • Get a potentiometer and a push button and practice and PIC32MX: Analog Inputs.
  • Get an LCD and follow the instructions on PIC32MX: Parallel LCD to write a program to control it.
  • Follow the instructions at PIC32MX: RS232 and write a program that sends a message to a PC over the RS232 to USB cable in your group box.

When you have finished, demonstrate your circuit to the TA.