欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: C8051F410單片機利用pca捕獲外部脈沖 [打印本頁]

作者: y電子設計dsd    時間: 2019-7-31 14:16
標題: C8051F410單片機利用pca捕獲外部脈沖
//-----------------------------------------------------------------------------
// 聲明:外部引腳的脈沖輸入CEX0為P0^0,
//-----------------------------------------------------------------------------

#include <c8051f410.h>                 // SFR declarations
#include"UART.h"
#include <stdio.h>

#define SYSCLK      24500000           // SYSCLK frequency in Hz
#define BAUDRATE        9600           // Baud rate of UART in bps

sfr16 PCA0CP0 = 0xFB;                  // PCA0 Compare Register Definition
unsigned int CLKNUM = 0;
float period;

void OSCILLATOR_Init (void);
void PORT_Init (void);
void PCA0_Init (void);
static unsigned int capture_period;
unsigned int counter;
void main (void)
{
   PCA0MD = 0x00;                      // Disable watchdog timer

   PORT_Init ();                       // Initialize crossbar and GPIO
   OSCILLATOR_Init ();                 // Initialize oscillator
   PCA0_Init ();                       // Initialize PCA0
   UART0_Init ();

   EA = 1;

   while (1)
   {
      printf("CLKNUM= %d us\n",CLKNUM);
         printf("period= %f us\n",period);
   }
}


void OSCILLATOR_Init (void)
{
   OSCICN = 0x87;                      // Set internal oscillator to run
                                       // at its maximum frequency

   CLKSEL = 0x00;                      // Select the internal osc. as
                                       // the SYSCLK source
     RSTSRC = 0x04;                      // enable missing clock detector(串口需要)
}

void PORT_Init (void)
{
   XBR0    = 0x01;                     //串口通信使能
   XBR1    = 0x41;                     // Route CEX0 to P0.0,
                                       // Enable crossbar and weak pull-ups
}

void PCA0_Init (void)
{
   PCA0CN = 0x00;                      // Stop counter; clear all flags
   PCA0MD = 0x08;                      // Use 系統時鐘 as time base
   PCA0CPM0 = 0x21;                    // Module 0 = Rising Edge Capture Mode
                                       // enable CCF flag.
   EIE1 = 0x10;                       // Enable PCA interrupts  
   CR = 1;                             // Start PCA counter
}
void PCA0_ISR (void) interrupt 11
{
   static unsigned int current_capture_value, previous_capture_value;

   if (CCF0)                                                                         // If Module 0 caused the interrupt
   {
//          CLKNUM++;
         
      CCF0 = 0;                                                                      // Clear module 0 interrupt flag.   
      current_capture_value = PCA0CP0;                                               // Store most recent capture value     
      capture_period = current_capture_value - previous_capture_value;               // Calculate capture period from last two values.
      previous_capture_value = current_capture_value;                                // Update previous capture value with most recent info.
            period = capture_period *4.0816326530612244897959183673469e-8;
         
         
         
         
     }
   else                                // Interrupt was caused by other bits.
   {
      PCA0CN &= ~0x86;                 // Clear other interrupt flags for PCA
   }
}

作者: lyl_420819    時間: 2019-11-16 17:01
好資料,學習了,謝謝分享。




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