標題: K60 smartcar最終代碼 學習資料 [打印本頁]

作者: XIONG111    時間: 2018-5-22 09:57
標題: K60 smartcar最終代碼 學習資料
單片機源程序如下:
  1. void  main(void)
  2. {
  3.     u16 count;

  4.     DisableInterrupts;                                      //禁止總中斷

  5.     FTM_PWM_init(FTM1, CH0, 100, 50);                       //FTM模塊產生PWM,用 FTM1_CH0 ,即 PTA8 ,頻率為 100

  6.     lptmr_counter_init(LPT0_ALT2, INT_COUNT, 2, LPT_Rising); //初始化脈沖計數器,用LPT0_ALT2,即PTC5輸入,每隔INT_COUNT產生中斷,延時2個時鐘濾波,上升沿觸發(fā)

  7.     EnableInterrupts;                                       //開總中斷

  8.     while(1)
  9.     {
  10.         if( LPT_INT_count > 0 )
  11.         {
  12.             count           =   LPTMR0_CNR;                         //保存脈沖計數器計算值
  13.             lptmr_counter_clean();                                  //清空脈沖計數器計算值(馬上清空,這樣才能保證計數值準確)
  14.             printf("LPT產生一次中斷啦:%d\n", LPT_INT_count * INT_COUNT +  count); //打印計數值
  15.             LPT_INT_count   =   0;                                  //清空LPT中斷次數
  16.         }
  17.     }
  18. }


  19. void  LPT_Handler(void)
  20. {
  21.     LPTMR0_CSR |= LPTMR_CSR_TCF_MASK;   //清除LPTMR比較標志
  22.     LPT_INT_count++;                    //中斷溢出加1
  23. }

  24. void PIT0_IRQHandler()
  25. {
  26.     pit_flag = 1;               //標記進入PIT中斷
  27.     PIT_Flag_Clear(PIT0);       //清中斷標志位
  28. }

  29. #undef      VECTOR_101
  30. #define     VECTOR_101  LPT_Handler

  31. #undef  VECTOR_084
  32. #define VECTOR_084    PIT0_IRQHandler     //重新定義84號中斷為PIT0_IRQHandler中斷

  33. extern  void  LPT_Handler(void);
  34. extern  void PIT0_IRQHandler(void);            //PIT0 定時中斷服務函數
復制代碼

所有資料51hei提供下載:
K60 smartcar最終代碼.rar (1.72 MB, 下載次數: 10)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1