#include "NUC1xx.h"
int32_t main (void)
{
uint32_t TEMP=0;
NVIC_DisableIRQ(TMR0_IRQn); //Disable Timer0 interrupt
outpw(&TIMER0->TCSR ,0 ); //Disable Timer0
//分析:由于->的优先级高于&,所以是先取结构体指针TIMER0的成员TCSR ,关键看这个成员“TCSR”是不是
// "outpw"入口参数所对应的类型。有(2)处解释知,这里的“TCSR”不是一个地址,而是一个结构体,所以前面要加一个取地址符&。
......
......
......
}
====================NUC1xx.h中有如下定义
有一段----------------
#define outpw(port,value) *((volatile unsigned int *)(port))=value //(1):注意,这里port的值只可能是某个寄存器的地址,即是个地址值
#define inpw(port) (*((volatile unsigned int *)(port)))
#define outpb(port,value) *((volatile unsigned char *)(port))=value
#define inpb(port) (*((volatile unsigned char *)(port)))
#define outps(port,value) *((volatile unsigned short *)(port))=value
#define inps(port) (*((volatile unsigned short *)(port)))
还有一段-----------------
#define TIMER0 ((TIMER_T *) TIMER0_BASE)
#define TIMER1 ((TIMER_T *) TIMER1_BASE)
#define TIMER2 ((TIMER_T *) TIMER2_BASE)
#define TIMER3 ((TIMER_T *) TIMER3_BASE)
还有一段-------------------
typedef struct
{
__IO uint32_t PRESCALE:8;
__I uint32_t RESERVE0:8;
__IO uint32_t TDR_EN:1;
__I uint32_t RESERVE1:8;
__IO uint32_t CACT:1;
__IO uint32_t CRST:1;
__IO uint32_t MODE:2;
__IO uint32_t IE:1;
__IO uint32_t CEN:1;
__IO uint32_t nDBGACK_EN:1;
} TIMER_TCSR_T;
typedef struct
{
TIMER_TCSR_T TCSR; //(2)有这里看出结构体"TIMER_T"的成员 TCSR并不是一个地址值,而是仅仅是一个TIMER_TCSR_T类型的结构体
TIMER_TCMPR_T TCMPR;
TIMER_TISR_T TISR;
TIMER_TDR_T TDR;
} TIMER_T; |