I have been interested in PIC microcontrollers for several years, after first seeing them in
QST, and I had heard of them from the BASIC Stamp stuff I was doing. I wanted to use them, but kind of
stayed away due to the need for a programmer (simple ones are available, but only for the FLASH
parts, and a PICSTART is $200), and the assembly language that they used. I found out that a
BASIC compiler was available for the PICs, but the $100 cost and the fact that the BASIC coding
was not a flexible as assembly kept me still waiting.
In the summer of 2000, I looked more in-depth at PIC information. I found a programmer that is identical to
the PICSTART, but only costs $100. It is the WARP-13 available from
Newfound Electronics. Then, the factor that really convinced me was the web page written
by Jim Brown on how
to program PICs in assembly language. I already had the MPLAB progam, so I
started writing some simple programs in order to learn basic assembly language instructions. I found
out that with the nice guide, it wasn't as tough as I thought. Also, by using the simulator in MPLAB,
I could run my programs step-by-step and see where the problems were. The simulator was great and so about
two months before I got a programmer and programmed my first PIC, I felt that I
had a reasonably good understanding of basic assembly language programming. I finally got a WARP-13
programmer around the beginning of October 2000, and worked on a few projects with a PIC16C84.
First I just played with eight segments of an LED bargraph, and then moved to three seven-segment
LED displays. I had the segment pins off all three hooked in parallel, and drove them off of the 8-bit port, PORTB.
Then I had the three common pins hooked to seperate pins of the 5-bit port. By multiplexing the common
lines, I could control three segments with only 10 pins. Each digit is in a lookup table that returns a
byte value that is written to PORTB. When the common pin is taken low, the number is displayed. It worked when
I first powered it up. I worked on advancing that program but had problems for awhile and moved on to other projects.
I think that with the programming experience I have now it would be pretty easy for me to do.
After that, I was kinda frustrated and didn't do much with PICs for a couple of months. I wrote a simple program
to control the PLL of the MP20. The code worked, but the hardware interface didn't work correctly. After that
the next major project was in the spring of 2001. It was a lap timer I made for myself to mount to the handlebars
of my dirtbike so that I could time my laps and get faster. It had 8 LEDs that would light differently depending
on how many seconds faster or slower the previous lap was than the one before it. The rider pushed a button at the
same spot on the track every lap to indicate the end of a lap. It used repeated subtraction to determine how much
faster or slower the last lap was. It was a great idea and I tried it out once, but the
battery holder I was using was very intermittent and made the timer keep resetting every few seconds. I need to get
a better battery holder and try it again.
The next large project was in July 2001 and was done to help with the code for the tank. I wrote a program
to control a "standard" Hitachi HD44780-based LCD. I got the basic program working and then modified it to run in
the 4-bit data mode. This cut the number of control lines needed from 10 to 6, and was pretty simple. When I finished
that, I worked on using the same port of the PIC for both the data lines and control lines. All this did was make the
code a bit more messy. The final enhancement to the program was placing all of the LCD signals on PORTC, which on the
16F873 is the same port that the USART (serial port) is on. Since the LCD only uses 6 port pins, I modified the program to free up the transmit
and receive lines, and then made a simple serial terminal so that I could type on the computer and have the LCD update, as well
as send data back to the PC. With this done, I left the code alone because it will let me use an LCD and serial comms
in future projects (I was planning to use it in the tank, but found out we couldn't use bidirectional data because the
radio couldn't switch between transmit and receive fast enough) using only PORTC and leaving ports A and C open for use
in the application. Some of the code (I got it from a more recent program and edited out all but the LCD stuff) can be
seen here. The "LCD control functions" are just routines I wrote to make some common LCD tasks easier.
I have written several other programs for the tank, including some experimental joystick decoding code, a test program
for the video overlay board, servo control code, an H-bridge test controller, and some modem test code. I also got a
book on Windows programming in C and wrote a couple tank programs in C for Windows (they use the Win API and look like VB
programs) that interface to a PIC.
On one weekend during March of 2002, my math class was given an optional extra credit project to write a program that
would calculate the sine and cosine of a number from 0 to 360 degrees by converting the angle to radians, dividing the
angle into one of eight 45 degree segments (pi/4 rad), then using Taylor Series' to find the sin and cos of the angle
(over the 0 to 45 degree segment), and then using identities to find the final sin and cos values. I thought it would be
neat to use a PIC as the computer and write the code in C. For input I decided to use a rotary encoder that I had and use
an LCD for output. I spent most of the following Saturday working on the code, and got the Taylor Series, input, and
output working. It took a while longer to implement the identities, and I started running out of space in the PIC, even
though it was a 16F627 with 4K of ROM. After that was done there was another problem that I fixed by type casting a variable
in one of the equations. That took me a while to find, and when I was done with that I modified a copy of the program to
find the sin and cos of all angles between 0 and 360 degrees and output the results to the serial port (for part of the
assigment we had to turn in a listing of the values that the program calculated).
|