I'm comming from many years on AVR and starting my first PIC project with a PIC18F46K42. Using actual MPLAB v5.15 with XC8 compiler v2.05 (set to C99 standard). (signing up at the microchip forum doesn't work for days...)
And now I'm having basic problems to get a simple IO-port access working:
First setting RC6 as Output:
TRISC = 0b10111111;
Now trying to read IO-Port RC6:
uint8_t LEDstate = PORTCbits_t.RC6; // auto completition of PORTC.. command by xc8
=> compiling Error: unexpected type name 'PORTCbits_t': expected expression
The command "PORTCbits.RC6, without "_t" , which is published in many tutorials, isn't recognized by the compiler at all
And then trying to write to IO-Port RC6:
LATCbits_t.LATC6 = 0; // auto completition of LATC.. command by xc8
=> compinling Error: expected identifier or '('
The command "LATCbits.LATC6, without "_t" , which is also published in many tutorials, isn't also recognized by the compiler at all
Reading the xc8 manual and the datasheet doesn't really help... I think, I missed something basic with this IDE / compiler. Maybe within the setup...
Any ides or suggestions of documentation are really appreciated!!
Many Thanks!!
You might want to consider using MCC (MPLAB Code Configurator). It will make things easier for using the peripherals - even just simple pin I/O.
It also makes keeping track of your resources easier.
You can create alias names for the pins and then MCC will provide you with clean macros like:
#define LEDState_SetHigh() do { LATCbits.LATC6 = 1; } while(0)