移位为什么出问题?????????急!!!!!!!!
- UID
- 518123
- 性别
- 男
|
移位为什么出问题?????????急!!!!!!!!
我用定时器中断产生流水灯效果,按下PB1,流水灯从左到右亮,按下PB2效果相反 怎么跑不起来呢????????????
#include <hidef.h> /* for EnableInterrupts macro */ #include "derivative.h" /* include peripheral declarations */
/* DZ60 initialization functions */ #include "DZ60_init.h"
/* TPM1 overflow interrupt service routine */ void interrupt TPM1_ISR(void);
/* I/O macros */
#define LED PTDD /* User LEDs */ /*#define LED2 PTDD_PTDD0 */
#define PB1 PTBD_PTBD0 /* Push buttons */ #define PB2 PTBD_PTBD1
#define ON 0 #define OFF 1
/*****************************************************************************/
void main(void) { MCG_Init(); /* Clock Generator initialization */
GPIO_Init(); /* GPIO configuration */ LED = OFF; /* LEDs initial state */ /* LED2 = OFF; */
TPM1_Init(); /* Real time counter initialization */
EnableInterrupts; /* Enable interrupts */
while(1) {
} }
/*****************************************************************************/ /** * \brief TPM1 overflow interrupt service routine * \author B05114 */ void interrupt 11 TPM1_ISR(void) { static char PB_status = 0;
(void)TPM1SC; /* Read TPM status register */ TPM1SC_TOF = 0; /* and clear interrupt flag */
if (PB1 == 0) PB_status = 1; /* Update status */ if (PB2 == 0) PB_status = 2; /* if (PB2 == 1||PB1 == 1) PB_status = 3; */
switch (PB_status) { case 1:
LED <<1; /* Toggle selected LED */ /*LED2 = OFF;*/ /* and turn-off opposite LED */ break;
case 2:
LED>>1; /* Toggle selected LED */ /* LED2 ^= 1;*/ /* and turn-off opposite LED */ break;
/* case 3: LED = OFF; break; */ }
}
|
|
|
|
|
|
- UID
- 187580
- 性别
- 男
|
个人BLOG:http://blog.eccn.com/u/107300/index.htm |
|
|
|
|
|
- UID
- 143639
- 性别
- 男
|
先确定下有没有进入中断,如果有进,那中断时间是不是太短,以至于来不急看到亮就灭了[em07] |
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
定时100ms,应该够用,是不是移位指令不对啊???????????????
|
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
麻烦版主看看,辛苦可..................呵呵 |
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
麻烦版主看看,辛苦可..................呵呵 |
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
怎么上传啊?我上传了,并提示上传成功,我怎么看不到传到什么地方了???????
怎么上传啊?我上传了,并提示上传成功,我怎么看不到传到什么地方了???????????? |
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
我又改了下程序,可是效果是灯逐个变亮,结果8个led全亮了后就保持了................我感觉是PTDD=PTDD<<1; 出问题了,不能循环移位,如果循环移位,该怎么做啊??????????????????????还有就是在移位方面汇编做的比较好,用嵌入汇编怎么样啊?????????????????[em06] |
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
我又改了下程序,可是效果是灯逐个变亮,结果8个led全亮了后就保持了................我感觉是PTDD=PTDD<<1; 出问题了,不能循环移位,如果循环移位,该怎么做啊??????????????????????还有就是在移位方面汇编做的比较好,用嵌入汇编怎么样啊?????????????????[em06] |
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
ptdd=255; ptdd<<1; 移位7次后是不是变为00000000了?如果要变为11111110、11111101、11111011、~~~~~~~~01111111这样的效果,该怎么写啊??????????????
|
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
好啊
ptdd=255; ptdd<<1; 移位7次后是不是变为00000000了?如果要变为11111110、11111101、11111011、~~~~~~~~01111111这样的效果,该怎么写啊??????????????
|
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
好啊
ptdd=255; ptdd<<1; 移位7次后是不是变为00000000了?如果要变为11111110、11111101、11111011、~~~~~~~~01111111这样的效果,该怎么写啊??????????????
|
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
|
|
|
|
|
- UID
- 518123
- 性别
- 男
|
|
|
|
|
|