PIC18 IO-Port noobie issues with XC8

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)

Problem with RC0 on a PIC18F4550, PIC Microcontrollers (PIC10F, PIC12F, PIC16F, PIC18F); Problem with RC0 I can get this to work for bits on other ports like A and B, but for some reason not RC0. I am a newbie and attempting to learn the tricks of the processor, the IDE, RC1 is also configurable as CCP2 input/output and UOE output. MPLAB® XC8 C COMPILER USER’S GUIDE FOR PIC 2012-2018 Microchip Technology Inc. DS50002737A-page 5 Preface INTRODUCTION This chapter contains general information that will be useful to know before using the MPLAB® XC8 C Compiler User’s Guide for PIC ® MCU. Items discussed in this chapter include: • Document Layout

..._t is wrong, it's a type definition. Take a look at the part header (pic18lf46k42.h), line 46579. The actual port structure, defined at the next line, is called PORTCbits . In order for this name to be recognized you need to #include <xc.h> in your source and make sure the correct part is set up in the MPLAB project.

I'm using this notation all the time and it always works, given that the pin exists and the above two conditions are met. Example:

https://github.com/felis/stirrer/blob/f-desk/board_control/code/stirrer/bsp.h#L58

Read Modify Write Problem with PIC Microcontrollers, PIC18 IO-Port noobie issues with XC8. As mentioned by Oleg, the _t is incorrect​. Change the line to the one below and it will compile without issues. uint8_t  Programming PIC 18 using XC8 (MPLAB X) : USART (PIC18F Serial) May 15th, 2013 singularengineer Leave a comment Go to comments I was about to start Analog to Digital Converters (ADC), but then how am I going to see the output?

As mentioned by Oleg, the ..._t is incorrect. Change the line to the one below and it will compile without issues.

uint8_t LEDstate = PORTCbits.RC6; // auto completition of PORTC.. command by xc8

I've just tried the following code with your chip and it compiled without any issues.

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <stdint.h>

int main(int argc, char** argv) {
    uint8_t LEDstate = PORTCbits.RC6; // auto completition of PORTC.. command by xc8
    return (EXIT_SUCCESS);
}

I2C Communication with PIC Microcontroller, Mid-Range PIC Microcontroller uses two registers, TRIS and PORT to control the direction and status of an IO pin respectively. When you try to  MPLAB® XC8 C COMPILER USER’S GUIDE 2012-2016 Microchip Technology Inc. DS50002053G-page 7 Preface INTRODUCTION This chapter contains general information that will be useful to know before using the MPLAB® XC8 C Compiler User’s Guide. Items discussed in this chapter include: • Document Layout

8-bit Enhanced Mid-Range Digital I/O, Master and Slave using MPLAB XC8. device which is connected to different slave devices like I/O Port Expanders, LED/LCD Drivers, ADCs, Synchronous Serial Port Mode Select bits – PIC 16F877A But i have problem with I2C device​. Thank you very clear for a newbie like myself to understand. Programming PIC 18 using XC8 (MPLAB X) : IO ports April 14th, 2013 singularengineer Leave a comment Go to comments When you start the project, the main.c (or newmain.c, depends on what you named your main c file).

Led blinking program for pic18f2550, Miscellaneous · Appearance · Diff · Files · Issue Tracking · JavaScript XC8 (also HI-TECH compilers PICC, PICC18-STD, PIC18-PRO, dsPIC®, PIC32) · XC16 (​also I/O Port Trace Connections (Logic Port) · Setting Up Trace in MPLAB X IDE  MPLAB X IDE problem with PIC Programmer I have a programmer and it works fine with PICKit2v2. As you see in the below images, I read my PIC16F877A memory and write to it successfully : But the problem appears when I want to use my

pic: PIC18 IO-Port проблемы с Noobie с XC8, The circuit presented here solves this problem by adding a simple hardware Actually i am toggling the whole Port-A of pic microcontroller. page for the test programs for 18F2550/18F4550 with led blinking, serial port test and I/O port Simple LED using PIC18F2550 microcontroller using mplabx IDE and XC8 Compiler.