ME333 Sample Code

From Mech
Jump to navigationJump to search

A Crash Course in C

Section A.1: HelloWorld.c

Section A.4: printout.c, datasizes.c, overflow.c, typecast.c, invest.c

Section A.4.16: helper.h, helper.c, main.c

Problems, Section A.5: bubble.c, lights.c, hexdump.c

Chapter 1 - Quickstart

simplePIC.c, simplePIC_standalone.c, talkingPIC.c, NU32bootloaded.ld, NU32.c, NU32.h

Chapter 3 - Looking Under The Hood: Software

Problem 6: makefile (save as "makefile"; make sure there is no .txt extension)

Chapter 4 - Using Libraries

All Chapter 4 code (zip)

-> LCD code, has a bug

Chapter 5 - Time and Space

timing.c

-> add a timing.c with coreTimer?

Chapter 6 - Interrupts

All Chapter 6 code (zip)

-> these are all plib, check all or change to registers, some plib fns did not work last year

Chapter 7 - Digital Input and Output

All Chapter 7 code (zip)

Chapter 8 - Counters / Timers

All Chapter 8 code (zip)

Chapter 9 - Output Compare

All Chapter 9 code (zip)

Chapter 10 - Analog Input

All Chapter 10 code (zip)

Chapter 11 - UART

All Chapter 11 code (zip)

Chapter 12 - SPI Communication

All Chapter 12 code (zip)

Chapter 13 - I2C Communication

All Chapter 13 code (zip)

Chapter 14 - USB

All Chapter 14 code (zip)

Chapter 15 - Input Capture

All Chapter 15 code (zip)

Chapter 16 - Comparator

All Chapter 16 code (zip)

Chapter 17 - Watchdog Timer

All Chapter 17 code (zip)

Chapter 18 - Storing Data in Flash Memory

All Chapter 18 code (zip)

Chapter 19 - Power Saving: Sleep, Idle, and Freeze

All Chapter 19 code (zip)

Chapter 20 - Real-time Clock and Calendar

All Chapter 20 code (zip)

Chapter 21 - Controller Area Network (CAN)

All Chapter 21 code (zip)

Chapter 22 - Direct Memory Access

All Chapter 22 code (zip)

Chapter 23 - Sensors and Signal Conditioning

All Chapter 23 code (zip)

Chapter 24 - Digital Signal processing

All Chapter 24 code (zip)

Chapter 25 - Brushed Permanent Magnet DC Motors

All Chapter 25 code (zip)

Chapter 26 - DC Motor Control

All Chapter 26 code (zip)

Chapter 27 - Brushless Motor Control

All Chapter 27 code (zip)

Chapter 28 - Stepper Motors and RC Servos

All Chapter 28 code (zip)

Chapter 29 - Connecting to an Android Device

All Chapter 29 code (zip)




Final Project

OLD PIC32 Code

DIP PIC32 with reconfigurable pins (1/2xx) (11/21)

  • Reconfiguring the pins.

Simple PIC

  • simplePIC.c: Flashes LEDs on the NU32 unless the USER button is pressed.

NU32 library, header file, procdefs, and terminal comm test

Interrupts

  • INT_core_timer.c: Interrupt on core timer period match.
  • INT_ext_int.c: Interrupt on rising edge of external interrupt line INT0.
  • Peripheral timer interrupt.

Digital I/O

  • DIGIO_sfrs.c: Digital I/O and change notification using SFR manipulation.
  • DIGIO_plib.c: Digital I/O and change notification using the peripheral library.

Counter/timer

Output compare (PWM)

  • OC_PWM_nolib.c: Set up PWM by setting SFRs.
  • OC_PWM_lib.c: Set up PWM using peripheral library functions.
  • OC_square_wave.c: Alternate between two different PWM duty cycles at 1 Hz. PWM is at 100 kHz and can be low-pass filtered to get a square wave analog output.

Analog to digital (11/16)

  • ADC_Read2.c: Reads two analog inputs repetitively and prints the results to the user's terminal.
  • ADC_Read2_LCD.c Reads two analog inputs repetitively and prints the results to the LCD.
  • Something else, scanning mode, asynchronous results check on the buffer, and/or interrupt generated when some results are ready.

Applications

DSP and FFT

Reading a quadrature encoder with the dsPIC33FJ12MC201 breakout board

Controlling a stepper motor with the TB6612

Controlling an RC servo motor