[求助]
G2553.h头文件有许多不明白的地方,求帮助解释
各位坛友好,我今天晚上闲来无事,查看了一下g2553的头文件,发现了有好多细节的地方很不清楚,百度了一晚上也弄不出个所以然,所以希望在这里大家能帮助我解释一下这些疑问。问题如下:
在g2553的头文件中,
/* External references resolved by a device-specific linker command file */
#define SFR_8BIT(address) extern volatile unsigned char address
这个要怎么理解,结合下面的:
#ifndef __DisableCalData
SFR_8BIT(CALDCO_16MHZ); /* DCOCTL Calibration Data for 16MHz */
SFR_8BIT(CALBC1_16MHZ); /* BCSCTL1 Calibration Data for 16MHz */
SFR_8BIT(CALDCO_12MHZ); /* DCOCTL Calibration Data for 12MHz */
SFR_8BIT(CALBC1_12MHZ); /* BCSCTL1 Calibration Data for 12MHz */
SFR_8BIT(CALDCO_8MHZ); /* DCOCTL Calibration Data for 8MHz */
SFR_8BIT(CALBC1_8MHZ); /* BCSCTL1 Calibration Data for 8MHz */
SFR_8BIT(CALDCO_1MHZ); /* DCOCTL Calibration Data for 1MHz */
SFR_8BIT(CALBC1_1MHZ); /* BCSCTL1 Calibration Data for 1MHz */
#endif /* #ifndef __DisableCalData */
我是越看越不能理解,类似SFR_8BIT(CALDCO_16MHZ); /* DCOCTL Calibration Data for 16MHz */ 的代码有很多很多,主要是对
/* External references resolved by a device-specific linker command file */
#define SFR_8BIT(address) extern volatile unsigned char address
的不理解,其次#ifndef __DisableCalData和#endif /* #ifndef __DisableCalData */又是什么意思,请各位高人前辈帮忙,谢谢。
回复 楼主 bobde163 的帖子
#ifndef __DisableCalData和#endif /* #ifndef __DisableCalData
是条件编译。如果没有定义就定义它。请参考C语言手册
[ 本帖最后由 qinkaiabc 于 2012-12-20 15:37 编辑 ]
回复 楼主 bobde163 的帖子
SFR_8BIT(CALDCO_16MHZ);
对使用宏定义的地方进行字符展开就是:extern volatile unsigned char CALDCO_16MHZ;
SFR_8BIT is a macro that defines a variable to be a volatile unsigned char located at a certain address.
You quoted the macro definition.
However, somewhere else in a different header file, the macro is used in the form
SFR_8BIT(P1DIR = 0x22);
or
SFR_8BIT(0x22) P1DIR;
or something similar. I don't use IAR/CCS, so I don't know the exact syntax there, but on mspgcc it is similar:
#define sfrb(name, address) volatile unsigned char name asm(#address);
and used with
sfrb(P1DIR, 0x22);
throughout the different header files, which then expands to
volatile unsigned char P1DIR asm("0x22");
There are also sfrw and sfra macros which do the same for word or address-word (20bit) registers
The macro is usd in other header files which may be in a processor-specific subfolder or such. Perhaps it is even assembled by calling an include file with the name of the Port (P1) and the base address (0x20), so the same include file can be called for any number of ports, by addign port name and port register extension (P1 and OUT) and adding base address and register offset (0x20 and 2). It keeps maintenance low and allows reusing the header file for different MSPs with different module addresses but otherwise same module hardware.
回复 板凳 qinkaiabc 的帖子
是一个宏定义,现在理解了,但是我不明白在官方给出的温度演示程序的C代码中有这样一条:
void InitializeClocks(void)
{
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3);
}
里面的CALBC1_1MHZ和CALDCO_1MHZ不知道在哪里定义的,在头文件中
SFR_8BIT(CALDCO_1MHZ); /* DCOCTL Calibration Data for 16MHz */
SFR_8BIT(CALBC1_1MHZ); /* BCSCTL1 Calibration Data for 16MHz */
这两句也是定义它们是一个不可被编译优化的变量,而在G2553的datasheet中所使用的标签是CAL_DCO_1MHZ和 CAL_BC1_1MHZ,这又让我搞不清楚,您能再解释一下吗?
没仔细看
反正我也觉得一大堆书就是没有明了地讲明白实际中遇到的各种情况的机理的中文书
关于SFR_8BIT的相关说明:
External references resolved by a device - specific linker command file
(外部引用解决的特定于设备的连接器命令文件)
#define SFR_8BIT(address) extern volatile unsigned char address
#define SFR_16BIT(address) extern volatile unsigned int address
CALBC1_1MHZ and CALDCO_1MHZ are two bytes programmed in the flash at the factory which are a calibrated value as to the VCO (voltage controlled oscillator) of the chip. This means that when you load those two values into the respective registers, you are using a precalibrated setting to get appoximately 1MHz.
CALBC1_1MHZ and CALDCO_1MHZ是用来设置校准值的。TI已经把他放进flash中了。
#define CALDCO_8MHZ_ (0x10FCu) /* DCOCTL Calibration Data for 8MHz */
READ_ONLY DEFC( CALDCO_8MHZ, CALDCO_8MHZ_)
#define CALBC1_8MHZ_ (0x10FDu) /* BCSCTL1 Calibration Data for 8MHz */
READ_ONLY DEFC( CALBC1_8MHZ, CALBC1_8MHZ_)
#define CALDCO_12MHZ_ (0x10FAu) /* DCOCTL Calibration Data for 12MHz */
READ_ONLY DEFC( CALDCO_12MHZ, CALDCO_12MHZ_)
#define CALBC1_12MHZ_ (0x10FBu) /* BCSCTL1 Calibration Data for 12MHz */
READ_ONLY DEFC( CALBC1_12MHZ, CALBC1_12MHZ_)
#define CALDCO_16MHZ_ (0x10F8u) /* DCOCTL Calibration Data for 16MHz */
READ_ONLY DEFC( CALDCO_16MHZ, CALDCO_16MHZ_)
#define CALBC1_16MHZ_ (0x10F9u) /* BCSCTL1 Calibration Data for 16MHz */
READ_ONLY DEFC( CALBC1_16MHZ, CALBC1_16MHZ_)
回复 8楼 qinkaiabc 的帖子
我想问一下,你给出的这段定义的代码是出自G2553.h这个头文件中吗?我在头文件中怎么也找不到
回复 7楼 qinkaiabc 的帖子
这个我知道,在数据表中看到了,只是数据表中给它的定义的标签是CAL_DCO_1MHZ和 CAL_BC1_1MHZ,这两者没有关系吗?
回复 5楼 wangfuchong 的帖子
我刚入门,很多细节的地方没有弄清楚,希望能向您能多多求教
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
#define CALDCO_1MHZ_ (0x10FEu) /* DCOCTL Calibration Data for 1MHz */
READ_ONLY DEFC( CALDCO_1MHZ , CALDCO_1MHZ_)
#define CALBC1_1MHZ_ (0x10FFu) /* BCSCTL1 Calibration Data for 1MHz */
READ_ONLY DEFC( CALBC1_1MHZ , CALBC1_1MHZ_)
0X10FFu表示地址;
TI的芯片在出厂时有一个校准好的1MHz时钟值,放在这个地方,
程序中直接调用就ok
在作如下宏定义之前,
#define CALDCO_1MHZ_ (0x10FEu) /* DCOCTL Calibration Data for 1MHz */
READ_ONLY DEFC( CALDCO_1MHZ , CALDCO_1MHZ_)
#define CALBC1_1MHZ_ (0x10FFu) /* BCSCTL1 Calibration Data for 1MHz */
READ_ONLY DEFC( CALBC1_1MHZ , CALBC1_1MHZ_)
头文件中有一行字:
/************************************************************
* Calibration Data in Info Mem
************************************************************/
他的意思就是:存储在flash中的校准数据,0x10FFu 这些都是他们的地址
在430内部有个信息段用于存储为何DCO可以配置到各种不同的频率的值的
回复 16楼 qinkaiabc 的帖子
我用的是CCS5.2
回复 17楼 qinkaiabc 的帖子
我仔细对照了您给我的这个头文件和CCS里的头文件,在基础时钟模块的定义的这就不一样,CCS里的如下:
/************************************************************
* Basic Clock Module
************************************************************/
#define __MSP430_HAS_BC2__ /* Definition to show that Module is available */
SFR_8BIT(DCOCTL); /* DCO Clock Frequency Control */
SFR_8BIT(BCSCTL1); /* Basic Clock System Control 1 */
SFR_8BIT(BCSCTL2); /* Basic Clock System Control 2 */
SFR_8BIT(BCSCTL3); /* Basic Clock System Control 3 */
您给出的是下面这样的:
/************************************************************
* Basic Clock Module
************************************************************/
#define __MSP430_HAS_BC2__ /* Definition to show that Module is available */
#define DCOCTL_ (0x0056u) /* DCO Clock Frequency Control */
DEFC( DCOCTL , DCOCTL_)
#define BCSCTL1_ (0x0057u) /* Basic Clock System Control 1 */
DEFC( BCSCTL1 , BCSCTL1_)
#define BCSCTL2_ (0x0058u) /* Basic Clock System Control 2 */
DEFC( BCSCTL2 , BCSCTL2_)
#define BCSCTL3_ (0x0053u) /* Basic Clock System Control 3 */
DEFC( BCSCTL3 , BCSCTL3_)
还有在后面的也不一样,CCS里的:
/************************************************************
* Calibration Data in Info Mem
************************************************************/
#ifndef __DisableCalData
SFR_8BIT(CALDCO_16MHZ); /* DCOCTL Calibration Data for 16MHz */
SFR_8BIT(CALBC1_16MHZ); /* BCSCTL1 Calibration Data for 16MHz */
SFR_8BIT(CALDCO_12MHZ); /* DCOCTL Calibration Data for 12MHz */
SFR_8BIT(CALBC1_12MHZ); /* BCSCTL1 Calibration Data for 12MHz */
SFR_8BIT(CALDCO_8MHZ); /* DCOCTL Calibration Data for 8MHz */
SFR_8BIT(CALBC1_8MHZ); /* BCSCTL1 Calibration Data for 8MHz */
SFR_8BIT(CALDCO_1MHZ); /* DCOCTL Calibration Data for 1MHz */
SFR_8BIT(CALBC1_1MHZ); /* BCSCTL1 Calibration Data for 1MHz */
您给的:
/************************************************************
* Calibration Data in Info Mem
************************************************************/
#ifndef __DisableCalData
#define CALDCO_16MHZ_ (0x10F8u) /* DCOCTL Calibration Data for 16MHz */
READ_ONLY DEFC( CALDCO_16MHZ , CALDCO_16MHZ_)
#define CALBC1_16MHZ_ (0x10F9u) /* BCSCTL1 Calibration Data for 16MHz */
READ_ONLY DEFC( CALBC1_16MHZ , CALBC1_16MHZ_)
#define CALDCO_12MHZ_ (0x10FAu) /* DCOCTL Calibration Data for 12MHz */
READ_ONLY DEFC( CALDCO_12MHZ , CALDCO_12MHZ_)
#define CALBC1_12MHZ_ (0x10FBu) /* BCSCTL1 Calibration Data for 12MHz */
READ_ONLY DEFC( CALBC1_12MHZ , CALBC1_12MHZ_)
#define CALDCO_8MHZ_ (0x10FCu) /* DCOCTL Calibration Data for 8MHz */
READ_ONLY DEFC( CALDCO_8MHZ , CALDCO_8MHZ_)
#define CALBC1_8MHZ_ (0x10FDu) /* BCSCTL1 Calibration Data for 8MHz */
READ_ONLY DEFC( CALBC1_8MHZ , CALBC1_8MHZ_)
#define CALDCO_1MHZ_ (0x10FEu) /* DCOCTL Calibration Data for 1MHz */
READ_ONLY DEFC( CALDCO_1MHZ , CALDCO_1MHZ_)
#define CALBC1_1MHZ_ (0x10FFu) /* BCSCTL1 Calibration Data for 1MHz */
READ_ONLY DEFC( CALBC1_1MHZ , CALBC1_1MHZ_)
都不一样,难道这是因为我使用的是CCS而您使用的是IAR的原因吗?