|
当把线连好后,输出来的波形全是杂波
#include
#define keyin (P1IN & 0x08)// PIN 为输入寄存器
void Clock_Init(void)
{
BCSCTL1 &=~ XT2OFF;//(XT2高速晶振关)设置为低频状态
while(IFG1 & OFIFG)
{
IFG1 &=~OFIFG; // 清 OSC中断标志位
__delay_cycles(3000);
}
}
int Keyscan(void)
{
unsigned int flag =0;
while(1)
{
if(keyin != 0x08)//表明键按下
{
__delay_cycles(3000);
if(keyin != 0x08)
{
while(keyin !=0x08);//等待按键释放
flag++;
P1OUT ^= BIT6;
}
}
return flag;
}
}
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
Clock_Init();
TACTL = TASSEL0 + TACLR + MC_1;//ACLK , 增计数
// P1IE |= BIT3;//允许中断
//P1IES |= BIT3;//上升沿触发
//P1IFG = 0X00; //中断标志
CCTL0 = OUTMOD_4;//翻转模式
CCR0 = 512-1;
CCTL1 = OUTMOD_7;//PWM复位/置位
CCR1 = 32;
P1SEL = 0X06; //0000 0110 P1.1对应 CCR0的TA0;
P1DIR = 0X06; // P1.2对应 CCR1的TA1
P1REN |= BIT3;//这个必须要加上 !!上拉电阻
P1DIR |= BIT6;
while(1)
{
if(Keyscan() != 0)
{
if(CCR1 >448) CCR1=32;
else CCR1+=32;
}
}
}
|
|