0
\$\begingroup\$

It has been quite a while since I haven't done PIC programming.

While trying to run a simple example I have ran into a problem.

#include <pic.h>

int main()
{
    TRISB = 0; // PORTB is output

    PORTB = 0xFF; // All leds are on

    while (1) {} // Loop forever

}

I use PICKit2 command line interface to load to program into the microcontroller.

pk2cmd -PPIC16F877A -Fhelloworld.hex -M PICkit 2 Program Report 1-10-2020, 21:19:44 Device Type: PIC16F877A

Program Succeeded.

You can see the schematics of the circuit here.

pic16f887a

I meausured the voltage at the output of RB5 with a multimeter. It was about 300 mV.

Are there any ideas on how to fix this problem. Thanks.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Have you set the clock configuration i.e. HS oscillator? \$\endgroup\$ Commented Oct 1, 2020 at 19:46
  • \$\begingroup\$ In this example I didn't. But before that I've tried clock settings that way. Also the crystal has a K16.000 label on it. \$\endgroup\$
    – user211748
    Commented Oct 1, 2020 at 19:53
  • \$\begingroup\$ I do not expect the LED to blink. But in my previous attempt I was measuring about 300 milivolts from the output of RB5. \$\endgroup\$
    – user211748
    Commented Oct 1, 2020 at 20:25
  • 1
    \$\begingroup\$ never assume that PORTB = 0xFF; will output Vcc ... always try PORTB = 0; also ... if both generate the same output, then start assuming that there is a problem \$\endgroup\$
    – jsotola
    Commented Oct 1, 2020 at 20:37
  • 1
    \$\begingroup\$ Well, SE/EE is not a forum, and it works this way: If you have an answer (or solution) to your question, please post it as such. Then mark it, you might need to let pass some time for this. Please do not edit your question with a solution, because others looking for help will just scan over the list of questions and commonly "filter" the ones with (marked) answers. \$\endgroup\$ Commented Oct 2, 2020 at 8:26

1 Answer 1

0
\$\begingroup\$

I was able to solve the problem.

It appears that some of my LED's were damaged.

The external clock frequency is set to high speed (HS).

The updated code can be found here.

#include <pic.h>

#ifndef _XTAL_FREQ
// The clock frequency is 16 Mhz
#define _XTAL_FREQ 16000000
#endif

__CONFIG (FOSC_HS & WDTE_OFF & LVP_OFF & CPD_OFF & CP_OFF);

int main()
{
    TRISB = 0; // PORTB is output

    while(1)
    {
        /* RB5 PORTB6 is on */
        PORTB = 0x20;  // b0010 0000

        /* wait for a second */
        __delay_ms(1000);

        /* all leds on PORTB is off */
        PORTB = 0;

        /* wait for a second */
        __delay_ms(1000);
    }
}
\$\endgroup\$

Your Answer

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