0xc000
写入内容,我们可以在C语言中定义一个宏来实现:#define LCDCW1_ADDR 0xc000
#define READ_LCDCW1() (*(volatile uint32_t *)LCDCW1_ADDR)
#define WRITE_LCDCW1(val) ((*(volatile uint32_t *)LCDCW1_ADDR) = (val))
我的问题是,在使用任何微控制器时,以MSP430为例,P1OUT寄存器地址为0x0021。
但是当我们使用P1OUT=0xFFFF;//它会将P1OUT赋值为0xFFFF。
我的问题是,它是如何写入该地址的,例如在此情况下为0x0021。IDE是IAR。我在msp430g2553.h头文件中找到以下定义:
#define P1OUT_ (0x0021u) /* Port 1 Output */
DEFC( P1OUT , P1OUT_)
我猜这是在定义地址,但是其他用于读写的宏在哪里呢?
请问有人能够解释一下P1OUT如何在特定的地址位置进行写入吗?另外,请告诉我0x0021u中的u是什么意思?
谢谢。
到目前为止,我找到的细节如下:
在msp430g2553.h中:
#ifdef __IAR_SYSTEMS_ICC__
#include "in430.h"
#pragma language=extended
#define DEFC(name, address) __no_init volatile unsigned char name @ address;
#define DEFW(name, address) __no_init volatile unsigned short name @ address;
#define DEFXC volatile unsigned char
#define DEFXW volatile unsigned short
#endif /* __IAR_SYSTEMS_ICC__ */
#ifdef __IAR_SYSTEMS_ASM__
#define DEFC(name, address) sfrb name = address;
#define DEFW(name, address) sfrw name = address;
#endif /* __IAR_SYSTEMS_ASM__*/
#define P1OUT_ (0x0021u) /* Port 1 Output */
DEFC( P1OUT , P1OUT_)
io430g2553.h文件中写道
__no_init volatile union
{
unsigned char P1OUT; /* Port 1 Output */
struct
{
unsigned char P0 : 1; /* */
unsigned char P1 : 1; /* */
unsigned char P2 : 1; /* */
unsigned char P3 : 1; /* */
unsigned char P4 : 1; /* */
unsigned char P5 : 1; /* */
unsigned char P6 : 1; /* */
unsigned char P7 : 1; /* */
}P1OUT_bit;
} @0x0021;
有人能解释一下上面的定义是什么意思吗?我在MSP430 IAR C/C++编译器中找到了以下详细信息:
Example of using __write and __read
The code in the following examples use memory-mapped I/O to write to an LCD
display:
__no_init volatile unsigned char LCD_IO @ address;
size_t __write(int Handle, const unsigned char * Buf,
size_t Bufsize)
{
size_t nChars = 0;
/* Check for stdout and stderr
(only necessary if file descriptors are enabled.) */
if (Handle != 1 && Handle != 2)
{
return -1;
}
for (/*Empty */; Bufsize > 0; --Bufsize)
{
LCD_IO = * Buf++;
++nChars;
}
return nChars;
}
The code in the following example uses memory-mapped I/O to read from a keyboard:
__no_init volatile unsigned char KB_IO @ 0xD2;
size_t __read(int Handle, unsigned char *Buf, size_t BufSize)
{
size_t nChars = 0;
/* Check for stdin
(only necessary if FILE descriptors are enabled) */
if (Handle != 0)
{
return -1;
}
for (/*Empty*/; BufSize > 0; --BufSize)
{
unsigned char c = KB_IO;
if (c == 0)
break;
*Buf++ = c;
++nChars;
}
return nChars;
}
有人知道吗?
DEFC()"
几乎肯定是一个宏,就像 "READ_LCDCW1()"
和 "#define LCDCW1_ADDR 0xc000"
一样都是宏。你需要在系统的 *.h 头文件中查看它的作用。 "u
" 只是表示数字 "0x0021" 是 "unsigned" 类型。你可以安全地省略它。 - paulsm4