Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8372049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:19:07+00:00 2026-06-09T14:19:07+00:00

In microchip C30 compiler i can set pin i/o value using LAT register in

  • 0

In microchip C30 compiler i can set pin i/o value using LAT register in this way:

LATBbits.LATB10=1;

LATBbits is defined as:

typedef struct tagLATBBITS {
  unsigned LATB0:1;
  unsigned LATB1:1;
  unsigned LATB2:1;
  unsigned LATB3:1;
  unsigned LATB4:1;
  unsigned LATB5:1;
  unsigned LATB6:1;
  unsigned LATB7:1;
  unsigned LATB8:1;
  unsigned LATB9:1;
  unsigned LATB10:1;
  unsigned LATB11:1;
  unsigned LATB12:1;
  unsigned LATB13:1;
  unsigned LATB14:1;
  unsigned LATB15:1;
} LATBBITS;
extern volatile LATBBITS LATBbits __attribute__((__sfr__));

My target is to write a function that can set i/o value using LAT register as an argument, in pseudocode:

void setPin(unsigned int* latReg, unsigned int value){
  (*latReg)=value;
}

setPin(&LATBbits.LATB10, 1);

Unfortunately this code won’t compile because “cannot take address of bit-field ‘LATB10′”.

I need it because i want to realize a simil-class library that can handle a port expander. Each port expander can have different pins, so i need to configure it and i think to do something like this:

typedef struct sPortExpander{
  unsigned int* CS;
  unsigned int* SPBUFF;
  ecc...
} PortExpander

void PortExpander_setOutput(PortExpander p, unsigned char value){
  (*p.CS)=0;
  // Send SPI data
  (*p.CS=1);
}

In this way i can manage multiple port expander.

So, there is a way to do what i try to do?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:19:08+00:00Added an answer on June 9, 2026 at 2:19 pm

    Declare the struct as __attribute__((packed)), then use:

    void function setPin(struct LATBBITS *reg, unsigned int fieldno, unsigned int value){
        if (value)
            *(uint16_t *)reg |= (1 << fieldno);
        else
            *(uint16_t *)reg &= ~(1 << fieldno);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to port code over to compile using Microchip's C18 compiler for a
I am currently starting out with programming micro controllers using C30 (A C compiler
Using Microchip C18 compiler with a pic18f, I want to create a big buffer
I'm using a crude IDE (Microchip MPLAB) with C30 toolchain on Windows XP. The
I am using the Microchip C18 compiler and on occurrence of an interrupt I
I'm currently using Microchip's Fixed Point Library, but I think this applies to most
update I'm using pic 18F4550 with microchip v8.63 and C compiler. I'm trying to
I'm writing for a microcontroller (dsPIC24) using Microchip's compiler. The peripheral devices are all
This code is for Microchip's PIC32MX microprocessor. Their compiler is essentially GCC 3.4. I
I'm porting the T6963-based LCD driver from AVR-GCC to the microchip C18 compiler. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.