Getting My Feet Wet With
PIC Microcontroller Development


I jumped into this knowing diddly about electronics. Sure, I knew which end of the radio plugged in and which end you carried into the shower, but that was about it. Then, one day while I was binding my own business, I received an email to take a look at David Ek's digital setting circle project. The brains of this project were a PIC16F84. The PIC 16F84 is a embedded microprocessor which contains the CPU and program loaded into it. When the power comes on it begins to do whatever you tell it to. That could be things like read optical encoders and send their value out of a serial port, control LEDs, LCDs, read buttons, real-time clocks and more. Very cool. I already knew how to program, but now I needed to learn electronics 101. Oh ya, I needed a way to send the program to the PIC also.

The 'F' in the 16F84 means that it's a Flash programmable PIC. You drop the PIC chip into a ZIF (Zero Insertion Force) socket and tell the PIC programmer to send your program to it. Don't confuse the Programmer and the program that it sends to the PIC. The Programmer is a piece of hardware that plugs into your computer and sends instructions to the PIC chip. Those instructions are the program that you write and they tell the PIC what to do. The programmer that I'm using is a L866-3G (the ZIF a must!). You will likely also want the ability to do In-Circuit Programming where the programmer connects directly to the circuit with the PIC instead of needing to remove the chip for programming.

I want to throw in a plug for Jameco, Mouser and Digikey all offer a great selection for parts.

While there are a number of languages to program a PIC there are three that rise above the rest: Assembly, Pic Basic and Pic Basic Pro, and C. Assembly is popular because it's free and usually generates the most compact compiled code. Pic Basic is popular because, well, it's BASIC and probably the easiest language to learn. In the middle is C, which is often called a high level assembler. Since I've been programming in C since 1986 on the Amiga 1000 and since then in DOS, Windows (pick a version, any version) and Unix (Solaris), C was my language of choice for the PIC also. The good news was that there were a number of PIC C compilers to choose from. After I weighed in cost and capabilities, the CCS C compiler was the clear winner. The PCM version of the CCS compiler handles the 14bit core PICs which covers the 16Fx series and more.

With a Programmer and compiler in hand it was time to load up some PICs with code and see what they could do.

LCD Interface

This is my second CCS C program on a PIC. The first was the required blinking LED to the tune of 'Hello World'. The brain is a 16F628 running at 20 MHz. The thing that amazed me was that it worked on the first try. The law of averages finally worked in my favor! I need to rewire the B4-B7 wires (4 yellow wires from the LCD to the PIC) so that I can use those pins for the B interrupt on the buttons.

Multiplexing

This board multiplexes four 7-segment LED numbers. That's a fancy way of saying that it blinks between each number fast enough that they look like that are solid lights. This allows a limited number of pins to control many LEDs. Each additional number only requites one additional pin on the PIC after the first number is wires up. A side benefit is that it used less power since only one number is on at a time, of course they are a little dimmer than if each were on all of the time. With all good things there is a drawback. If too many numbers are on the same 'loop' they will start to blink visually. The plans for this setup are here: http://picbasic.com/resources/articles/ledart.htm. I rewrote the code in C, of course, and it's running in a PIC 16F88. This test cycled through the four LEDs 500 times with a 100 microsecond pause on each LED before incrementing the display to the next number.

I finally got Pulse Wave Modulation (PWM) working on a 16F88 using the 8MHz internal clock. At the moment it's just changing the brightness of a LED. Fortunately that's enough to control an astronomy map lamp. A bonus to this change is that power not going to the LED will be conserved better than burning it off as heat if a potentiometer was used. The 16F88 was chosen because it has an internal clock, PWM and analog to digital inputs.

Projects on the virtual drawing board...

I want to make a light meter for measuring the brightness of the night sky. This will allow me to quantify different locations as better or worse for astronomy. The intent is to use a TSL230 light to frequency chip and then a PIC to count the frequency. A simple LED or LCD display would be enough, but storing the date, time and light reading (maybe digital compass direction also?) and storing the results in a I2C eeprom with serial output would be pretty cool, and well within the ability of a PIC, if not me ;) This may depend on the success of the next item on the to-do list.

Mail