首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >寄存器中的PIC24设置位

寄存器中的PIC24设置位
EN

Stack Overflow用户
提问于 2014-12-17 20:46:15
回答 1查看 809关注 0票数 0

我正在用C语言用PIC24FJ192GA106编译器在MPLABX中为XC16编写一些程序,我在编译过程中遇到了以下问题

代码语言:javascript
复制
error: request for member 'UARTEN' in something not a structure or union

问题是:

代码语言:javascript
复制
U1MODE.UARTEN = '1';

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

代码语言:javascript
复制
`#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__));`

我也试过

代码语言:javascript
复制
U1MODEbits.UARTEN = '1';
U1MODEBITS.UARTEN = '1';

或不同的价值

代码语言:javascript
复制
U1MODEbits.UARTEN = 0b1;
U1MODEbits.UARTEN = 1;

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

代码语言:javascript
复制
// 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){};

};
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-17 21:50:17

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

另外,Unable to resolve identifier不是编译器错误,而是由MPLABX提供的消息(当它以红色下划线时)。MPLABX经常会给出错误的红线,所以您不应该过多地依赖它并编译。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27534562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档