標(biāo)題: K60 smartcar最終代碼 學(xué)習(xí)資料 [打印本頁(yè)]

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

  4.     DisableInterrupts;                                      //禁止總中斷

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

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

  7.     EnableInterrupts;                                       //開(kāi)總中斷

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


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

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

  29. #undef      VECTOR_101
  30. #define     VECTOR_101  LPT_Handler

  31. #undef  VECTOR_084
  32. #define VECTOR_084    PIT0_IRQHandler     //重新定義84號(hào)中斷為PIT0_IRQHandler中斷

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

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







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