两天了一点头绪也没有

2019-07-15 16:48发布

最初程序,采集AD值12864显示,传感器位于电机上。两个子程序同时放进while去只有采集好使,电机要么转一次要么干脆不动。(屏蔽Sample()电机可以转,根据采集有延时可以推断程序执行了Onclick()但电机却不动,不太确定问题是否出在这)。问题是电机不转AD采集不到数。该程序用51单片机做电机能转动又能采集数。
  1. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <msp430f5529.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <LCD12864.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <IIC.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <Display.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <Motor.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <PWM.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <Event.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <Key.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#define uint unsigned int</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#define uchar unsigned char</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">uint flag;</font></font></p>
  2. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">void main()</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">{</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT</font></font></p>
  3. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    PWMA_Init();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    Key_Init();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    Key_Scan();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    Motor_Init();</font></font></p>
  4. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    GPIO_Init();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">LCD12864_Init();</font></font></p>
  5. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">  while(1)</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体"> {</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">On_Click();//检测事件控制电机正反转</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">Sample();//采集AD值12864显示</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">      }</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">}</font></font></p>

  6. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">然后修改程序,把采集放入(看门狗,定时器)中断扫描16ms/250ms/1000ms,离谱的是程序一旦进入中断就是反复扫描sample(),不再进入while中,电机照样不转。</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <msp430f5529.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <LCD12864.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <IIC.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <Display.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <Motor.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <PWM.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <Event.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#include <Key.h></font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#define uint unsigned int</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#define uchar unsigned char</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">uint flag;</font></font></p>
  7. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">void WDT_Init()</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">{</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">  WDTCTL = WDT_ADLY_16;                    // WDT 16ms, ACLK, interval timer</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">// WDTCTL = WDT_MDLY_32;</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">  SFRIE1 |= WDTIE;                          // Enable WDT interrupt</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">//  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, enable interrupts</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">}</font></font></p>
  8. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">void main()</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">{</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT</font></font></p>
  9. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    PWMA_Init();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    Key_Init();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    Key_Scan();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    Motor_Init();</font></font></p>
  10. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    WDT_Init();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">    GPIO_Init();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">LCD12864_Init();</font></font></p>
  11. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">  while(1)</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体"> {</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">_EINT();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">On_Click();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">      }</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">}</font></font></p>
  12. <p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">// Watchdog Timer interrupt service routine</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">#pragma vector = WDT_VECTOR</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">__interrupt void WDT_ISR(void)</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">{</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">SFRIFG1 &=~ WDTIFG;</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">Sample();</font></font></p><p style="line-height: 18px; text-indent: nullem; text-align: left;"><font color="rgb(0, 0, 0)"><font face="Arial, 宋体">}</font></font></p>
复制代码
求大戏不吝赐教。

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。