本帖最后由 奔波儿熊 于 2019-4-26 17:12 编辑
首先是AVR的IO口定义, 摘自iom4808.h:
typedef volatile uint8_t register8_t;
/* Virtual Ports */
typedef struct VPORT_struct
{
register8_t DIR; /* Data Direction */
register8_t OUT; /* Output Value */
register8_t IN; /* Input Value */
register8_t INTFLAGS; /* Interrupt Flags */
} VPORT_t;
/* I/O Ports */
typedef struct PORT_struct
{
register8_t DIR; /* Data Direction */
register8_t DIRSET; /* Data Direction Set */
register8_t DIRCLR; /* Data Direction Clear */
register8_t DIRTGL; /* Data Direction Toggle */
register8_t OUT; /* Output Value */
register8_t OUTSET; /* Output Value Set */
register8_t OUTCLR; /* Output Value Clear */
register8_t OUTTGL; /* Output Value Toggle */
register8_t IN; /* Input Value */
register8_t INTFLAGS; /* Interrupt Flags */
register8_t PORTCTRL; /* Port Control */
register8_t reserved_0x0B;
register8_t reserved_0x0C;
register8_t reserved_0x0D;
register8_t reserved_0x0E;
register8_t reserved_0x0F;
register8_t PIN0CTRL; /* Pin 0 Control */
register8_t PIN1CTRL; /* Pin 1 Control */
register8_t PIN2CTRL; /* Pin 2 Control */
register8_t PIN3CTRL; /* Pin 3 Control */
register8_t PIN4CTRL; /* Pin 4 Control */
register8_t PIN5CTRL; /* Pin 5 Control */
register8_t PIN6CTRL; /* Pin 6 Control */
register8_t PIN7CTRL; /* Pin 7 Control */
register8_t reserved_0x18;
register8_t reserved_0x19;
register8_t reserved_0x1A;
register8_t reserved_0x1B;
register8_t reserved_0x1C;
register8_t reserved_0x1D;
register8_t reserved_0x1E;
register8_t reserved_0x1F;
} PORT_t;
#define VPORTA (*(VPORT_t *) 0x0000) /* Virtual Ports */
#define PORTA (*(PORT_t *) 0x0400) /* I/O Ports */
其次是PIC的IO口定义, 摘自pic16f18875.h:
// Register: PORTA
#define PORTA PORTA
extern volatile unsigned char PORTA @ 0x00C;
#ifndef _LIB_BUILD
asm("PORTA equ 0Ch");
#endif
// bitfield definitions
typedef union {
struct {
unsigned RA0 :1;
unsigned RA1 :1;
unsigned RA2 :1;
unsigned RA3 :1;
unsigned RA4 :1;
unsigned RA5 :1;
unsigned RA6 :1;
unsigned RA7 :1;
};
} PORTAbits_t;
extern volatile PORTAbits_t PORTAbits @ 0x00C;
两个有趣的地方已经标红了.
问题1:
#define PORTA PORTA 有什么用?
问题2:
extern volatile unsigned char PORTA @ 0x00C;
看到这行我的第一反应是有extern, 这应该是PORTA的声明, 那应该有个地方定义了PORTA, 但是我并没有找到. 那怎么理解呢?
关于这两个问题,我心里已经有了自己的答案, 先不献丑了,先看看强大的水友们有何见解.
|