0
\$\begingroup\$

Environment

Symptoms

After inserting the PIC into the adapter board and writing the blink program, I place the LED on the electrodes of the adapter board, but it does not blink. The LED is turned on when connected to VDD and VSS. So the LED is working fine. Some pins of RB on the PIC are connected to VDD or VSS inside the adaptor, but I am using RB1, which is not connected, to test the LED. I have confirmed that "Programming/Verify complete" is displayed after programming.

Program

// PIC16F84 Configuration Bit Settings

// 'C' source line config statements

// 16F88
// CONFIG1
#pragma config WDTE = OFF
#pragma config PWRTE = ON
#pragma config CP = OFF

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

#include <stdio.h>
#include <stdlib.h>

// If using the __delay_ms() function, it must be written as follows, and it must be specified that the clock is 8MHz. This should be written at the beginning of the program, before the main function.
#define _XTAL_FREQ 8000000

void main(void)
{
PORTA = 0x00; // Initialize PORTA
PORTB = 0x00; // Initialize PORTB
TRISA = 0x00; // Set input/output for PORTA
TRISB = 0x00; // Set input/output for PORTB

while(1){ // Infinite loop
PORTB ^= 0b00000010; // Toggle RB1
__delay_ms(500); // Wait for 500 milliseconds
}
}

I google "PIC16F84A-201/P led blink" but it didn't help me much.

What could be the issue? I would appreciate any guidance from those with detailed knowledge.

\$\endgroup\$
6
  • \$\begingroup\$ And what clock circuit the PIC has? \$\endgroup\$
    – Justme
    Commented Jul 12 at 14:26
  • \$\begingroup\$ @Justme It's 20MHz. \$\endgroup\$
    – dixhom
    Commented Jul 12 at 16:46
  • \$\begingroup\$ OK. But your project is set to have 8 MHz. And you selected this clock into use how when you programmed the PIC? I mean, you set all kinds of CONFIG fuse bits in software but not the clock type. Did you program the CONFIG bits? Also, don't program them until you are 100% sure you don't end up locked out if you select wrong clock settings or other settings. If you never programmed them, make sure the watchdog is OFF. \$\endgroup\$
    – Justme
    Commented Jul 12 at 16:50
  • \$\begingroup\$ Actually, I'm not sure about 20MHz. This document (ww1.microchip.com/downloads/en/DeviceDoc/35007b.pdf) says " Operating speed: DC - 20 MHz clock input" on the page 1. I replaced 8000000 by 20000000 by it didn't work. I'm not sure what the CONFIG bits mean. Other than what I set on GUI like the supply voltage, what's on the code is all that's configured. \$\endgroup\$
    – dixhom
    Commented Jul 12 at 23:37
  • \$\begingroup\$ Yes, the PIC can work with many different frequencies and types of clock. Please verify your board where the PIC is supposed to run provides a clock to the PIC clock pin(s). \$\endgroup\$
    – Justme
    Commented Jul 13 at 0:55

1 Answer 1

1
\$\begingroup\$

The PIC seems to have no clock source at all, if your PCB does not provide one already or assumes the user to solder in a clock circuit for the PIC.

The board mentions a ceramic resonator and has a empty place where you can solder a 3-pin ceramic resonator with built-in loading capacitors.

It may work with a quartz crystal but then you need to bodge two separate load capacitors with the crystal.

The PIC must be told what kind of quartz or ceramic resonator you put there to oscillate correctly. This is done by setting the CONFIG bits correctly, maybe in the code, and actually programming the CONFIG bits to the PIC - this is usually not done by default because you don't want to accidentally program them.

Also you need to tell in your code what frequency clock source you put there, in order for the delay functions to wait the correct amount of clock cycles.

It may be simpler to just wire a 3-pin crystal oscillator clock module which takes in supply and ground and provides a square wave clock to one of the PIC pins that can take in external square wave clock.

The PIC can also work with an RC oscillator, and it may be used in a pinch, but it requires very low value ceramic capacitor to work at high speeds and is subject to large frequency tolerance so I can't recommend it.

\$\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.