0
\$\begingroup\$

I want to blink LED with PIC16F628A and run it directly with the button make and program device main project of MPLAB X. to programing the PIC I did simple wiring shown in this tutorial without using any resistor (just wiring).

To blinking the LED I just wired RA0 ---> resistor ---> LED ---> ground but nothing works.

Should I remove some wires after programming the PIC or add something?

code :

#include<htc.h>
#include <pic.h>
#include <pic16f628a.h>
// Config word
__CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_ON & CP_OFF);
#define LED  RA0
#define _XTAL_FREQ   4000000
void main()
{   
        TRISA0 = 0;                // Make RA0 pin output
        LED    = 0;
        CMCON = 0x07;
        // Make RA0 low
    while(1)
    {
        __delay_ms(1000);       // Half sec delay
        LED = 0;               // LED off
        __delay_ms(1000);       // Half sec delay
        LED = 1;               // LED on
    }
}

MPLAB X output

BUILD SUCCESSFUL (total time: 5s)
Loading code from C:/Users/makhlouf/MPLABXProjects/blink.X/dist/default/production/blink.X.production.hex...
Loading completed
Connecting to programmer...
Programming target...
Programming completed
Running target...

enter image description here

enter image description here

enter image description here

\$\endgroup\$
13
  • \$\begingroup\$ Did the programmer report that programming was successful? \$\endgroup\$
    – kjgregory
    Commented Jul 22, 2014 at 15:29
  • \$\begingroup\$ Also, what do you mean "raspberry ground"? \$\endgroup\$
    – kjgregory
    Commented Jul 22, 2014 at 15:33
  • 1
    \$\begingroup\$ We are all very confused here. Please post your entire schematic to help us \$\endgroup\$
    – Majenko
    Commented Jul 22, 2014 at 15:40
  • 2
    \$\begingroup\$ What does the Raspberry have to do with this? The LED must be connected to the PIC ground. \$\endgroup\$ Commented Jul 22, 2014 at 15:52
  • 1
    \$\begingroup\$ Your schematic needs to show the power pins. We need to know that the PIC ground and the Raspberry ground are connected together. Alternatively, you could just ground your LED to the Vss pin (pin 5) of your PIC. \$\endgroup\$
    – kjgregory
    Commented Jul 22, 2014 at 16:01

3 Answers 3

1
\$\begingroup\$

Check your wiring, it looks like you've plugged in the PICkit connector backwards on the breadboard.

Please read the documentation more carefully in the future.

\$\endgroup\$
17
  • \$\begingroup\$ can the pic be damaged and detecte by MPLAB??? because I did exactely as you said but still not wokrking \$\endgroup\$ Commented Jul 22, 2014 at 16:00
  • \$\begingroup\$ In my experience, when I have damaged a PIC, the programmer reports that it was not successful. \$\endgroup\$
    – kjgregory
    Commented Jul 22, 2014 at 16:03
  • \$\begingroup\$ It seems to me that you should eliminate the Raspberry Pi from the equation altogether. The PICkit can power the PIC and I see no other reason to connect the Raspberry Pi. \$\endgroup\$
    – kjgregory
    Commented Jul 22, 2014 at 16:04
  • 1
    \$\begingroup\$ OK, that sounds correct then (Vss should already be wired to PICkit-pin3). I would verify that your LED works, is oriented in the correct direction and that all your wiring is correct at this point. \$\endgroup\$
    – kjgregory
    Commented Jul 22, 2014 at 16:17
  • 1
    \$\begingroup\$ Could be... I don't have time to check your config word. \$\endgroup\$
    – kjgregory
    Commented Jul 22, 2014 at 19:01
1
\$\begingroup\$

A decoupling capacitor between Vcc and Gnd is missing.

Every time, but even more when working with a breadboard, decoupling caps are necessary.

"What is a decoupling cap"

This may be the cause of strange behaviors of your PIC.

\$\endgroup\$
4
  • \$\begingroup\$ I should use decoupling capacitor even with internal osciallator??? \$\endgroup\$ Commented Jul 23, 2014 at 10:42
  • 1
    \$\begingroup\$ Yes. If you have a look at the provided link you will see that a digital chip would draw current from their Vcc pins mainly "by burst". It's the switching of the internal logic that create theses current pulses. This happens, regardless of the used oscillator. If you don't have decoupling capacitors, then the "quality" of your Vcc would depend on the length of your Vcc cables, quality of the breadboard contacts, kind of power supply you use, etc. Use decoupling caps and if 5V is provided, the power won't be an issue anymore. (as a fist order approximate). \$\endgroup\$
    – Blup1980
    Commented Jul 23, 2014 at 10:47
  • \$\begingroup\$ i put 0.1uF capacitor between vdd and vss ebay.com/itm/… and still not working, when I hold the led with hand it works, so it's the breadboard connection??? and is 0.1uF enough???? \$\endgroup\$ Commented Aug 19, 2014 at 14:33
  • \$\begingroup\$ 0.1uF should be Ok. \$\endgroup\$
    – Blup1980
    Commented Aug 19, 2014 at 18:22
1
\$\begingroup\$

Your code sets the PIC to use MCLR reset but you have nothing pulling you MCLR up to vdd. AFAIK the PICkit2 wont pull it up to vdd but will simply release it. You can add an external resistor pulling your MCLR to Vdd or you can try your code with:

--- __CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_ON & CP_OFF);
+++ __CONFIG( FOSC_INTOSCIO & WDTE_OFF & PWRTE_ON & CP_OFF & MCLRE_OFF );

I have to point out, even though it may seem basic to some, that LEDs cannot work in reverse, if you are not 100% certain that you have the polarity correct, try reversing the LED (very few LEDs have maximum reverse voltages lower then 5V so this should not be able to damage the LED or the PIC).

Also, dont forget to power your circuit. You have to explicitly tell the PICkit (especially the PICkit3) to power the host circuit otherwise it will assume the circuit has it`s own power supply and it will not feed power to your circuit.

In the PICKit2 interface (your image):

  1. check the "VDD PICKit2" - "ON" box to instruct the pickit to supply power to your circuit.

In the MPLABX interface:

  1. right click on your project
  2. click properties
  3. in the tree on the left of the properties window (titled categories), click PICkit 2
  4. Uncheck the "Use target power always" box
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.