Led stay in HIGH

Thread Starter

krkarkarkmak678

Joined Mar 13, 2023
7
Hi I'm tryng to make a led blink on the pic microcontroller 16f628a but when I conect the microcontroller to the power the led only stay in HIGH this is the code that i'm using.

C-like:
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)

#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)

#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)

#pragma config MCLRE = OFF    // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)

#pragma config BOREN = OFF      // Brown-out Detect Enable bit (BOD disabled)

#pragma config LVP = OFF        // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)

#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Data memory code protection off)

#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)


// #pragma config statements should precede project file includes.

// Use project enums instead of #define for ON and OFF.


#include <xc.h>

#define _XTAL_FREQ 4000000



void main(void) {

   TRISBbits.TRISB5 = 0;

    while(1){

            RB5 = 1;

            __delay_ms(500);

            RB5 = 0;

            __delay_ms(500);

    }       

    return;

}
 

LesJones

Joined Jan 8, 2017
4,190
Hi Scott, The PIC that the TS is using (PIC16F628A) does not have LATCH registers.
I can't comment of theTS's code as I use assembler rather than "C".

Les.
 
Last edited:

Ron314

Joined Mar 14, 2023
21
Oh. If this is your first foray into microcontrollers it's always best to minimize things that can go wrong. Adding a Crystal might be the thing that is stopping your project from working(it's happened to me b4). It could be that your supporting caps are wrong or your bread board is wreaking havoc or your crystal isn't cut correctly or ?. I tend to isolate hardware problems 1st by finding the easiest way to eliminate components and then add the components back in after I have a working project. Hope this helps.
 

Thread Starter

krkarkarkmak678

Joined Mar 13, 2023
7
Oh. If this is your first foray into microcontrollers it's always best to minimize things that can go wrong. Adding a Crystal might be the thing that is stopping your project from working(it's happened to me b4). It could be that your supporting caps are wrong or your bread board is wreaking havoc or your crystal isn't cut correctly or ?. I tend to isolate hardware problems 1st by finding the easiest way to eliminate components and then add the components back in after I have a working project. Hope this helps.
So I made a simulation on proteous and it does the same the led only stay in HIGH.Screenshot 2023-03-15 105646.png
 

LesJones

Joined Jan 8, 2017
4,190
Why two crystals ? The crystal is normalty connected between osc1 and osc2 and one 22pF capacitor between osc1 and ground and the other 22 pf capacitor between osc2 and ground. You should also have a decoupling capacitor (About 100 nF) between the supply pins to the PIC. It should be CLOSE to the PIC.
A picture of how you have constructed the circuit would help.

Les.
 

Thread Starter

krkarkarkmak678

Joined Mar 13, 2023
7
Why two crystals ? The crystal is normalty connected between osc1 and osc2 and one 22pF capacitor between osc1 and ground and the other 22 pf capacitor between osc2 and ground. You should also have a decoupling capacitor (About 100 nF) between the supply pins to the PIC. It should be CLOSE to the PIC.
A picture of how you have constructed the circuit would help.

Les.
I made a more simple program and change the external oscilator to an internal an works on proteus but not in the physical microcontroller.
 

Ron314

Joined Mar 14, 2023
21
Years ago I was fortunate enough to have Microchip come to my city to promote their microcontrollers, this included a quick start guide to building a 1st project. Without that I'd be in the same shoes as you my friend. Having your 1st project running is actually the hardest part of building with these devices, after that 1st one every other project will be much much much easier. There are a myriad of possible reasons why your 1st project doesn't run, but most of them can be eliminated if you were to follow along on a step by step tutorial that you could find on You Tube. Try searching something like "Hello World in C for PIC 16F microcontrollers" or something like that. Hello world is usually a term for your 1st project from a ZERO knowledge starting point to a running finished project sitting in front of you. Most likely you missed some small detail that will make sense once you spot it and after that you can start building the gadgets that you have dreamed up.


ron
 
Top