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.

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

  • Pets Challenge

    Pets Challenge
  • Fandom Contest

    Fandom Contest
  • Colors of the Rainbow Contest

    Colors of the Rainbow Contest

42 Discussions

0
None
mrGman123

2 months 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?

2 replies
1
None
beeseedubmrGman123

Reply 2 months 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
None
mrGman123beeseedub

Reply 2 months 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
None
eburman

Question 2 months 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?

2 answers
0
None
eburmanbeeseedub

Reply 2 months ago

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

1
None
HunnyDob

3 months 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.

4 replies
0
None
corigami79eburman

Reply 2 months ago

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

0
None
eburmancorigami79

Reply 2 months ago

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

0
None
corigami79eburman

Reply 2 months ago

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

0
None
Grindyloww

Question 3 months 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.

1 answer
0
None
eburmanGrindyloww

Answer 2 months 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
None
seaprimate

Question 3 months 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?

4 answers
0
None
5urg3seaprimate

Answer 3 months 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
None
eburman5urg3

Reply 2 months ago

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

0
None
seaprimateeburman

Reply 2 months 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

0
None
eburmanseaprimate

Reply 2 months ago

It's probably not the PIC chip. If the circuit is behaving erratically then make sure you have capacitors placed across VCC and VDD (+ and -) of the power supply. Transients in the supply rail often cause trouble. The capacitors help to smooth them out. Also, the cheep Chinesium breadboard may be at fault. If the capacitors don't help then try rewiring the circuit using different holes.

0
None
jer502

3 months ago

On step 6 - second bullet point [Change both the FOSC IDE setting and the #define in the code.] I'm lost on that one.

1
None
5urg3

Tip 3 months ago

My system worked fine just as shown in the instructions, except that the "HackLife" Line was not generated on the LCD screen.

Voltage set to 4.875 ( as it should be.... a little lower than max to program)

Tip: Once you hit "generate source code", Paste the OUTPUT WINDOW at the bottom of the IDE into the source code (that wasn't all that clear in the instructions) then paste the _XTAL_FREQ 4000000 and the Blink code. Make sure you have #include too.

Tip: Put the PIC into the ZIF starting on the SECOND ROW from the RIGHT so that there is one row between the end of the socket and pins 9 and 10 on the PIC. Pin One (the smallest dot on the top of the IC) should be pointed toward the lock-down handle on the ZIF.

Tip: VSS = GND
VDD = +5V (sometimes called Vcc)

Tip: Build a 'tight' circuit (aka shortest wires possible even if you have to use more short jumpers to connect each pin to Vdd/Vss). Long wires make things tough to debug.

Tip: Have the PICKit3 plugged into a true USB on your computer (not a dock or bus) and THEN open the IDE.

Tip: Start a brand new project with for the LCD circuit. Start from the beginning of the instructions and follow the steps EXACTLY. Right Click the Source Files Folder and click "Add Existing Item" and then find the download of the picLCD.c source file and click ADD. Then set the Config bits again (use HS for the 16.000 Mhz Oscillator) and upload to the PIC.

Tip: If you only See the green back light on the LCD or just Dark Blocks (After ensuring you've programmed the IC correctly) turn the blue trimm potentiometer with a small screwdriver or thin piece of plastic and the screen should show text. I believe it is CounterClockWise for dark blocks and ClockWise if you only see the backlight.

5urg3_Pic_Of_Destiny.jpg