求助,写了一个小程序,怎么才能跳出中断啊,求各位大佬解惑!
#include <reg52.h>
void GPIO_Init();
void P1_IODect();
void P2_IODect();
void TURN_Left();
void TURN_Right();
void TIMER_A0_1();
void TIMER_A1_1();
int main(void) {
WDTCTL = WDTPW | WDTHOLD;
GPIO_Init();
TIMER_A0_1();
TIMER_A1_1();
_enable_interrupts();
}
void GPIO_Init(){
P1DIR |= BIT0+BIT1;
P1OUT |= BIT1;
P1OUT &= ~BIT0;
P1SEL |= BIT6;
P1DIR |= BIT6;
P2DIR |= BIT0+BIT1;
P2OUT |= BIT1;
P2OUT &= ~BIT0;
P2SEL |= BIT2;
P2DIR |= BIT2;
P1REN |= BIT3;
P1OUT |= BIT3;
P1DIR &=~ BIT3;
P1IES |= BIT3;
P1IE |= BIT3;
P2REN |= BIT3;
P2OUT |= BIT3;
P2DIR &=~ BIT3;
P2IES |= BIT3;
P2IE |= BIT3;
}
void TIMER_A0_1(){
TA0CTL=0; //清除以前的设置
TA0CTL |= TASSEL_1+MC_1; //使用子系统时钟,帧计数模式,不倍频
TA0CTL|=ID_0; //使用子系统时钟,帧计数模式,不倍频
TA0CCTL1 = OUTMOD_7;
TA0CCR0 = 1000; //时钟频率为32768HZ,100HZ
TA0CCR1 = 400; //占空比CCR1/CCR0=1/3
TA0CTL |= TACLR;
}
void TIMER_A1_1(){
TA1CTL=0; //清除以前的设置
TA1CTL |= TASSEL_1+MC_1; //使用子系统时钟,帧计数模式,不倍频
TA1CTL|=ID_0; //使用子系统时钟,帧计数模式,不倍频
TA1CCTL1 = OUTMOD_7;
TA1CCR0 = 1000; //时钟频率为32768HZ,100HZ
TA1CCR1 = 400; //占空比CCR1/CCR0=1/3
TA1CTL |= TACLR;
}
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1_IODect();
P1IFG=0;
}
void P1_IODect()
{
unsigned int Push_Key=0;
Push_Key=P1IFG&(~P1DIR);
if((P1IN&Push_Key)==0)
{
switch(Push_Key){
case BIT3:
TURN_Right();
P1IN ^= BIT3;
break;
default: break;
}
}
}
#pragma vector = PORT2_VECTOR
__interrupt void PORT2_ISR(void)
{
P2_IODect();
P2IFG=0;
}
void P2_IODect()
{
unsigned int Push_Key=0;
Push_Key=P2IFG&(~P2DIR);
if((P2IN&Push_Key)==0)
{
switch(Push_Key){
case BIT3: TURN_Left();
P2IN ^=BIT3;
break;
default: break;
}
}
}
void TURN_Left(){
unsigned int MILL1=400;
unsigned int MILL2=400;
while((P2IN&0x04)==0){
MILL1=MILL1+40;
MILL2=MILL2-40;
TA0CCR1=MILL1;
TA1CCR1=MILL2;
}
}
void TURN_Right(){
unsigned int MILL1=400;
unsigned int MILL2=400;
MILL1=MILL1-40;
MILL2=MILL2+40;
while((P1IN&0x04)==0){
MILL1=MILL1-40;
MILL2=MILL2+40;
TA0CCR1=MILL1;
TA1CCR1=MILL2;
}
} |