|
/*目的是按下按键则蜂鸣器就发出声音,电路板是msp430F169的学习板*/
#include <msp430x16x.h>
#define NO_KEY 0 //没有按键
#define KEY_K1 1 //按键1
#define KEY_K2 2 //按键2
#define KEY_K3 3 //按键3
#define STEP_IDEL 0 //按键延时
#define STEP_DELAY 1 //等待按键
#define STEP_FINISH 2 //按键过程结束
#define TRUE 1
unsigned int wDelay = 0;
unsigned char nKey = NO_KEY;
unsigned char GetKey(void)
{
static unsigned char nStep = STEP_IDEL;
static unsigned char nBufferedKey;
switch(nStep)
{
case STEP_DELAY: //按键消抖
if(wDelay > 4)
wDelay = 0;
nStep = STEP_FINISH;
break;
case STEP_FINISH: //按键完成
if(((P1IN & 0x04) == 0 )&& (nBufferedKey == KEY_K1))
nKey = KEY_K1;
else if(((P1IN & 0x08) == 0)&& (nBufferedKey == KEY_K2))
nKey = KEY_K2;
else if(((P1IN &0x10) == 0) &&(nBufferedKey ==KEY_K3))
nKey = KEY_K3;
nStep = STEP_IDEL;
break;
case STEP_IDEL: //按键检测
if ((P1IN & 0x04) == 0)
{
nBufferedKey = KEY_K1;
nKey = NO_KEY;
wDelay = 0;
nStep = STEP_DELAY;
}
else if((P1IN &0x08) == 0)
{
nBufferedKey = KEY_K2;
nKey = NO_KEY;
wDelay = 0;
nStep = STEP_DELAY;
}
else if((P1IN & 0x10) == 0)
{
nBufferedKey = KEY_K3;
nKey = NO_KEY;
wDelay = 0;
nStep = STEP_DELAY;
}
break;
default:
break;
}
return nBufferedKey;
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;//关闭看门狗
TACTL = TASSEL1 + TACLR ;//时钟源SMCLK,清除TAR
CCTL0 = CCIE;//CCR0中断使能
CCR0 = 1000;//产生3.2ms的定时
TACTL |= MC0;//Timer_a增计数模式
_EINT();//使能系统中断
while (TRUE)
{
nKey = GetKey();
switch (nKey)
{
case NO_KEY:
break;
case KEY_K1:
P4DIR |= 0x0c;
P4OUT |= 0x04;
nKey= NO_KEY;
break;
case KEY_K2:
P4DIR |= 0x0c;
P4OUT |= 0x08;
nKey= NO_KEY;
break;
case KEY_K3:
nKey = NO_KEY;
break;
}
}
}
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A( void)
{
wDelay++;
}
到中断过程出现以下问题提示
Warn.||1|| Missing ``declaration specifiers'' - assuming ``int''||93||C:\Program Files\AQ430\test.c||
Error||1|| Expected ',' or ';' - skipping to next ';'||93||C:\Program Files\AQ430\test.c||
Error||1|| Expected identifier||96||C:\Program Files\AQ430\test.c||
Warn.||1|| Missing ``declaration specifiers'' - assuming ``int''||96||C:\Program Files\AQ430\test.c||
Error||1|| Expected ',' or ';' - skipping to next ';'||96||C:\Program Files\AQ430\test.c||
主要是 在
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A( void)
{
wDelay++;
}这段出的问题,怎么回事啊?把这一段删除则没有错误了,但是看这段也没有上面错误啊,问题在哪呢?
|
|