标签:
现在终于进入到蓝牙SPI的环节了, 下面还要研究I2C, 所以第一步, 先点灯, 就是GPIO控制吧.
参考一下LEd的初始化:
void HalLedInit (void)
{
#if (HAL_LED == TRUE)
HalLedSet(HAL_LED_ALL, HAL_LED_MODE_OFF); // Initialize all LEDs to OFF.
// Set LED GPIOs to outputs.
LED1_DDR |= LED1_BV;
#if (!defined HAL_PA_LNA && !defined HAL_PA_LNA_CC2590)
LED2_DDR |= LED2_BV;
#if (!defined CC2540_MINIDK && !defined HAL_BOARD_CC2540USB)
LED3_DDR |= LED3_BV;
#endif
#endif
#if defined BLINK_LEDS
HalLedStatusControl.sleepActive = FALSE; // Initialize sleepActive to FALSE.
#endif
#endif
}
其中重要的两句是:
HalLedSet(HAL_LED_ALL, HAL_LED_MODE_OFF); // Initialize all LEDs to OFF.
// Set LED GPIOs to outputs.
LED1_DDR |= LED1_BV;
先看看怎么把GPIO脚P1_0定义为输出
/* 1 - Green */
#define LED1_BV BV(0)
#define LED1_SBIT P1_0
#define LED1_DDR P1DIR
#define LED1_POLARITY ACTIVE_HIGH
/* Port 1 */
SFRBIT( P1 , 0x90, P1_7, P1_6, P1_5, P1_4, P1_3, P1_2, P1_1, P1_0 )
SFR( RFIRQF1 , 0x91 ) /* RF Interrupt Flags MSB */
SFR( DPS , 0x92 ) /* Data Pointer Select */
SFR( MPAGE , 0x93 ) /* Memory Page Select */
SFR( T2CTRL , 0x94 ) /* Timer2 Control Register */
SFR( ST0 , 0x95 ) /* Sleep Timer 0 */
SFR( ST1 , 0x96 ) /* Sleep Timer 1 */
SFR( ST2 , 0x97 ) /* Sleep Timer 2 */
#define LED1_DDR P1DIR
SFR( P1DIR , 0xFE ) /* Port 1 Direction */
所以, LED1_DDR |= LED1_BV; //即: 将SFR 0XFE的值, 或一个00000000.
在看看
HalLedSet(HAL_LED_ALL, HAL_LED_MODE_OFF);
其实重点是:
led = HAL_LED_1;
leds &= HAL_LED_ALL;
sts = HalLedStatusControl.HalLedControlTable;
while (leds)
{
if (leds & led)
{
if (mode != HAL_LED_MODE_TOGGLE)
{
sts->mode = mode; /* ON or OFF */
}
else
{
sts->mode ^= HAL_LED_MODE_ON; /* Toggle */
}
HalLedOnOff (led, sts->mode);
leds ^= led;
}
led <<= 1;
sts++;
}
一开始其实是不是不用写得好像它那么高深莫测, 简单实现以下, 知道如何输出0, 1, 就是第一步的目标. 对吧.
ok, let‘s rock!
标签:
原文地址:http://www.cnblogs.com/Montauk/p/5792579.html