0

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

bouqbouq
  • 583
  • 8
  • 27

3 Answers3

1

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.

kjgregory
  • 1,030
  • 2
  • 8
  • 18
  • can the pic be damaged and detecte by MPLAB??? because I did exactely as you said but still not wokrking – bouqbouq Jul 22 '14 at 16:00
  • In my experience, when I have damaged a PIC, the programmer reports that it was not successful. – kjgregory Jul 22 '14 at 16:03
  • 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. – kjgregory Jul 22 '14 at 16:04
  • And i just have to wire the led ground to vss ???(already wired to pin 3 of pickit) – bouqbouq Jul 22 '14 at 16:09
  • 1
    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. – kjgregory Jul 22 '14 at 16:17
  • i did exactly like that (see picture above ). I just added led to RA0 and vcc (pin 5) but nothing works, simulation with Proteus works fine, the PIC is detected and successfully programmed either with MPLAB or Pickit2 software. the led direction is correct (light with vdd ground Raspberry) – bouqbouq Jul 22 '14 at 16:42
  • It looks like you may have the PICkit connector inserted backwards on the breadboard. – kjgregory Jul 22 '14 at 17:21
  • no it's not inserted backward, it's detected by the pickit, (see last picture) :) . – bouqbouq Jul 22 '14 at 17:25
  • Well, looking at the wire colors in reference to the tutorial you linked, orange is Vpp, you have it wired to nothing. Grey is aux (not used), you have it wired to Vpp. If it's working, then you must have connected the jumper backwards on the PICkit as well. – kjgregory Jul 22 '14 at 17:34
  • I dont think those colors have sense since it the tutorial there is colors white and red that doest exist in the real pickit wire and since it's detected then it's well wired, and when I reversed pickit wires nothing detected. (it's just difference of color, I made the right order) – bouqbouq Jul 22 '14 at 17:39
  • I don't see the resistor in the picture, is it hiding behind the LED? Have you verified that the LED lights up when you connect the resistor directly to Vdd? – kjgregory Jul 22 '14 at 17:42
  • I didnt put resistor betwenn RA0 and led, I didnt put any resistor here, for what purpose??? – bouqbouq Jul 22 '14 at 17:51
  • no I added resistor between RA0 AND LED still not working, workds when set VSS rasberry -> resistor -> led -> ground (it lights this way) – bouqbouq Jul 22 '14 at 17:54
  • Is it syntax issue in code since I'm using internal oscillator . it can be configuration problem ???? – bouqbouq Jul 22 '14 at 18:58
  • 1
    Could be... I don't have time to check your config word. – kjgregory Jul 22 '14 at 19:01
  • OK sorry hhh. I will check it by myself hhhh – bouqbouq Jul 22 '14 at 19:07
  • i put 0.1uF capacitor between vdd and vss http://www.ebay.com/itm/261264381649?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT and still not working, when I hold the led with hand it works, so it's the breadboard connection??? and is 0.1uF enough???? – bouqbouq Aug 19 '14 at 14:34
1

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.

Blup1980
  • 6,120
  • 3
  • 26
  • 47
  • I should use decoupling capacitor even with internal osciallator??? – bouqbouq Jul 23 '14 at 10:42
  • 1
    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). – Blup1980 Jul 23 '14 at 10:47
  • i put 0.1uF capacitor between vdd and vss http://www.ebay.com/itm/261264381649?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT and still not working, when I hold the led with hand it works, so it's the breadboard connection??? and is 0.1uF enough???? – bouqbouq Aug 19 '14 at 14:33
  • 0.1uF should be Ok. – Blup1980 Aug 19 '14 at 18:22
1

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
Mathieu L.
  • 584
  • 2
  • 5