#include<msp430x14x.h>
#define Pad1_OUT_L P1DIR|=BIT3;P1OUT&=~BIT3 //将Pad1置为低电平的宏定义
#define Pad1_DIR_IN P1DIR&=~BIT3 //将Pad1设置为输入状态的宏定义
#define Pad1_in (P1IN&BIT3) //读回Pad1电平的宏定义
#define Pad2_OUT_L P1DIR|=BIT1;P1OUT&=~BIT1 //将Pad2置为低电平的宏定义
#define Pad2_DIR_IN P1DIR&=~BIT1 //将Pad2设置为输入状态的宏定义
#define Pad2_in (P1IN&BIT1) //读回Pad2电平的宏定义
unsigned char Pad1_BUFF[5];
int Pad_1= 0 ;
void TouchPad_Scan_Pad1()
{
int i,j,Count;
_BIC_SR(SCG0);
Pad1_OUT_L;
_NOP();
Count = 0;
Pad1_DIR_IN;
while (Pad1_in == 0)
Count ++;
Pad1_BUFF[0] = Pad1_BUFF[1];
Pad1_BUFF[1] = Pad1_BUFF[2];
Pad1_BUFF[2] = Pad1_BUFF[3];
Pad1_BUFF[3] = Pad1_BUFF[4];
Pad1_BUFF[4] = Count;
for (i=0;i<5;i++)
{
if (Pad1_BUFF<30)
break;
}
for (j=0;j<5;j++)
{
if (Pad1_BUFF[j]>=30)
break;
}
if (j == 4)
Pad_1 = 0;
else if (i == 4)
Pad_1 = 1;
}
int Get_Pad1()
{
return Pad_1;
}
__interrupt void BT_ISR(void)
{
int i;
for (i=0;i<800;i++);
TouchPad_Scan_Pad1();
__low_power_mode_off_on_exit();
}
这个是Touch.c的程序。
下面是主程序的主循环部分:
while(1)
{
delay_0(50);
if (Get_Pad1())
{
m++ ;
if (m == 0)
Disp1Char(12,0,'0');
if (m == 1)
Disp1Char(12,0,'1');
if (m == 2)
Disp1Char(12,0,'2');
if (m == 3)
Disp1Char(12,0,'3');
if (m == 4)
Disp1Char(12,0,'4');
if (m == 5)
Disp1Char(12,0,'5');
if (m == 6)
Disp1Char(12,0,'6');
Delay5ms();
}
else
Disp1Char(12,0,'8');
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>