jump to navigation

Vindication! September 18, 2006

Posted by Jason in Electrical Engineering.
2 comments

After hours of internet searches, hardware and software tweaking, and much wailing and gnashing of teeth, I finally managed to get my PIC programmer to work! I just needed to get the right combination of software and hardware and the correct options selected. I’m going to record some of the things I did on here so that I don’t forget them and for the benefit of others who may be trying to do the same thing.

Hardware
The PIC I’m using for this project is the 16F84A. Some notes on the basic circuit requirements:

  • You’ll need a crystal. For this project I used a 4-pin 20 MHz crystal.
  • Tie the MCLR pin on the PIC to Vdd using a 4.7 kΩ resistor.

PIC Programming

  • I’m using WinPicProg 1.95e Beta (download here) in combination with a DIY hardware programmer that operates identically to the P16PRO40 (.pdf) on the WinPicProg website.
  • Under the Hardware option in WinPicProg set Programmer Type to P16PRO40-7406 (my situation specific).
  • When programming with a 20 MHz crystal set the oscillator fuse to HS and always unselect Code Protect.

Software Programming

  • I’m using SourceBoost with the BoostC (included in the download) compiler for my code.

Here’s the code I used to make a simple LED flashing circuit:

#include <system.h>

#pragma CLOCK_FREQ 20000000
void main()
{
//configure I/O ports
portb = 00000000b;
trisb = 00000000b; //0 = Output, 1 = Input

while(1)
{
portb=00000000b; //pull all port B pins low
delay_s(1); //wait 1 second
portb=11111111b; //pull all port B pins low
delay_s(1); //wait 1 second
}
}

Note that you have to set the clock frequency. This program makes any LEDs (don’t forget to put a resistor in series with the LED) connected to a portB pin turn off for one second and then on for one second and then repeats the sequence ad infinitum. The trisb line determines which bits of PortB will be used as outputs or inputs. A ’0′ will make that bit an output and a ’1′ will make it an input. The delay_s function is included in the system.h file provided by SourceBoost. Very handy!

All that time and energy just to get an LED to flash!

Working with PICs September 17, 2006

Posted by Jason in Electrical Engineering.
1 comment so far

I might be doing some PIC programming soon. In case you don’t know programmable integrated circuits (PICs) can be used to create customized hardware. They’re very versatile and can be used in applications such as analog-to-digital conversion or data-logging. You program them by writing software in your choice of programming language (assembly and C are common picks as long as you can find a compiler), compiling your software to a form the PIC can understand, and finally writing the program to the PIC.

I’m still looking for an IDE to use. I have MPLab but I don’t think it compiles C and I’m not very good at assembly language. Right now I’m downloading SourceBoost to give it a try. The free version has restricted features but I think it’ll be enough to do what I need. I’m not expecting anything too complex. If anyone has any suggestions for a free PIC compiler that can do C let me know in the comments.

Another thing you need to program PICs is the actual hardware programmer! I built one last year using some schematics I found off the web. It works…most of the time. I could use a more reliable programmer so, again, if anyone has a recommendation for one let me know in the comments. Here’s a picture of the one I built:

PIC Programmer

I’ll be helping with the construction of a haunted house (last year’s website) in Fremont. Electronics-wise I’m not sure yet what we’ll be working on. Maybe just simple things like flashing LEDs or maybe even some motor control. I heard something about a spider that needs movable jaws…

Last year we set it up in a hangar at the local airport. It was a lot of fun! I did some radio work a couple of nights and played one of the characters the last night. It was a huge success and I’m looking forward to working with them again on it.

Follow

Get every new post delivered to your Inbox.