NIOS的一小段程序

2019-03-25 09:41发布

在《NIOS那些事》上看的程序,串行通信一节,有点小疑问
SOP.H中的
typedef struct
{    //接收寄存器
    union{
        struct{
            volatile unsigned long int RECEIVE_DATA         :8;
            volatile unsigned long int NC                   :24;          
        }BITS;
        volatile unsigned long int WORD;
    }RXDATA;
    //发送寄存器
    union{
        struct{
            volatile unsigned long int TRANSMIT_DATA        :8;
            volatile unsigned long int NC                   :24;           
        }BITS;
        volatile unsigned long int WORD;
    }TXDATA;
    //状态寄存器
    union{
        struct{
            volatile unsigned long int PE           :1;
            volatile unsigned long int FE           :1;
            volatile unsigned long int BRK          :1;
            volatile unsigned long int ROE          :1;
            volatile unsigned long int TOE          :1;
            volatile unsigned long int TMT          :1;
            volatile unsigned long int TRDY         :1; //准备信号,准备好为1,否则为0
            volatile unsigned long int RRDY         :1;
            volatile unsigned long int E            :1;
            volatile unsigned long int NC           :1;
            volatile unsigned long int DCTS         :1;
            volatile unsigned long int CTS          :1;
            volatile unsigned long int EOP          :1;
            volatile unsigned long int NC1          :19;           
        } BITS;
        volatile unsigned long int WORD;
    }STATUS;
    //控制寄存器
    union{
        struct{
            volatile unsigned long int IPE          :1;
            volatile unsigned long int IFE          :1;
            volatile unsigned long int IBRK         :1;
            volatile unsigned long int IROE         :1;
            volatile unsigned long int ITOE         :1;
            volatile unsigned long int ITMT         :1;
            volatile unsigned long int ITRDY        :1;
            volatile unsigned long int IRRDY        :1;
            volatile unsigned long int IE           :1;
            volatile unsigned long int TRBK         :1;
            volatile unsigned long int IDCTS        :1;
            volatile unsigned long int RTS          :1;
            volatile unsigned long int IEOP         :1;
            volatile unsigned long int NC           :19;           
        }BITS;
        volatile unsigned long int WORD;
    }CONTROL;
    //波特率寄存器
    union{
        struct{
            volatile unsigned long int BAUD_RATE_DIVISOR    :16;
            volatile unsigned long int NC                   :16;          
        }BITS;
        volatile unsigned  int WORD;
    }DIVISOR;

}UART_ST;
在UART.C中有个语句
UART->STATUS.WORD=0;
说是这个语句对状态寄存器清零了,这是为什么呢?volatile unsigned long int WORD;这个状态寄存器中的WORD定义的是什么意思呢?
还有->是什么用法?C里的吗?
编程能力不好,求指教
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
kdy
2019-03-25 20:34
1、UART是一个结构体变量,UART.C中应该有UART_ST UART;这样的语句。定义一个结构体UART。 2、UART->STATUS.WORD=0这样就是对状态寄存器清零是因为 union{ struct{ volatile unsigned long int PE :1; volatile unsigned long int FE :1; volatile unsigned long int BRK :1; volatile unsigned long int ROE :1; volatile unsigned long int TOE :1; volatile unsigned long int TMT :1; volatile unsigned long int TRDY :1; //准备信号,准备好为1,否则为0 volatile unsigned long int RRDY :1; volatile unsigned long int E :1; volatile unsigned long int NC :1; volatile unsigned long int DCTS :1; volatile unsigned long int CTS :1; volatile unsigned long int EOP :1; volatile unsigned long int NC1 :19; } BITS; volatile unsigned long int WORD; 这一段联合Union的定义表示WORD和以上的Struct共享同一段内存(请仔细看C的联合、结构体章节)所以可以互相赋值。 BITS就是WORD的位

一周热门 更多>