HackerBox 0040: PIC of Destiny

Introduction: HackerBox 0040: PIC of Destiny

Greetings to HackerBox Hackers around the world. HackerBox 0040 has us experimenting with PIC Microcontrollers, breadboarding, LCD displays, GPS, and more. This Instructable contains information for getting started with HackerBox 0040, which can be purchased here while supplies last. If you would like to receive a HackerBox like this right in your mailbox each month, please subscribe at HackerBoxes.com and join the revolution!

Topics and Learning Objectives for HackerBox 0040:

  • Develop embedded systems with PIC Microcontrollers
  • Explore in-circuit programming of embedded systems
  • Test power supply and clocking options for embedded systems
  • Interface a PIC Microcontroller to an LCD output module
  • Experiment with an integrated GPS receiver
  • Wield the PIC of Destiny

HackerBoxes is the monthly subscription box service for DIY electronics and computer technology. We are hobbyists, makers, and experimenters. We are the dreamers of dreams.

HACK THE PLANET!

Step 1: Content List for HackerBox 0040

  • PIC Microcontroller PIC16F628 (DIP 18)
  • PIC Microcontroller PIC12F675 (DIP 8)
  • PICkit 3 In-Circuit Programmer and Debugger
  • ZIF Socket Programming Target for PICkit 3
  • USB Cable and Header Wires for PICkit 3
  • GPS Module with Onboard Antenna
  • 16x2 Alphanumeric LCD Module
  • Breadboard Power Supply with MicroUSB
  • 16.00MHz Crystals (HC-49)
  • Tactile Momentary Buttons
  • Diffused RED 5mm LEDs
  • 5K Ohm Trimmer Potentiometer
  • 18pF Ceramic Capacitors
  • 100nF Ceramic Capacitors
  • 1K Ohm 1/4W Resistors
  • 10K Ohm 1/4W Resistors
  • 830 Point (Large) Solderless Breadboard
  • Formed Jumper Wire Kit with 140 Pieces
  • Celluloid Guitar Picks
  • Exclusive PIC16C505 Die Decal

Some other things that will be helpful:

  • Soldering iron, solder, and basic soldering tools
  • Computer for running software tools

Most importantly, you will need a sense of adventure, hacker spirit, patience, and curiosity. Building and experimenting with electronics, while very rewarding, can be tricky, challenging, and even frustrating at times. The goal is progress, not perfection. When you persist and enjoy the adventure, a great deal of satisfaction can be derived from this hobby. Take each step slowly, mind the details, and don't be afraid to ask for help.

There is a wealth of information for current and prospective members in the HackerBoxes FAQ. Almost all of the non-technical support emails that we receive are already answered there, so we really appreciate your taking a few minutes to read the FAQ.

Step 2: PIC Microcontrollers

The PIC family of microcontrollers is made by Microchip Technology. The name PIC initially referred to Peripheral Interface Controller, but was later corrected to Programmable Intelligent Computer. The first parts in the family came out in 1976. By 2013, more than twelve billion individual PIC microcontrollers had been shipped. PIC devices are popular with both industrial developers and hobbyists due to their low cost, wide availability, large user base, extensive collection of application notes, availability of low cost or free development tools, serial programming, and re-programmable Flash-memory capability. (Wikipedia)

HackerBox 0040 includes two PIC Microcontrollers temporarily seated for transport in a ZIF (zero insertion force) socket. The first step it to remove the two PICs from the ZIF socket. Please do that now!

The two microcontrollers are a PIC16F628A (datasheet) in a DIP18 package and a PIC12F675 (datasheet) in a DIP 8 package.

The examples here use the PIC16F628A, however the PIC12F675 works similarly. We encourage you to try it out in a project of your own. Its tiny size makes for an efficient solution when you only need a small number of I/O pins.

Step 3: Programming PIC Microcontrollers With PICkit 3

There are a lot of configuration steps that need to be addressed when using the PIC tools, so here is a pretty basic example:
  • Install the MPLAB X IDE software from Microchip
  • At the end of the install, you will be presented with a link to install the MPLAB XC8 C Compiler. Be sure to select that. XC8 is the compiler we will be using.
  • Insert the PIC16F628A (DIP18) chip into the ZIF socket. Note the position and orientation listed on the reverse of the ZIF target PCB.
  • Set the jumper switches as indicated on the reverse of the ZIF target PCB (B, 2-3, 2-3).
  • Plug the five-pin programming header of the ZIF target board into the PICkit 3 header.
  • Connect the PICkit 3 to the computer using the red miniUSB cable.
  • Run the MPLAB X IDE.
  • Select the menu option to create a new project.
  • Configure: microchip embedded standalone project, and hit NEXT.
  • Select device: PIC16F628A, and hit NEXT
  • Select debugger: None; Hardware tools: PICkit 3; Compiler: XC8
  • Enter the project name: blink.
  • Right click source files, and under new select new main.c
  • Give the c file a name like "blink"
  • Navigate to window > tag memory view > config bits
  • Set the FOSC bit to INTOSCIO and everything else to OFF.
  • Hit the “generate source code” button.
  • Paste the generated code into your blink.c file above
  • Also paste this into the c file: #define _XTAL_FREQ 4000000
  • Past in the main block of c code below:
void main(void)
{
   TRISA = 0b00000000;
    while (1)
    {   
        PORTAbits.RA3 = 1;
        __delay_ms(300);
        PORTAbits.RA3 = 0;
        __delay_ms(300);
    } 
}

  • Hit the hammer icon to compile
  • Navigate to production > set project configuration > customize
  • Select PICkit 3 in left panel of the popup window and then Power from the dropdown field at the top.
  • Click the “power target” box, set the target voltage to 4.875V, hit Apply.
  • Back at the main screen, hit the green arrow icon.
  • A warning about about voltage will pop up. Hit continue.
  • You should eventually get “Programming/Verify Complete” in the status window.
  • If the programmer is not behaving, it can help to shut down the IDE and just run it again. All of your selected settings should be maintained.

Step 4: Breadboarding the PIC Programmed With Blink.c

Once the PIC is programmed (previous step), it can be dropped onto a solderless breadboard for testing.

Since the internal oscillator was selected, we only need to wire up three pins (power, ground, LED).

Power can be supplied to the breadboard using the power supply module. Pointers for using the power supply module:

  • Put some more solder on the side tabs of the microUSB socket before it breaks off - not after.
  • Make sure the "black pins" go into the ground rail, and the "white pins" into the power rail. If they are reversed, you are on the wrong end of the breadboard.
  • Flip both switches to 5V for the included PIC chips.

After positioning the PIC microcontroller, note the pin 1 indicator. The pins are numbered from pin 1 in a counter-clockwise fashion. Wire pin 5 (VSS) to GND, pin 14 (VDD) to 5V, and pin 2 (RA3) to the LED. Notice in your code, I/O pin RA3 is being cycled on and off to blink the LED. The longer pin of the LED should connect to the PIC, while the shorter pin should connect to a 1K resistor (brown, black, red). The opposite end of the resistor should connect to the GND rail. The resistor simply acts as a current limit so that the LED doesn't look like a short between 5V and GND and draw too much current.

Step 5: Programming In-Circuit

The PICkit 3 dongle can be used to program the PIC chip in-circuit. The dongle can also supply power the circuit (the breadboard target) just as we did with the ZIF target.

  • Remove the power supply from the breadboard.
  • Connect the PICkit 3 leads to breadboard at 5V, GND, MCLR, PGC, and PGD.
  • Change the delay numbers in the C code.
  • Recompile (hammer icon) and then Program the PIC.

Since the delay numbers were changed, the LED should blink differently now.

Step 6: Using an External Crystal Oscillator

For this PIC experiment, switch from the internal oscillator to a high-speed external crystal oscillator. Not only is the external crystal oscillator faster 16MHz instead of 4MHz), but it is much more accurate.

  • Change the FOSC configuration bit from INTOSCIO to HS.
  • Change both the FOSC IDE setting and the #define in the code.
  • Change #define _XTAL_FREQ 4000000 from 4000000 to 16000000.
  • Reprogram the PIC (maybe change the delay numbers again)
  • Verify operation with the external crystal.
  • What happens when you pull the crystal from the breadboard?

Step 7: Driving an LCD Output Module

The PIC16F628A can be used to drive output to a 16x2 Alphanumeric LCD Module (data) when wired up as shown here. The attached file picLCD.c gives a simple example program for writing text output to the LCD module.

Attachments

Step 8: GPS Time and Location Receiver

This GPS module can determine time and location quite accurately from signals received from space into its small integrated antenna. Only three pins are required for basic operation.

The red "Power" LED will light up when proper power is connected. Once the satellite signals are acquired, the green "PPS" LED with start to pulse.

Power is supplied to the GND and VCC pins. The VCC can operate on 3.3V or 5V.

The third pin that is necessary is the TX pin. The TX pin outputs a serial stream that can be captured into a computer (via TTL-USB adapter) or into a microcontroller. There are numerous example projects for receiving GPS data into an Arduino.

This git repo includes pdf documentation for this type of GPS module. Also check out u-center.

This project and video demonstrates an example of capturing high accuracy date and time from a GPS module into a PIC16F628A microcontroller.

Step 9: Live the HackLife

We hope you have enjoyed this month's voyage into DIY electronics. Reach out and share your success in the comments below or on the HackerBoxes Facebook Group. Certainly let us know if you have any questions or need some help with anything.

Join the revolution. Live the HackLife. You can get a cool box of hackable electronics and computer tech projects delivered right to your mailbox each month. Just surf over to HackerBoxes.com and subscribe to the monthly HackerBox service.

2 People Made This Project!

Recommendations

  • Pocket-Sized Speed Challenge

    Pocket-Sized Speed Challenge
  • Super-Size Speed Challenge

    Super-Size Speed Challenge
  • Audio Challenge 2020

    Audio Challenge 2020

45 Discussions

0
patsnyder07
patsnyder07

21 days ago

I keep getting an error "Tool not Found" when I try to program using MPLAB and the PickKit3. In my configuration settings the Pickit3 keeps disappearing from the left side menu as well, even after I reselect it from the Hardware Tools list; for some reason hitting apply is then removing it. I am seeing an error, "info: The project uses platform tool noID but that tool is not installed. From the main menu, select Tools then select Plugins. Install the missing plugin." in the debugging console. The problem is that I do have the plugin installed.

Capture3.PNGCapture2.PNGCapture.PNGCapture4.PNG
0
patsnyder07
patsnyder07

Reply 21 days ago

Nevermind, I solved it. For anyone else experiencing a similar problem: I thought the pickit3 had a standard mini-b usb plug however there is apparently something special about that red cable that was included. The standard cable I already had connected to my computer would power the pickit3 up and everything but would not let MPLAB recognize it. So as soon as I changed the cable out it worked...weird. Why use a non-standard cable?

0
goodwyn41.mg
goodwyn41.mg

Question 11 months ago on Step 7

My LED is turning on after I have turned the blue knob, but the words are not displaying. Does anyone have the correct and working code for this part??

0
mrGman123
mrGman123

1 year ago

Im having the same issue as eburman with the GPS project. Using the PIC16F682A. Has anyone been able to display the date and time yet?

1
beeseedub
beeseedub

Reply 1 year ago

Yep...I was able to.

Are you not getting past the startup display for the LCD screen?

The datasheet provided is not totally correct for this GPS chip.

IMG_20190407_074745.jpg
1
mrGman123
mrGman123

Reply 1 year ago

I changed the (unsigned char gps_header[]="GNRMC,";) now it gets past the startup screen and displays the time and date. Thank you.

1
eburman
eburman

Question 1 year ago

So, I've gotten past almost all the hurdles but the final goal still eludes me. Has anyone gotten the GPS clockcircuit to work properly? I've been successful using the PIKkit3 to program my chips after figuring out how to correctly set the power target voltage. I've gotten the LCD to display both lines after learning from HunnyDob that D3 has to be pulled up to 5V rather than being grounded. Why is that? Why do all the instructions show that this pin is grounded when it just doesn't work that way? This makes me wonder if there isn't something else going on related to the hardware that came with the kit. Now I'm stuck on the GPS project. I learned that X8C global option hasto be set to C Standard C90 (whatever that means) before it will compile so that's all good now. I've successfully loaded the code into the chip and it displays both lines of the opening LCD screen. But that's it. It never progresses further. The GPS module is powered and the green light flashes telling me that GPS data is being received. The TX serial output line from the GPS module is connected properly to the RX serial input port on the PIC. I also see an appropriate signal coming out of the GPS module using my logic analyzer so I know that the GPS module is working properly. But the PIC isn't parsing data and sending it to the LCD. No further information comes up on the LCD. It's just stuck on the first intro screen. What gives? Any ideas?

0
eburman
eburman

Reply 1 year ago

Thank you! That works. I'm now getting UTC time and date! Wooohoo!

1
HunnyDob
HunnyDob

1 year ago

In order to display "Hacklife" you need to remove the ground from pin 10 of JP4 (D3) and instead tie it to +5v. Grounding puts the display in single line mode.

1
eburman
eburman

Reply 1 year ago

Thanks! That works!

0
corigami79
corigami79

Reply 1 year ago

Yeah, thanks between that and removing the resistor from memclr, works like a champ.

0
eburman
eburman

Reply 1 year ago

The pull up resistor make no difference for me. I suspect it's not an issue.

0
corigami79
corigami79

Reply 1 year ago

Yeah, after posting i realized I had a 1k, instead of the 10k... Operator error.

0
Grindyloww
Grindyloww

Question 1 year ago

my 18 pin microchip or pick it 3 does not seem to work. when I first plug all components in, all the lights turn on but the status light quickly turns off. I cannot download any of the code to the chip. If anyone has suggestions please help.

0
eburman
eburman

Answer 1 year ago

The status light routinely turns off for me as well. That seems to be normal. My PICkit3 is working fine. Something else must be wrong.

0
seaprimate
seaprimate

Question 1 year ago

One problem I'm having is persistance on the screen. After loading the chip, if I shut the power off then turn it back on, the screen only has black blocks on the top. But after doing that, if I quickly cycle the power to just the PIC on and off real fast, the "HackerBoxes/HackLife" will show up. Also, after it boots up and is blank, just by touching pin 4 with something metallic causes it to start working correctly. I imagine it needs a delay added somewhere to cause it to run appropriately. Any ideas?

0
5urg3
5urg3

Answer 1 year ago

Same Problem, then i turned the Pot a little CCW until it showed

I don't see the "HackLife" Line on my screen though :\

0
eburman
eburman

Reply 1 year ago

See answer from HunnyDob. That solved the problem of not getting both lines to show up.

0
seaprimate
seaprimate

Reply 1 year ago

I think my pic is defective, it's garbled until I tap the side of pin 4 on the pic with something metallic, or I cycle the power several times super fast, then it'll show as planned. it's weird