General Information
Announcements
Web Resources
Other IAP classes
Lectures
1. The Basics
2. Timing, analog hack
3. IR (sony, irda)
4. Our favorite add-ons
Labs
1. Assembling the board.
2. Intro to programming.
3. Input/Output/IR
4. Your own project?
|
Hack Your Room:
Introduction to Microcontrollers
|
Programming the board
There are several programming projects to work on today, starting
simple and getting more and more complicated. You can skip early ones
if you have a good C background and think they would bore you.
For most programs, you probably want to start with Rob Poor's hello.c
program as a template... remove the commands in the main () function
and add your own.
There is a copy of the C manual explaining all the commands you can
use in PIC programming sitting in 4-409 on top of the computer with
the PIC programmer. You can use it there-- don't remove it from the room!
For instructions on how to set up a new project, how to compile, and
how to use the various software in general, consult the Getting
Started portion of Rob's iRX notes.
As always, ask us if you have any questions.
The programming assignments:
Do whichever ones look interesting. The easier ones are at the
beginning of each section.
- Write a program that prints to the computer (over the serial port)
"Hit a key", waits for
the user to hit a key, then turns on the LED.
- PWM and LED brightness:
- Write a program that turns on the LED for a few seconds, then
turns it on at some lower brightness (hint: turning the LED on and off
very quickly and adjusting what percent of the time it is on can set
the brightness).
- Write a program that prints to the computer "Enter a brightness",
waits for the user to enter a number from 0 to 9, then turns on the
LED at that brightness level.
- Write a program that prints to the computer "Enter a brightness",
waits for the user to enter a number from 0 to 9, turns on the
LED at that brightness level, and whenever the user hits another
number, switches immediately to that other brightness level.
- Write a program to blinks the LED at some very specific
frequency. Then look at the output on an oscilloscope. Is this exactly
the frequency you wanted? Does it vary at all? How could you improve
this?
- Digital (on/off) inputs:
- Solder two wires to your board so that when you touch them
together you short one of the unused input pins on the PIC to ground.
Write a program that turns on
the LED whenever the pin is connected to ground.
- Write a program that toggles the state of the LED each time the
pin is connected to ground (if it's off, it should turn on, and vice
versa).
- If you use the previous program, you'll notice that
sometimes when you touch the wires together the PIC may toggle the LED
a few times. Why would this happen? How could you fix this?
- Analog (continuous) inputs and data logging:
- Write a program that reads an analog sensor and prints the value
to the serial port. See Rob's
analog hack for inspiration.
- Write a program that uses the reading of an analog sensor to set
the brightness of an LED. Hook up an adjustable knob (potentiometer)
as the sensor and you have a dimmer!
- Write a program that reads an analog sensor and
prints the current value and the average of the last 10 values to the
serial port.
Solutions (Code)
- Hit a key:
- PWM and LED brightness:
- Digital Input:
- Analog Hack
|