-1
\$\begingroup\$

schematic of circuit

I am trying to simply blink an led light using pic16f877a microcontroller. softwares i am using are, MPLABX IDE, MPLAB IPE and XC8 compiler. I use Pickit 3.5 programmer. My head-aching question is, i have no errors when downloading the .hex to microcontroller in the IPE programme (it says "Programming complete" and when verify --"Verify complete"), but the led not even light up. but when downloading the programme, i can see the led randomly blinks or keep lit for sometime, then when done programming, it goes off.

I've made sure,

-led working -connections are good -pic is new (although tried using it for three or four times)

I'm not sure -whether i'm using something called "signal diode" correctly as stated in here https://www.youtube.com/watch?v=HVQ4tj-D8jM. i am using IN4007 diode (to connect its cathode to the MCLR of pickit's output...

Code:

#define _XTAL_FREQ 20000000
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = ON        // Low-Voltage (Single-Supply) In-Circuit 
Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage 
programming enabled)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit 
(Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits 
(Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit 
(Code protection off)

void main(void)
{
    TRISB=0b00000000;
    PORTBbits.RB0=1;
    return;
}

UPDATED Code: (WORKING - only during 'connecting' period of pickit to MPLAB IPE software)

#define _XTAL_FREQ 20000000
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF         // Low-Voltage (Single-Supply) In-Circuit 
Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage 
programming enabled)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit 
(Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits 
(Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit 
(Code protection off)

void main(void)
{
    TRISB=0;

    while(1)
    {
        PORTBbits.RB0=1;
        __delay_ms(50);
        PORTBbits.RB0=0;
        __delay_ms(50);

    }
}

Components in my circuit breadboard,

-pic16f877a microcontroller + base

-led

-IN4007 diode (its cathode connect to MCLR of pickit's output)

-20MHz crystal oscillator (to CLKIN and CLKOUT of pic)

-2x22pF capacitors (for oscillator)

-330R resistor (for led from pin RB0)

-10k resistor (for IN4007 diode from MCLR of pickit's output)

-0.1uF capacitor (for IN4007 diode to connect to ground)

-jumper wires

-pickit3.5 connection

I tried using several microcontrollers like pic16f84a and pic18f452 also, following different tutorials on internet, but no luck. i really love doing this and i am not hoping to give it up.

Anybody please help, it will relieve a big headache! Thank you very much!**

\$\endgroup\$
  • \$\begingroup\$ Are you sure that the LED isn't active low? Try writing a zero. Also make sure you set the data direction register for port B (DDRB) to outputs. \$\endgroup\$ – Ron Beyer Nov 28 '17 at 13:09
  • \$\begingroup\$ I've changed the code such that RB0=1 and RB0=0, but when i measured voltage across the led, the slight voltage of about 0.05V remained constant. BTW, i am a beginner although i've done some electrical stuff back then. \$\endgroup\$ – stackUsr Nov 28 '17 at 13:18
  • \$\begingroup\$ @DiBosco, i've added a diagram. PS: i am not familiar with schematic designing and electronics at large. but i hope i have converted my circuit to an understandable schematic. \$\endgroup\$ – stackUsr Nov 28 '17 at 14:04
  • 1
    \$\begingroup\$ One thing that occurs to me (sorry this is nothing to do with the hardware) is that your software should have: while (1); instead of return; I'm not sure what your processor will do when it hits the return; statement and what state it will put the pins in. \$\endgroup\$ – DiBosco Nov 28 '17 at 14:11
  • \$\begingroup\$ I reckon D2 is completely unnecessary BTW. \$\endgroup\$ – DiBosco Nov 28 '17 at 14:13
4
\$\begingroup\$

I have found a solution:

  • I closed MPLAB IPE completely.
  • Then from project properties of MPLABX IDE, I selected the needed power and selected option to power the target from PICkit3.
  • Then "made" the program.
  • To run it, clicked on "Release from Reset".

IT WORKED!!! Now the LED blinks like COOL!!! Headache cured!

\$\endgroup\$
  • \$\begingroup\$ You can accept your own answer to indicate the correct solution to your question. Thank you for posting the solution. +1 \$\endgroup\$ – Transistor Nov 28 '17 at 18:20
  • \$\begingroup\$ When I get to the point where I can ask an intelligent question, I usually can find a solution. +1 \$\endgroup\$ – StainlessSteelRat Nov 28 '17 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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