在结合硬件的编程中,有些变量需要特定地址.
一般可以采用指针变量.
例如:
unsigned int *LedReg = (unsigned int *)0x5f00;//发光二极管地址
*LedReg = 0xFF;
但有些时候感觉不是太好时,可以像Keil那样
unsigned int LedReg at 0x5f00;//发光二极管地址
LedReg = 0xFF;
这样看着"比较顺眼"~~~
但在TIDSP的CCS环境下,不能采用at或__at等来定位地址.
不过CCS也提供了类似的手段,不过有些"麻烦".
具体实现:
1.在CMD文件中
MEMORY
{
PAGE 0: /* Program Memory */
PAGE 1: /* Data Memory */
LED_REG : origin = 0x005f00, length = 0x00001 /*发光二极管地址*/
LCD_ComL : origin = 0x005100, length = 0x00001
LCD_ComH : origin = 0x005200, length = 0x00001
LCD_DatL : origin = 0x005300, length = 0x00001
LCD_DatH : origin = 0x005400, length = 0x00001
EINT_REG : origin = 0x005c00, length = 0x00001
KEY_REG : origin = 0x005b00, length = 0x00001
RCLK_REG : origin = 0x005500, length = 0x00001 /*数码管锁存地址*/
}
SECTIONS
{
LedDataRegsFile : > LED_REG, PAGE = 1
LcdComlRegsFile : > LCD_ComL, PAGE = 1
LcdComhRegsFile : > LCD_ComH, PAGE = 1
LcdDatlRegsFile : > LCD_DatL, PAGE = 1
LcdDathRegsFile : > LCD_DatH, PAGE = 1
KeyRegsFile : > KEY_REG, PAGE = 1
EintRegsFile : > EINT_REG, PAGE = 1
RclkRegsFile : > RCLK_REG, PAGE = 1
}
2.在C/C++文件中
#ifdef __cplusplus
#pragma DATA_SECTION("LedDataRegsFile") /*C++语言格式*/
#else
#pragma DATA_SECTION(LedRegs,"LedDataRegsFile");/*C语言格式*/
#endif
volatile unsigned int LedRegs;
/*以下为C++语言格式*/
#pragma DATA_SECTION("LcdComlRegsFile")
volatile unsigned int LcdComL;
#pragma DATA_SECTION("LcdComhRegsFile")
volatile unsigned int LcdComH;
#pragma DATA_SECTION("LcdDatlRegsFile")
volatile unsigned int LcdDatL;
#pragma DATA_SECTION("LcdDathRegsFile")
volatile unsigned int LcdDatH;
#pragma DATA_SECTION("EintRegsFile")
volatile unsigned int EintRegs;
#pragma DATA_SECTION("KeyRegsFile")
volatile unsigned char KeyRegs;
#pragma DATA_SECTION("RclkRegsFile")
volatile bool SpiRclkRegs;
3.在应用程序中
extern unsigned int LedRegs;
extern volatile unsigned int EintRegs;
extern volatile unsigned char KeyRegs;
extern volatile bool SpiRclkRegs;
//............
LedRegs = 0xff;//这样就不需要指针变量的写法了
//..................
一般可以采用指针变量.
例如:
unsigned int *LedReg = (unsigned int *)0x5f00;//发光二极管地址
*LedReg = 0xFF;
但有些时候感觉不是太好时,可以像Keil那样
unsigned int LedReg at 0x5f00;//发光二极管地址
LedReg = 0xFF;
这样看着"比较顺眼"~~~
但在TIDSP的CCS环境下,不能采用at或__at等来定位地址.
不过CCS也提供了类似的手段,不过有些"麻烦".
具体实现:
1.在CMD文件中
MEMORY
{
PAGE 0: /* Program Memory */
PAGE 1: /* Data Memory */
LED_REG : origin = 0x005f00, length = 0x00001 /*发光二极管地址*/
LCD_ComL : origin = 0x005100, length = 0x00001
LCD_ComH : origin = 0x005200, length = 0x00001
LCD_DatL : origin = 0x005300, length = 0x00001
LCD_DatH : origin = 0x005400, length = 0x00001
EINT_REG : origin = 0x005c00, length = 0x00001
KEY_REG : origin = 0x005b00, length = 0x00001
RCLK_REG : origin = 0x005500, length = 0x00001 /*数码管锁存地址*/
}
SECTIONS
{
LedDataRegsFile : > LED_REG, PAGE = 1
LcdComlRegsFile : > LCD_ComL, PAGE = 1
LcdComhRegsFile : > LCD_ComH, PAGE = 1
LcdDatlRegsFile : > LCD_DatL, PAGE = 1
LcdDathRegsFile : > LCD_DatH, PAGE = 1
KeyRegsFile : > KEY_REG, PAGE = 1
EintRegsFile : > EINT_REG, PAGE = 1
RclkRegsFile : > RCLK_REG, PAGE = 1
}
2.在C/C++文件中
#ifdef __cplusplus
#pragma DATA_SECTION("LedDataRegsFile") /*C++语言格式*/
#else
#pragma DATA_SECTION(LedRegs,"LedDataRegsFile");/*C语言格式*/
#endif
volatile unsigned int LedRegs;
/*以下为C++语言格式*/
#pragma DATA_SECTION("LcdComlRegsFile")
volatile unsigned int LcdComL;
#pragma DATA_SECTION("LcdComhRegsFile")
volatile unsigned int LcdComH;
#pragma DATA_SECTION("LcdDatlRegsFile")
volatile unsigned int LcdDatL;
#pragma DATA_SECTION("LcdDathRegsFile")
volatile unsigned int LcdDatH;
#pragma DATA_SECTION("EintRegsFile")
volatile unsigned int EintRegs;
#pragma DATA_SECTION("KeyRegsFile")
volatile unsigned char KeyRegs;
#pragma DATA_SECTION("RclkRegsFile")
volatile bool SpiRclkRegs;
3.在应用程序中
extern unsigned int LedRegs;
extern volatile unsigned int EintRegs;
extern volatile unsigned char KeyRegs;
extern volatile bool SpiRclkRegs;
//............
LedRegs = 0xff;//这样就不需要指针变量的写法了
//..................