找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4412|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

飛思卡爾三輪程序+實物圖

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:648562 發(fā)表于 2019-11-26 22:11 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
給大家分享一個飛思卡爾三輪的程序自己大學(xué)親自做的
車模可以選擇飛思卡爾要求的車模
下邊就靠自己 調(diào)PID了


單片機源程序如下:
  1. /*********************************************************************************************************************
  2. *
  3. * @file                       isr.c
  4. *                                  中斷服務(wù)函數(shù)
  5. * @core                        S9KEA128
  6. * @date                       2018
  7. ********************************************************************************************************************/
  8. #include "includefile.h"


  9. /****************全局變量定義******************/
  10. uint8 Flag_Stop = OFF;                        //=OFF停車
  11. uint8 Flag_Speed = ON;                        //=ON增加速度控制
  12. uint8 Flag_Direction = ON;                //=ON增加方向控制
  13. uint8 Flag_Debuge = OFF;                //=ON進入調(diào)參界面
  14. uint8 Flag_Out = 2;                                //虛擬示波器顯示標(biāo)志


  15. void PIT_CH0_IRQHandler(void)
  16. {
  17.     PIT_FLAG_CLR(PIT0);
  18.    
  19.         //標(biāo)志變量定義
  20.         static uint16 i = 0;
  21.         static uint16 j = 0;
  22.        
  23.         //0.5sLED閃爍
  24.         i++;
  25.         if(i >= 100)  
  26.     {   
  27.             i = 0;
  28.             gpio_turn(LED);
  29.         }
  30.         //20ms一次速度控制
  31.         j++;
  32.         if(j >= 4)  
  33.     {   
  34.             j = 0;
  35.                 SpeedControl();
  36.         }       
  37.         DirectionControl();        //方向控制
  38.         PWMOut();                        //最終PWM輸出
  39.        
  40.         //以下為虛擬示波器部分
  41.         switch(Flag_Out)
  42.         {               
  43.                 case 0 :         OutData[0] = (int)g_fRealSpeed;                //真實速度
  44.                                           OutData[1] = (int)g_fSpeedError;        //速度偏差
  45.                                         OutData[2] = (int)g_fSpeedFilter;        //速度濾波
  46.                                         OutData[3] = (int)g_fExpectSpeed;        //期望速度
  47.                                         break;
  48.                                        
  49.                 case 1 :        OutData[0] = (int)g_ValueOfAD[0];        //水平左電感
  50.                                           OutData[1] = (int)g_ValueOfAD[1];        //水平右電感
  51.                                         OutData[2] = (int)(1000*g_fDirectionError[0]);                //方向偏差          (放大1000倍)
  52.                                         OutData[3] = (int)(1000*g_fDirectionError_dot[0]);        //方向偏差微分(放大1000倍)
  53.                                         break;
  54.                                        
  55.                 case 2 :        OutData[0] = (int)g_ValueOfAD[0];//水平左電感
  56.                                           OutData[1] = (int)g_ValueOfAD[1];//垂直右電感
  57.                                         OutData[2] = (int)g_ValueOfAD[2];//水平左電感
  58.                                         OutData[3] = (int)g_ValueOfAD[3];//垂直右電感
  59.                                         break;       
  60.                                        
  61.                 case 3 :        OutData[0] = (int)g_fSpeedControlOut;                //速度控制輸出        (紅)
  62.                                           OutData[1] = (int)g_fDirectionControlOut;        //方向輸出                (黃)
  63.                                         OutData[2] = (int)g_PWMOut;                                        //總PWM                        (藍)
  64.                                         OutData[3] = 0;
  65.                                         break;
  66.                 default :break;
  67.         }
  68.         OutPut_Data();
  69. }


  70. void PIT_CH1_IRQHandler(void)
  71. {
  72.     PIT_FLAG_CLR(PIT1);
  73.    
  74. }

  75. void IRQ_IRQHandler(void)
  76. {  
  77.     CLEAR_IRQ_FLAG;
  78.     gpio_set(BUZZ,1);                //蜂鳴器開
  79.     ir_decode();                        //紅外解碼和處理   
  80.     gpio_set(BUZZ,0);                 //蜂鳴器關(guān)
  81. }

  82. void KBI0_IRQHandler(void)
  83. {
  84.     CLEAN_KBI0_FLAG;

  85. }

  86. /*
  87. 記得進入中斷后清除標(biāo)志位
  88. FTMRE_IRQHandler      
  89. PMC_IRQHandler        
  90. IRQ_IRQHandler        
  91. I2C0_IRQHandler      
  92. I2C1_IRQHandler      
  93. SPI0_IRQHandler      
  94. SPI1_IRQHandler      
  95. UART0_IRQHandler
  96. UART1_IRQHandler
  97. UART2_IRQHandler
  98. ADC0_IRQHandler      
  99. ACMP0_IRQHandler      
  100. FTM0_IRQHandler      
  101. FTM1_IRQHandler      
  102. FTM2_IRQHandler      
  103. RTC_IRQHandler        
  104. ACMP1_IRQHandler      
  105. PIT_CH0_IRQHandler   
  106. PIT_CH1_IRQHandler   
  107. KBI0_IRQHandler      
  108. KBI1_IRQHandler      
  109. Reserved26_IRQHandler
  110. ICS_IRQHandler        
  111. WDG_IRQHandler        
  112. PWT_IRQHandler        
  113. MSCAN_Rx_IRQHandler   
  114. MSCAN_Tx_IRQHandler   
  115. */
復(fù)制代碼
  1. /*********************************************************************************************************************
  2. *
  3. * @file                       main.c
  4. *                                  主函數(shù)
  5. * @core                        S9KEA128
  6. * @date                       2018
  7. ********************************************************************************************************************/

  8. #include "includefile.h"
  9.    
  10. int main(void)
  11. {
  12.     get_clk();              //獲取時鐘頻率
  13.     DisableInterrupts;

  14.     car_init();
  15. //        param_in();             //讀取參數(shù)
  16.     EnableInterrupts;
  17.     while(1)
  18.     {
  19.                 oled_print_16x8short(0 ,0,g_ValueOfAD[0]);//顯示水平左電感
  20.                 oled_print_16x8short(80,0,g_ValueOfAD[1]);//顯示水平右電感
  21.                
  22.                 oled_print_16x8short(10,3,g_ValueOfAD[2]);//顯示垂直左電感
  23.                 oled_print_16x8short(70,3,g_ValueOfAD[3]);//顯示垂直右電感
  24.     }
  25. }
復(fù)制代碼

所有資料51hei提供下載:
第十三屆電磁組程序 - 無調(diào)參系統(tǒng)版.7z (744.73 KB, 下載次數(shù): 35)

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:243684 發(fā)表于 2020-8-5 13:32 來自手機 | 只看該作者
你好樓主,我用iar下載,無法下載到單片機內(nèi)是什么原因呀,其他的程序能成功燒錄
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表