打印

新人求教,急,

[复制链接]
1854|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
nwttjpu|  楼主 | 2011-11-8 19:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
帮忙看下:程序;
dir = -1,这句什么意思
还能给变量赋-1!!!;是不是把1右移一位啥的,
超级新手求解

相关帖子

沙发
nwttjpu|  楼主 | 2011-11-8 19:06 | 只看该作者
大侠们速来啊

使用特权

评论回复
板凳
nwttjpu|  楼主 | 2011-11-8 20:14 | 只看该作者
程序:#include <stdint.h>
#include "LPC17xx.h"
                  
#define LED_NUM     8                      /* Number of user LEDs             */
const unsigned long led_mask[] = { 1UL<<0, 1UL<<1, 1UL<<2, 1UL<< 3,
                                   1UL<< 4, 1UL<< 5, 1UL<< 6, 1UL<< 7 };
int idxCur = -1;                           /* current led position from 0..7  */
int idxOld =  0;                           /* old     led position from 0..7  */
int dir    =  1;                           /* direction for switching the LED */

/**
* @brief  Function that initializes Button INT0
*/
void BUTTON_init(void) {
  LPC_GPIO2->FIODIR      &= ~(1 << 10);    /* PORT2.10 defined as input       */
  LPC_GPIOINT->IO2IntEnF |=  (1 << 10);    /* enable falling edge irq         */

  NVIC_EnableIRQ(EINT3_IRQn);              /* enable irq in nvic              */
}

/**
* @brief  Function that initializes LEDs
*/
void LED_init(void) {
  LPC_GPIO2->FIODIR = 0x000000FF;          /* LEDs on PORT2 defined as Output */
  
  LPC_GPIO0->FIODIR   |= 0x03f80000;
  LPC_GPIO0->FIOSET    = 0x03f80000;
}

/**
* @brief  Function that turns on requested LED
*/
void LED_On (unsigned int num) {

  LPC_GPIO2->FIOPIN |= led_mask[num];
}

/**
* @brief  Function that turns off requested LED
*/
void LED_Off (unsigned int num) {

  LPC_GPIO2->FIOPIN &= ~led_mask[num];
}

/**
* @brief  Function that initializes Button INT0
*/
void EINT3_IRQHandler()
{
  LPC_GPIOINT->IO2IntClr |= (1 << 10);     /* clear pending interrupt         */

  /* Calculate 'idx': 0,1,...,LED_NUM-1,LED_NUM-1,...,1,0,0,...   */
  idxCur += dir;
  if (idxCur == LED_NUM){ dir = -1; idxCur -=  2; }
  else if   (idxCur < 0) {  dir =  1; idxCur +=  2; }

  LED_Off(idxOld);                         /* switch off    old LED position  */
  LED_On (idxCur);                         /* switch on  current LED position */
  idxOld = idxCur;
}


/**
* @brief  Main Function
*/
int main (void)
{
          SystemInit();                            /* initialize system               */
          LED_init();
          idxCur = 0;                              
          idxOld = 0;                           
          dir = 1;                             
          LED_On (idxCur);                         /* switch on  first LED            */
       
          BUTTON_init();

          while (1);                 
}求分析

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:求真,务实

2

主题

98

帖子

0

粉丝