compiler-errorsxc8mplab-x

Unable to resolve identifier


Being a beginner i have written this code in xc8 compiler but its showing warning on include file and error on port and tris register(Unable to resolve Identifier).Also When i execute this code in Proteus it only blink led on RB0 except on whole port.I tried alot from past two days but all attempts go in vain.


#define _XTAL_FREQ 8000000

#pragma config FOSC = XT
#pragma config WDTE = ON 
#pragma config PWRTE = OFF 
#pragma config BOREN = ON 
#pragma config LVP = OFF 
#pragma config CPD = OFF 
#pragma config WRT = OFF 
#pragma config CP = OFF 

int main()
{
  TRISB = 0 ; //RB0 as Output PIN
  while(1)
  {
    PORTB = 1;  // LED ON
    _delay_ms(1000); // 1 Second Delay
    PORTB = 0;  // LED OFF
    _delay_ms(1000); // 1 Second Delay
  }
  return 0;
}```

Solution

  • When compiling with XC8 include the XC8 header by adding the line #include <xc.h>. Writing 1 to PORTB will only set bit 0 and turn on RB0. To turn on RB0 through RB7 set all 8 bits by writing PORT B = 0b11111111 (255 decimal).