【问题标题】:PIC24 setting bits in registersPIC24 设置寄存器中的位
【发布时间】:2014-12-17 20:46:15
【问题描述】:

我正在使用 C 使用 XC16 编译器在 MPLABX 中为 PIC24FJ192GA106 进行一些编程。我在编译过程中遇到以下问题

error: request for member 'UARTEN' in something not a structure or union

问题是:

U1MODE.UARTEN = '1';

U1MODE 是定义在#include "p24FJ192GA106.h" 中的结构体(头文件包含在文件中),具体结构如下

`#define U1MODE U1MODE
extern volatile unsigned int  U1MODE __attribute__((__sfr__));
__extension__ typedef struct tagU1MODEBITS {
  union {
    struct {
      unsigned STSEL:1;
      unsigned PDSEL:2;
      unsigned BRGH:1;
      unsigned RXINV:1;
      unsigned ABAUD:1;
      unsigned LPBACK:1;
      unsigned WAKE:1;
      unsigned UEN:2;
      unsigned :1;
      unsigned RTSMD:1;
      unsigned IREN:1;
      unsigned USIDL:1;
      unsigned :1;
      unsigned UARTEN:1;
    };
    struct {
      unsigned :1;
      unsigned PDSEL0:1;
      unsigned PDSEL1:1;
      unsigned :5;
      unsigned UEN0:1;
      unsigned UEN1:1;
    };
  };
} U1MODEBITS;
extern volatile U1MODEBITS U1MODEbits __attribute__((__sfr__));`

我也试过

U1MODEbits.UARTEN = '1';
U1MODEBITS.UARTEN = '1';

或不同的值

U1MODEbits.UARTEN = 0b1;
U1MODEbits.UARTEN = 1;

但没有运气,任何想法我做错了什么?

---- main.c ----

// PIC24 HEADER
#include "p24FJ192GA106.h"
// CONFIGURATION WORDS 2
#pragma config POSCMOD = NONE           // Primary Oscillator Select (Primary oscillator disabled)
#pragma config IOL1WAY = OFF            // IOLOCK One-Way Set Enable bit (Unlimited Writes To RP Registers)
#pragma config OSCIOFNC = OFF           // Primary Oscillator Output Function (OSCO functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor (Both Clock Switching and Fail-safe Clock Monitor are disabled)
#pragma config FNOSC = FRCDIV           // Oscillator Select (Fast RC oscillator with Postscaler (FRCDIV))
#pragma config IESO = ON                // Internal External Switch Over Mode (IESO mode (Two-speed start-up) enabled)
// CONFIGURATION WORDS 1
#pragma config WDTPS = PS32768          // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128            // WDT Prescaler (Prescaler ratio of 1:128)
#pragma config WINDIS = OFF             // Watchdog Timer Window (Standard Watchdog Timer is enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (Watchdog Timer is disabled)
#pragma config ICS = PGx1               // Comm Channel Select (Emulator functions are shared with PGEC1/PGED1)
#pragma config GWRP = OFF               // General Code Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF                // General Code Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = ON              // JTAG Port Enable (JTAG port is enabled)

int main() {

    U1MODEbits.UARTEN = 1; // Unable to resolve identifier U1MODEbits

    U1MODEbits.UARTEN = 1; // above mentioned problem during compilation

    while(1){};

};

【问题讨论】:

  • 那么,我应该定义自己的 U1MODEbits 类型的变量并使用它吗?
  • U1MODEbits.UARTEN = 1; 是正确的语法,你不应该定义任何东西,它对我有用,如果你这样做有什么错误?
  • U1MODEbits 无法识别 -> 无法解析标识符 U1MODEbits
  • 您确定项目配置的是24FJ192GA106设备吗?另外,如果我错了,请纠正我,但这看起来不像是编译器错误,而是 MPLABX 会给你的。 MPLABX 通常会给出虚假的红色下划线。您是否尝试实际编译?什么是编译器错误?
  • 1) 是的,该项目配置为 PIC24FJ192GA106 2) 是的,“无法解析标识符 U1MODEbits”不是编译过程中的错误,MPLABX 强调了它 3) 好吧,我已经尝试编译它使用 U1MODEbits 并且似乎可以工作:D .... 没有编译器错误谢谢

标签: c struct header microchip pic24


【解决方案1】:

U1MODEbits.UARTEN = 1; 是正确的语法,'1' 肯定是错误的,因为它表示字符 '1',即 0x31。

另外,Unable to resolve identifier 不是编译器错误,而是 MPLABX 给出的消息(当它带有红色下划线时)。 MPLABX 经常会给出错误的红线,所以你不应该过分依赖它,无论如何都要编译。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-25
    • 2014-05-13
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 2017-07-15
    • 2020-11-21
    相关资源
    最近更新 更多