Trying to make a led blink .

Thread Starter

krkarkarkmak678

Joined Mar 13, 2023
7
Hi I been trying to make a led blink in mplab xc8 but its not working I'm using the pic16f628a. Here is the code:

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) {

   TRISAbits.TRISA4 = 0 ;

    while(1){

            RA4 = 1;

            __delay_ms(500);

            RA4 = 0;

            __delay_ms(500);

    }       

    return;
 
Last edited by a moderator:

hexreader

Joined Apr 16, 2011
581
RA4 is an open-drain output (see datasheet 5.1 first sentance)

RA4 can only sink current it cannot supply current.

Connect your LED between positive supply via a current limiting resistor to RA4
LED will light when you output a low and will extinguish when you output a high on RA4

... better still, choose a different pin for your LED
 

Thread Starter

krkarkarkmak678

Joined Mar 13, 2023
7
RA4 is an open-drain output (see datasheet 5.1 first sentance)

RA4 can only sink current it cannot supply current.

Connect your LED between positive supply via a current limiting resistor to RA4
LED will light when you output a low and will extinguish when you output a high on RA4

... better still, choose a different pin for your LED
Ok thanks
 
Top