This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430F447:msp430f447

Guru**** 2027820 points
Other Parts Discussed in Thread: MSP430F447
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/588518/msp430f447-msp430f447

器件型号:MSP430F447

你(们)好

我已使用端口引脚来启用电机、并使用直通光束传感器来停止电机  

问题在于以下代码首次正常运行第二次电机停止运转时不会从 while 中退出  

代码是  

#include "io430.h"// msp430f447评估板的标头
#include // C 函数的标头

静态 int counter1=0;
静态 int counter2=0;
空延迟(int j);//延迟函数
void Delay1 (int k);//延迟函数
void Delay2 (int k);//延迟函数
void Reset_all ();//全部重置
void Timer_on ();//计时器打开函数
int filling 完成= 0;
int indexing_done = 0;
int RESET_TIME=0;
静态 int NRV_OPERATING = 0;
void main()//Main 函数




WDTCTL = WDTPW + WDTHOLD;//停止看门狗计时器
RESET_ALL ();
P1DIR |=0x7F;// P1.0、P1.1所有输出
P1OUT &=0x00;//清除 P1.0、P1.1
/*---------- 定时器模块--- *
CCR0 = 32768;
TACTL = tassel_1 + MC_2 +ID_0+TACLR;// ACLK、contmode、timerclear

P1OUT |= 0x08;//P1.3=1 NRV 电机旋转
while ((((P2IN & BIT0)=BIT0)||((P3IN & BIT7)!=BIT7));//wait P3.7==0;
P1OUT &= 0x00;// P1.0 = 0、P1.1 = 0、P1.2 = 0、P1.3 = 0
while (1)


if ((P6IN & BIT6)!= BIT6)//open/close 按钮

while (1)

/* if (RESET_TIME=1)
{//开始休息
Delay2 (200);
}*/
//进程开始
for (int operation_count=0;operation_count<200;++operation_count)

if (operation_count % 2 = 0 && operation_count!= 0)
Delay2 (100);
if (operation_count > 0)
Delay1(60);
///*--------------- 索引--- *
P1OUT |= 0x01;//P1.1=1 NRV 电机旋转
延迟(7);
while ((P2IN & BIT7)!= BIT7);
P1OUT &= 0x00;// P1.0 = 0、P1.1 = 0、P1.2 = 0、P1.3 = 0


/*------------------ NRV 操作--- *
NRV_OPERATING = 1;
P1OUT = 0x08;//P1.3=1 NRV 电机旋转
// while (((P2IN & BIT0)!= BIT0)||((P3IN & BIT7)== BIT7);//等待 P3.7==1;
Delay1(4);
while (((P3IN & BIT7)=BIT7);

延迟(4);
P1OUT &= 0x00;// P1.0 = 0、P1.1 = 0、P1.2 = 0、P1.3 = 0
timer_on ();
while (filling _done = 0);
Filling _DONE = 0;
TACTL = MC_0;
CCR0 = 32768;
TACTL = tassel_1 + MC_2 +ID_0+TACLR;// ACLK、contmode、timerclear */

}//完成的周期集
/* Filling 完成= 0;
CCR0 = 32768;
TACTL = tassel_1 + MC_2 +ID_0+TACLR;// ACLK、contmode、timerclear*/
//重新初始化 syztem
Filling _DONE = 0;
索引完成= 0;
P1DIR |=0x7F;// P1.0、P1.1所有输出
P1OUT &=0x00;//清除 P1.0、P1.1
CCR0 = 32768;
TACTL = tassel_1 + MC_2 +ID_0+TACLR;// ACLK、contmode、timerclear
//启动休眠变量并继续
RESET_TIME=1;




}//End of Main

空延迟(int j)

int i;
for (j=0;j<1;j++)
for (i=0;i<0xFFFF;i++);

空 Delay1 (int j)

int i;
for (j=0;j<10;j++)
for (i=0;i<0xFFFF;i++);

//非常长的延迟
空 Delay2 (int j)

int i、m;
for (m=0;<j;m++)
for (i=0;i<0xFFFF;i++);

void Timer_on ()//计时器开启函数

CCTL0 = CCIE;
_bis_SR_register (LPM0_bits + GIE);//通过中断输入 LPM0

#pragma vector=TIMERA0_vector
_interrupt void Timer_A (void)

//一秒计数器变量
CCR0 += 32768;
如果(++counter1>=10)//10秒(对于 NRV)

如果(NRV_OPERATING = 1)

P1OUT |= 0x08;//P1.3=1 NRV 电机旋转
while ((((P2IN & BIT0)=BIT0)||((P3IN & BIT7)!=BIT7));//wait P3.7==0;
P1OUT &= 0x00;// P1.0 = 0、P1.1 = 0、P1.2 = 0、P1.3 = 0
计数器1=0;
Filling _done = 1;
NRV_OPERATING = 0;


/*if (++counter2>=5)//5秒用于索引

P1OUT &= 0x00;// P1.0 = 0、P1.1 = 0、P1.2 = 0、P1.3 = 0
计数器2=0;
索引完成= 1;
}*/
_BIC_SR_REGISTER_ON_EXIT (CPUOFF);//从0 (SR)清除 CPUOFF 位

/*-------------------- 重置--- *

void Reset_All()

P1OUT=0x00;
P2OUT=0x00;
P3OUT=0x00;
P4OUT=0x00;
P5OUT=0x00;
P6OUT=0x00;

第二次来了,它不工作了  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    一旦通过 if ((P6IN & BIT6)!= BIT6)、您就永远不会因为嵌入式 while (1)循环而离开。 该 while (1)应被删除、这样您只需循环 main 即可。 如果这不是您的问题、则需要提供更多信息和调试工作、以帮助隔离问题。

    此致、
    Ryan
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Brown、您好、感谢您的回复

    #include "io430.h"// msp430f447评估板的标头
    #include // C 函数的标头

    静态 int counter1=0;
    静态 int counter2=0;
    空延迟(int j);//延迟函数
    void Delay1 (int k);//延迟函数
    void Delay2 (int k);//延迟函数
    void Reset_all ();//全部重置
    void Timer_on ();//计时器打开函数
    int filling 完成= 0;
    int indexing_done = 0;
    int RESET_TIME=0;
    静态 int NRV_OPERATING = 0;
    void main()//Main 函数




    WDTCTL = WDTPW + WDTHOLD;//停止看门狗计时器
    RESET_ALL ();
    P1DIR |=0x7F;// P1.0、P1.1所有输出
    P1OUT &=0x00;//清除 P1.0、P1.1
    /*---------- 定时器模块--- *
    CCR0 = 32768;
    TACTL = tassel_1 + MC_2 +ID_0+TACLR;// ACLK、contmode、timerclear

    P1OUT |= 0x08;//P1.3=1 NRV 电机旋转
    while ((((P2IN & BIT0)=BIT0)||((P3IN & BIT7)!=BIT7));//wait P3.7==0;
    P1OUT &= 0x00;// P1.0 = 0、P1.1 = 0、P1.2 = 0、P1.3 = 0





    //需要无限循环,但问题是第一次执行它,第二次停止它//此行"while ((P3IN & BIT7)== BIT7);"


    while (1)

    if ((P6IN & BIT6)!= BIT6)//open/close 按钮

    while (1)


    //进程开始
    for (int operation_count=0;operation_count<200;++operation_count)

    if (operation_count % 2 = 0 && operation_count!= 0)
    Delay2 (100);
    if (operation_count > 0)
    Delay1(60);
    ///*--------------- 索引--- *
    P1OUT |= 0x01;//P1.1=1 NRV 电机旋转
    延迟(7);
    while ((P2IN & BIT7)!= BIT7);
    P1OUT &= 0x00;// P1.0 = 0、P1.1 = 0、P1.2 = 0、P1.3 = 0


    /*------------------ NRV 操作--- *
    NRV_OPERATING = 1;
    P1OUT = 0x08;//P1.3=1 NRV 电机旋转


    while (((P3IN & BIT7)=BIT7);

    延迟(4);
    P1OUT &= 0x00;// P1.0 = 0、P1.1 = 0、P1.2 = 0、P1.3 = 0
    timer_on ();
    while (filling _done = 0);
    Filling _DONE = 0;
    TACTL = MC_0;
    CCR0 = 32768;
    TACTL = tassel_1 + MC_2 +ID_0+TACLR;// ACLK、contmode、timerclear */

    }//完成的周期集

    //重新初始化 syztem
    Filling _DONE = 0;
    索引完成= 0;
    P1DIR |=0x7F;// P1.0、P1.1所有输出
    P1OUT &=0x00;//清除 P1.0、P1.1
    CCR0 = 32768;
    TACTL = tassel_1 + MC_2 +ID_0+TACLR;// ACLK、contmode、timerclear
    //启动休眠变量并继续
    RESET_TIME=1;




    }//End of Main

    /*---------- 延迟------------------------------- *
    空延迟(int j)

    int i;
    for (j=0;j<1;j++)
    for (i=0;i<0xFFFF;i++);

    空 Delay1 (int j)

    int i;
    for (j=0;j<10;j++)
    for (i=0;i<0xFFFF;i++);

    //非常长的延迟
    空 Delay2 (int j)

    int i、m;
    for (m=0;<j;m++)
    for (i=0;i<0xFFFF;i++);

    void Timer_on ()//计时器开启函数

    CCTL0 = CCIE;
    _bis_SR_register (LPM0_bits + GIE);//通过中断输入 LPM0


    #pragma vector=TIMERA0_vector
    _interrupt void Timer_A (void)

    //一秒计数器变量
    CCR0 += 32768;
    如果(++counter1>=10)//10秒(对于 NRV)

    如果(NRV_OPERATING = 1)

    P1OUT |= 0x08;//P1.3=1 NRV 电机旋转
    while ((((P2IN & BIT0)=BIT0)||((P3IN & BIT7)!=BIT7));//wait P3.7==0;
    P1OUT &= 0x00;// P1.0 = 0、P1.1 = 0、P1.2 = 0、P1.3 = 0
    计数器1=0;
    Filling _done = 1;
    NRV_OPERATING = 0;


    _BIC_SR_REGISTER_ON_EXIT (CPUOFF);//从0 (SR)清除 CPUOFF 位


    /*-------------------- 重置--- *

    void Reset_All()

    P1OUT=0x00;
    P2OUT=0x00;
    P3OUT=0x00;
    P4OUT=0x00;
    P5OUT=0x00;
    P6OUT=0x00;

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    如果 P3.7继续处于高电平状态(没有硬件将其拉低、并且内部下拉电阻器未启用)、则此语句将保持为真、永远不会退出 while 环路。

    此致、
    Ryan