LEDs Test

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
Hi
I have total eight LED's and I want to turn on each LED one by one for 1 seconds only. I have connected all LED's at port D

Here is connection information, black is ground and all wires are coming from PIC ports

1602769250813.png


I wrote code that suppose to turn on each LED one by one for 1 seconds only

IDE MPLABX- 5.40
Version -XC8 2.30
Language- C
Hardware - PIC18F45K80

C:
/*
* File:   LEDs.c
* Author: Embedded System
* Created on October 15, 2020, 3:41 AM
*/

#define _XTAL_FREQ 8000000
#include <xc.h>
// PIC18F45K80 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF       // Extended Instruction Set (Enabled)
// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)
// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = SBORDIS  // Brown Out Detect (Enabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)
// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)
// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)
// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)
// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)
// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)
// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)
// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)
// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)
// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

//LED STATUS
#define LEDs_PORT             LATD
//#define LEDs_ON               0xff
//#define LEDs_OFF              0x00

#define TRUE                  1
#define LOW                   0


#include <xc.h>

void PORTs_Initialize(void)
{
    LATA = LATB = LATC = LATD = LATE =  LOW;
  
    TRISA = 0x00; // all are output Pins, Unused
    TRISB = 0x00; // all are output pins , Unused
    TRISC = 0x00; // all are output, Unused
    TRISD = 0x00; // All LEDs are connected to PortD. Output
    TRISE = 0x00; // All are output, Unused

    ANCON0 = 0; // digital port
    ANCON1 = 0; // digital port
    CM1CON = 0; // Comparator off
    CM2CON = 0; // Comparator off
    ADCON0 = 0; // A/D conversion Disabled
}

void main(void)  //Program start from here
{
  
   unsigned int count = 0;
  
     PORTs_Initialize(); // Initialize the PORT
  
     while(TRUE) // run forever
     {
         for (count = 0; count <8; count++)
         {
            LEDs_PORT = LEDs_PORT | 0x80 ;
            LEDs_PORT = LEDs_PORT << 1;
            __delay_ms(1000);     
        }
    }

}
The problem is any LED is not turning on/off ?

Debugging code : I don't get any value at line 100

1602768857270.png
 
Last edited:

bertus

Joined Apr 5, 2008
22,266
Hello,

What type of leds do you use?
What is the resistor value?
What is the supply voltage?

In the datasheet is given that the output current for the pins on port D is 8 mA.

Bertus
 

AlbertHall

Joined Jun 4, 2014
12,338
First off make sure hardware is working:
Before the while(TRUE) line 96 add:

LEDs_PORT = 0xFF;
__delay_ms(1000);

This should light all LEDs for one second.
If that works then as per post #3, change the '<<' to shift '>>'
I don't think that will give you want but at least it should show something happening.
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
This is a sequence I want for all LEDs

Code:
LEDs:  D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0
State:  1 |  0 |  0 |  0 |  0 |  0 |  0 |  0   
Wait 1 seconds 
State:  0 |  1 |  0 |  0 |  0 |  0 |  0 |  0   
Wait 1 seconds
State:  0 |  0 |  1 |  0 |  0 |  0 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  1 |  0 |  0 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  1 |  0 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  0 |  1 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  0 |  0 |  1 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0
Here is my workin program
C:
/*
* File:   LEDs.c
* Author: Embedded System
* Created on October 15, 2020, 3:41 AM
*/

#define _XTAL_FREQ 8000000
#include <xc.h>
// PIC18F45K80 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF       // Extended Instruction Set (Enabled)
// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)
// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = SBORDIS  // Brown Out Detect (Enabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)
// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)
// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)
// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)
// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)
// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)
// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)
// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)
// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)
// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

//LED STATUS
#define LEDs_PORT             LATD
//#define LEDs_ON               0xff
//#define LEDs_OFF              0x00

#define TRUE                  1
#define LOW                   0


#include <xc.h>

void PORTs_Initialize(void)
{
    LATA = LATB = LATC = LATD = LATE =  LOW;
 
    TRISA = 0x00; // all are output Pins, Unused
    TRISB = 0x00; // all are output pins , Unused
    TRISC = 0x00; // all are output, Unused
    TRISD = 0x00; // All LEDs are connected to PortD. Output
    TRISE = 0x00; // All are output, Unused

    ANCON0 = 0; // digital port
    ANCON1 = 0; // digital port
    CM1CON = 0; // Comparator off
    CM2CON = 0; // Comparator off
    ADCON0 = 0; // A/D conversion Disabled
}

void main(void)  //Program start from here
{
 
   unsigned int count = 0;
 
     PORTs_Initialize(); // Initialize the PORT
 
     while(TRUE) // run forever
     {
        
         for (count = 0; count <8; count++)
         {
            if (count == 0)
            {
              LEDs_PORT = 0x80;
              __delay_ms(1000); 
            }
            LEDs_PORT = LEDs_PORT >> 1;
            
            __delay_ms(1000);     
        }
    }

}
 

Thread Starter

Djsarakar

Joined Jul 26, 2020
489
I wouldn't bet on it.... You will all be correct Set bit 7 and shift it out... I bet he wants 0x80.. 0xC0.. 0xE0.. etc...
Did you mean like this

C:
/*
* File:   LEDs.c
* Author: Embedded System
* Created on October 15, 2020, 3:41 AM
*/

#define _XTAL_FREQ 8000000
#include <xc.h>
// PIC18F45K80 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF       // Extended Instruction Set (Enabled)
// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)
// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = SBORDIS  // Brown Out Detect (Enabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)
// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)
// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)
// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)
// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)
// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)
// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)
// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)
// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)
// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

//LED STATUS
#define LEDs_PORT             LATD
//#define LEDs_ON               0xff
//#define LEDs_OFF              0x00

#define TRUE                  1
#define LOW                   0


#include <xc.h>

void PORTs_Initialize(void)
{
    LATA = LATB = LATC = LATD = LATE =  LOW;

    TRISA = 0x00; // all are output Pins, Unused
    TRISB = 0x00; // all are output pins , Unused
    TRISC = 0x00; // all are output, Unused
    TRISD = 0x00; // All LEDs are connected to PortD. Output
    TRISE = 0x00; // All are output, Unused

    ANCON0 = 0; // digital port
    ANCON1 = 0; // digital port
    CM1CON = 0; // Comparator off
    CM2CON = 0; // Comparator off
    ADCON0 = 0; // A/D conversion Disabled
}

void main(void)  //Program start from here
{

   unsigned int count = 0;
   unsigned int Byte[9] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00};

    PORTs_Initialize(); // Initialize the PORT

     while(TRUE) // run forever
     {
       
         for (count = 0; count <8; count++)
         {
            LEDs_PORT = Byte[count];
              __delay_ms(1000);
          }  
     }

}
Edit Why compiler showing warning
warning: implicit conversion loses integer precision: 'unsigned int' to 'unsigned char' [-Wconversion]
 
Last edited:

AlbertHall

Joined Jun 4, 2014
12,338
This is a sequence I want for all LEDs

Code:
LEDs:  D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0
State:  1 |  0 |  0 |  0 |  0 |  0 |  0 |  0  
Wait 1 seconds
State:  0 |  1 |  0 |  0 |  0 |  0 |  0 |  0  
Wait 1 seconds
State:  0 |  0 |  1 |  0 |  0 |  0 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  1 |  0 |  0 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  1 |  0 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  0 |  1 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  0 |  0 |  1 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0
Wait 1 seconds
State:  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0
Here is my workin program
C:
/*
* File:   LEDs.c
* Author: Embedded System
* Created on October 15, 2020, 3:41 AM
*/

#define _XTAL_FREQ 8000000
#include <xc.h>
// PIC18F45K80 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF       // Extended Instruction Set (Enabled)
// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)
// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = SBORDIS  // Brown Out Detect (Enabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)
// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)
// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)
// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)
// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)
// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)
// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)
// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)
// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)
// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

//LED STATUS
#define LEDs_PORT             LATD
//#define LEDs_ON               0xff
//#define LEDs_OFF              0x00

#define TRUE                  1
#define LOW                   0


#include <xc.h>

void PORTs_Initialize(void)
{
    LATA = LATB = LATC = LATD = LATE =  LOW;

    TRISA = 0x00; // all are output Pins, Unused
    TRISB = 0x00; // all are output pins , Unused
    TRISC = 0x00; // all are output, Unused
    TRISD = 0x00; // All LEDs are connected to PortD. Output
    TRISE = 0x00; // All are output, Unused

    ANCON0 = 0; // digital port
    ANCON1 = 0; // digital port
    CM1CON = 0; // Comparator off
    CM2CON = 0; // Comparator off
    ADCON0 = 0; // A/D conversion Disabled
}

void main(void)  //Program start from here
{

   unsigned int count = 0;

     PORTs_Initialize(); // Initialize the PORT

     while(TRUE) // run forever
     {
       
         for (count = 0; count <8; count++)
         {
            if (count == 0)
            {
              LEDs_PORT = 0x80;
              __delay_ms(1000);
            }
            LEDs_PORT = LEDs_PORT >> 1;
           
            __delay_ms(1000);    
        }
    }

}
That looks good to me.
 

bertus

Joined Apr 5, 2008
22,266
Hello,

Ok, it is a clear red led.
The forward voltage will be about 2 Volts.
At 5 Volts power supply, the resistor must be higher as (5 - 2) Volts / 8 mA = 375 Ohms.
Use resistors of 470 Ohms to be on the safe side.

Bertus
 

MrSalts

Joined Apr 2, 2020
2,767
Do you need to turn off the analog function
ANCON0 = 0; // digital port
ANCON1 = 0; // digital port

And THEN set them as outputs
TRISB = 0x00;
 

JohnInTX

Joined Jun 26, 2012
4,787
Edit Why compiler showing warning
warning: implicit conversion loses integer precision: 'unsigned int' to 'unsigned char' [-Wconversion]
Because your array (Byte) contains 16 bit integers and the LED port is only 8 bits. The compiler has to decide which of the two bytes in the integer to use. According to C conversion rules the lower 8 bits of the 16 bit integer from the array is used. The upper 8 bits are ignored. The compiler is warning you that it has made that conversion. In this case, it works but you need to fix the array declaration anyway.
 
Last edited:
Top