PComp Assignment 2
Posted on September 22, 2005 at 05:19 PM by sj695

For our second Physical Computing lab assignment we had to program a pic chip using a version of Basic.
Day 1
Last night I was able to get a LED to blink by writing the following code:
'Define the clock speed
DEFINE OSC 4
'These are the ports i'm working with
OUTPUT portb.1 '34 Pin Number
OUTPUT portb.4 '37 Pin Number
OUTPUT portb.7 '40 Pin Number
'Start Main Function
main:
' Turn on Port 1
HIGH portb.1
' Leave on for half a second
PAUSE 500
'Turn off Port 1
LOW portb.1
'Turn off for half a second
PAUSE 500
' Go back and repeat
goto main
Seems simple, but the most difficult portion of the Lab was setting up the bread board. After receiving help from other students in the lab I had the board setup in 2 hours of course I also had to solder and wire my switch (I didn't use a switch in assignment 1). The programming took about 15 minutes.
Day 2
Today I disassembled my board to make sure i knew what was going on and to aslo add and program my switch. Reassembling my board was really helpful and I feel like I have a much clearer idea of what's going on. Here is the code I used to turn the LED on and off with the switch:
input portb.0
output portd.1
main:
if portb.0 = 1 then ' if the switch is closed on pin RB0
low portd.1 ' set pin RD1 low
else
high portd.1 ' set RD1 high
endif
goto main
I also added a potentiometer to fad the LED when the switch was on, I was going to attempt to start next weeks lab but decided to wait.
