日本高清不卡中文字幕-一起草草视频在线观看-亚洲精品一区二区三区色-国产亚洲精品免费视频

您好,歡迎進(jìn)入深圳市穎特新科技有限公司官方網(wǎng)站!

您現(xiàn)在的位置:首頁 新聞資訊 >> 新聞?lì)^條 >> 定時(shí)器2及輸入捕獲
新聞資訊
NEWS INFORMATION

定時(shí)器2及輸入捕獲

發(fā)布時(shí)間:2019-05-22

關(guān)于捕獲

1、外部波形周期
得到兩個(gè)相鄰波形上升沿或下降沿的時(shí)間T1,T2,
       "T2 - T1"的值就是周期
 
2、脈沖周期
記錄相鄰的兩個(gè)不同極性的沿變化時(shí)間T1,T2
   "T2 - T1"的值就是周期
 
PS:兩次輸入捕獲之間若存在著定時(shí)器溢出中斷,則需要考慮溢出中斷的次數(shù),而不能夠直接將T2-T1當(dāng)作周期,還需考慮定時(shí)器溢出中斷的周期。
 

定時(shí)器2是一個(gè)16位的向上計(jì)數(shù)器,由高8位寄存器(TH2)和低8位寄存器(TL2)組成。通過配置寄存器RCMP2H和RCMP2L,設(shè)置 (T2CON.0)后,定時(shí)器2能工作在比較模式和自動重載模式下。

定時(shí)器2具有3通道輸入捕獲模塊,可用于測量輸入脈沖寬度或周期。3通道捕獲結(jié)果分別存放在寄存器C0H 及 C0L, C1H 及 C1L, C2H及 C2L中。定時(shí)器2的時(shí)鐘來自系統(tǒng)時(shí)鐘的分頻,總共具有8級分頻,可適用于更多應(yīng)用需求。當(dāng)TR2(T2CON.2) 置 1,定時(shí)器使能;TR2置0時(shí),定時(shí)器關(guān)閉。下列寄存器用于控制定時(shí)器2功能。

自動重裝載功能模式

 當(dāng) 清0,定時(shí)器2配置為自動重裝載模式。在該模式下,RCMP2H 及 RCMP2L保存重裝載的數(shù)值。當(dāng)LDEN置位后,一旦有觸發(fā)事件發(fā)生,硬件將自動把 RCMP2H 及 RCMP2L 寄存器內(nèi)的值寫入TH2 及 TL2 中。觸發(fā)事件可以是定時(shí)器2溢出或是一個(gè)所配置的捕獲信道有觸發(fā)事件發(fā)生(根據(jù)LDTS[1:0] (T2MOD[1:0])配置)。注意,一旦CAPCR (T2MOD.3) 置1,如有一個(gè)捕獲事件發(fā)生,僅清除TH2及 TL2 內(nèi)的值,不會將 RCMP2H 及 RCMP2L的值載入。

比較功能模式
當(dāng) 置1,定時(shí)器2配置為比較器模式。在該模式下,RCMP2H 及 RCMP2L 預(yù)存待比較數(shù)據(jù)。由于定時(shí)器2向上計(jì)數(shù),一旦TH2 和 TL2 匹配RCMP2H 和 RCMP2L的設(shè)定值,TF2 (T2CON.7) 將會由硬件置1,用以標(biāo)示發(fā)生了比較匹配事件。

如果 CMPCR (T2MOD.2) 置1,當(dāng)發(fā)生比較匹配事件后,定時(shí)器2 計(jì)數(shù)器將硬件自動清0。

 

 輸入捕獲功能模塊

輸入捕獲模塊依靠定時(shí)器2實(shí)現(xiàn)輸入捕獲功能。輸入捕獲模塊通過寄存器CAPCON0~2配置來支持3組信道輸入(CAP0,CAP1和CAP2),可選擇配置9個(gè)引腳(P1.5,P1[2:0],P0.0,P0.1和P0[5:3])。引腳復(fù)合功能選擇通過CAPCON3和CAPCON4配置。每個(gè)輸入通道的噪聲濾波器可通過設(shè)置ENF0~2 (CAPCON2[6:4])使能,可濾除小于4個(gè)系統(tǒng)時(shí)鐘的輸入毛刺。每組輸入捕獲通道共享定時(shí)器2計(jì)數(shù),但有自己獨(dú)立的邊沿檢測。每個(gè)觸發(fā)邊沿檢測可由寄存器CAPCON1的相關(guān)位獨(dú)立配置,支持正邊沿捕獲,負(fù)邊沿捕獲,或雙邊沿捕獲。在使用前,必須設(shè)置通道使能位CAPEN0~2 (CAPCON0[6:4])。

當(dāng)輸入捕獲通道使能且所選擇的邊沿觸發(fā)發(fā)生時(shí),定時(shí)器2的計(jì)數(shù)值TH2和TL2將被捕獲、傳輸并存儲到捕獲寄存器CnH 和 CnL。邊沿觸發(fā)也可硬件置位CAPFn (CAPCON0.n),如果ECAP (EIE.2)和EA都打開,將產(chǎn)生中斷。三組輸入捕獲共享一個(gè)中斷向量, 用戶可通過檢查CAPFn來確定具體哪個(gè)通道有輸入捕獲。這些標(biāo)志必須由軟件清零。

CAPCR (CAPCON2.3)用于周期計(jì)算。當(dāng)設(shè)置CAPCR為1,一個(gè)捕獲邊沿事件發(fā)生后,TH2和TL2的值將被保存,然后硬件將自動清除定時(shí)器2的值為0000H。這樣可以避免常規(guī)軟件寫16位計(jì)數(shù)或者算法開銷。

 

#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_define.h"

//*****************  The Following is in define in Fucntion_define.h  ***************************
//****** Always include Function_define.h call the define you want, detail see main(void) *******
//***********************************************************************************************
#if 0

////-------------------- Timer2 Capture define --------------------
////--- Falling Edge -----
//#define IC0_P12_CAP0_FallingEdge_Capture        CAPCON1&=0xFC;CAPCON3&=0xF0;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC1_P11_CAP0_FallingEdge_Capture        CAPCON1&=0xFC;CAPCON3&=0xF0;CAPCON3|=0x01;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC2_P10_CAP0_FallingEdge_Capture        CAPCON1&=0xFC;CAPCON3&=0xF0;CAPCON3|=0x02;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC3_P00_CAP0_FallingEdge_Capture        CAPCON1&=0xFC;CAPCON3&=0xF0;CAPCON3|=0x03;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC3_P04_CAP0_FallingEdge_Capture        CAPCON1&=0xFC;CAPCON3&=0xF0;CAPCON3|=0x04;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC4_P01_CAP0_FallingEdge_Capture        CAPCON1&=0xFC;CAPCON3&=0xF0;CAPCON3|=0x05;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC5_P03_CAP0_FallingEdge_Capture        CAPCON1&=0xFC;CAPCON3&=0xF0;CAPCON3|=0x06;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC6_P05_CAP0_FallingEdge_Capture        CAPCON1&=0xFC;CAPCON3&=0xF0;CAPCON3|=0x07;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC7_P15_CAP0_FallingEdge_Capture        CAPCON1&=0xFC;CAPCON3&=0xF0;CAPCON3|=0x08;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4

//#define IC0_P12_CAP1_FallingEdge_Capture        CAPCON1&=0xF3;CAPCON3&=0x0F;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5
//#define    IC1_P11_CAP1_FallingEdge_Capture        CAPCON1&=0xF3;CAPCON3&=0x0F;CAPCON3|=0x10;CAPCON0|=SET_BIT5;CAPCON0|=SET_BIT5
//#define    IC2_P10_CAP1_FallingEdge_Capture        CAPCON1&=0xF3;CAPCON3&=0x0F;CAPCON3|=0x20;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5
//#define    IC3_P00_CAP1_FallingEdge_Capture        CAPCON1&=0xF3;CAPCON3&=0x0F;CAPCON3|=0x30;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5
//#define    IC3_P04_CAP1_FallingEdge_Capture        CAPCON1&=0xF3;CAPCON3&=0x0F;CAPCON3|=0x40;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5
//#define    IC4_P01_CAP1_FallingEdge_Capture        CAPCON1&=0xF3;CAPCON3&=0x0F;CAPCON3|=0x50;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5
//#define    IC5_P03_CAP1_FallingEdge_Capture        CAPCON1&=0xF3;CAPCON3&=0x0F;CAPCON3|=0x60;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5
//#define    IC6_P05_CAP1_FallingEdge_Capture        CAPCON1&=0xF3;CAPCON3&=0x0F;CAPCON3|=0x70;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5
//#define    IC7_P15_CAP1_FallingEdge_Capture        CAPCON1&=0xF3;CAPCON3&=0x0F;CAPCON3|=0x80;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5

//#define IC0_P12_CAP2_FallingEdge_Capture        CAPCON1&=0x0F;CAPCON4&=0xF0;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6
//#define    IC1_P11_CAP2_FallingEdge_Capture        CAPCON1&=0x0F;CAPCON4&=0xF0;CAPCON4|=0x10;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6
//#define    IC2_P10_CAP2_FallingEdge_Capture        CAPCON1&=0x0F;CAPCON4&=0xF0;CAPCON4|=0x20;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6
//#define    IC3_P00_CAP2_FallingEdge_Capture        CAPCON1&=0x0F;CAPCON4&=0xF0;CAPCON4|=0x30;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6
//#define    IC3_P04_CAP2_FallingEdge_Capture        CAPCON1&=0x0F;CAPCON4&=0xF0;CAPCON4|=0x40;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6
//#define    IC4_P01_CAP2_FallingEdge_Capture        CAPCON1&=0x0F;CAPCON4&=0xF0;CAPCON4|=0x50;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6
//#define    IC5_P03_CAP2_FallingEdge_Capture        CAPCON1&=0x0F;CAPCON4&=0xF0;CAPCON4|=0x60;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6
//#define    IC6_P05_CAP2_FallingEdge_Capture        CAPCON1&=0x0F;CAPCON4&=0xF0;CAPCON4|=0x70;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6
//#define    IC7_P15_CAP2_FallingEdge_Capture        CAPCON1&=0x0F;CAPCON4&=0xF0;CAPCON4|=0x80;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6

////----- Rising edge ----
//#define IC0_P12_CAP0_RisingEdge_Capture            CAPCON1&=0xFC;CAPCON1|=0x01;CAPCON3&=0xF0CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4;
//#define    IC1_P11_CAP0_RisingEdge_Capture            CAPCON1&=0xFC;CAPCON1|=0x01;CAPCON3&=0xF0;CAPCON3|=0x01;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4;
//#define    IC2_P10_CAP0_RisingEdge_Capture            CAPCON1&=0xFC;CAPCON1|=0x01;CAPCON3&=0xF0;CAPCON3|=0x02;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4;
//#define    IC3_P00_CAP0_RisingEdge_Capture            CAPCON1&=0xFC;CAPCON1|=0x01;CAPCON3&=0xF0;CAPCON3|=0x03;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4;
//#define    IC3_P04_CAP0_RisingEdge_Capture            CAPCON1&=0xFC;CAPCON1|=0x01;CAPCON3&=0xF0;CAPCON3|=0x04;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4;
//#define    IC4_P01_CAP0_RisingEdge_Capture            CAPCON1&=0xFC;CAPCON1|=0x01;CAPCON3&=0xF0;CAPCON3|=0x05;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4;
//#define    IC5_P03_CAP0_RisingEdge_Capture            CAPCON1&=0xFC;CAPCON1|=0x01;CAPCON3&=0xF0;CAPCON3|=0x06;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4;
//#define    IC6_P05_CAP0_RisingEdge_Capture            CAPCON1&=0xFC;CAPCON1|=0x01;CAPCON3&=0xF0;CAPCON3|=0x07;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4;
//#define    IC7_P15_CAP0_RisingEdge_Capture            CAPCON1&=0xFC;CAPCON1|=0x01;CAPCON3&=0xF0;CAPCON3|=0x08;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4;

//#define IC0_P12_CAP1_RisingEdge_Capture            CAPCON1&=0xF3;CAPCON1|=0x04;CAPCON3&=0x0FCAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC1_P11_CAP1_RisingEdge_Capture            CAPCON1&=0xF3;CAPCON1|=0x04;CAPCON3&=0x0F;CAPCON3|=0x10;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC2_P10_CAP1_RisingEdge_Capture            CAPCON1&=0xF3;CAPCON1|=0x04;CAPCON3&=0x0F;CAPCON3|=0x20;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC3_P00_CAP1_RisingEdge_Capture            CAPCON1&=0xF3;CAPCON1|=0x04;CAPCON3&=0x0F;CAPCON3|=0x30;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC3_P04_CAP1_RisingEdge_Capture            CAPCON1&=0xF3;CAPCON1|=0x04;CAPCON3&=0x0F;CAPCON3|=0x40;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC4_P01_CAP1_RisingEdge_Capture            CAPCON1&=0xF3;CAPCON1|=0x04;CAPCON3&=0x0F;CAPCON3|=0x50;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC5_P03_CAP1_RisingEdge_Capture            CAPCON1&=0xF3;CAPCON1|=0x04;CAPCON3&=0x0F;CAPCON3|=0x60;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC6_P05_CAP1_RisingEdge_Capture            CAPCON1&=0xF3;CAPCON1|=0x04;CAPCON3&=0x0F;CAPCON3|=0x70;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC7_P15_CAP1_RisingEdge_Capture            CAPCON1&=0xF3;CAPCON1|=0x04;CAPCON3&=0x0F;CAPCON3|=0x80;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;

//#define IC0_P12_CAP3_RisingEdge_Capture            CAPCON1&=0x0F;CAPCON1|=0x10;CAPCON4&=0xF0;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC1_P11_CAP3_RisingEdge_Capture            CAPCON1&=0x0F;CAPCON1|=0x10;CAPCON4&=0xF0;CAPCON4|=0x01;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC2_P10_CAP3_RisingEdge_Capture            CAPCON1&=0x0F;CAPCON1|=0x10;CAPCON4&=0xF0;CAPCON4|=0x02;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC3_P00_CAP3_RisingEdge_Capture            CAPCON1&=0x0F;CAPCON1|=0x10;CAPCON4&=0xF0;CAPCON4|=0x03;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC3_P04_CAP3_RisingEdge_Capture            CAPCON1&=0x0F;CAPCON1|=0x10;CAPCON4&=0xF0;CAPCON4|=0x04;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC4_P01_CAP3_RisingEdge_Capture            CAPCON1&=0x0F;CAPCON1|=0x10;CAPCON4&=0xF0;CAPCON4|=0x05;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC5_P03_CAP3_RisingEdge_Capture            CAPCON1&=0x0F;CAPCON1|=0x10;CAPCON4&=0xF0;CAPCON4|=0x06;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC6_P05_CAP3_RisingEdge_Capture            CAPCON1&=0x0F;CAPCON1|=0x10;CAPCON4&=0xF0;CAPCON4|=0x07;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC7_P15_CAP3_RisingEdge_Capture            CAPCON1&=0x0F;CAPCON1|=0x10;CAPCON4&=0xF0;CAPCON4|=0x08;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;

////-----BOTH  edge ----
//#define IC0_P12_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC1_P11_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x01;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC2_P10_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x02;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC3_P00_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x03;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC3_P04_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x04;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC4_P01_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x05;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC5_P03_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x06;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC6_P05_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x07;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
//#define    IC7_P15_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x08;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4

//#define IC0_P12_CAP1_BothEdge_Capture                CAPCON1&=0xF3;CAPCON1|=0x08;CAPCON3&=0x0F;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5
//#define    IC1_P11_CAP1_BothEdge_Capture                CAPCON1&=0xF3;CAPCON1|=0x08;CAPCON3&=0x0F;CAPCON3|=0x10;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC2_P10_CAP1_BothEdge_Capture                CAPCON1&=0xF3;CAPCON1|=0x08;CAPCON3&=0x0F;CAPCON3|=0x20;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC3_P00_CAP1_BothEdge_Capture                CAPCON1&=0xF3;CAPCON1|=0x08;CAPCON3&=0x0F;CAPCON3|=0x30;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC3_P04_CAP1_BothEdge_Capture                CAPCON1&=0xF3;CAPCON1|=0x08;CAPCON3&=0x0F;CAPCON3|=0x40;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC4_P01_CAP1_BothEdge_Capture                CAPCON1&=0xF3;CAPCON1|=0x08;CAPCON3&=0x0F;CAPCON3|=0x50;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC5_P03_CAP1_BothEdge_Capture                CAPCON1&=0xF3;CAPCON1|=0x08;CAPCON3&=0x0F;CAPCON3|=0x60;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC6_P05_CAP1_BothEdge_Capture                CAPCON1&=0xF3;CAPCON1|=0x08;CAPCON3&=0x0F;CAPCON3|=0x70;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;
//#define    IC7_P15_CAP1_BothEdge_Capture                CAPCON1&=0xF3;CAPCON1|=0x08;CAPCON3&=0x0F;CAPCON3|=0x80;CAPCON0|=SET_BIT5;CAPCON2|=SET_BIT5;

//#define IC0_P12_CAP3_BothEdge_Capture                CAPCON1&=0x0F;CAPCON1|=0x20;CAPCON4&=0xF0;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC1_P11_CAP3_BothEdge_Capture                CAPCON1&=0x0F;CAPCON1|=0x20;CAPCON4&=0xF0;CAPCON4|=0x01;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC2_P10_CAP3_BothEdge_Capture                CAPCON1&=0x0F;CAPCON1|=0x20;CAPCON4&=0xF0;CAPCON4|=0x02;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC3_P00_CAP3_BothEdge_Capture                CAPCON1&=0x0F;CAPCON1|=0x20;CAPCON4&=0xF0;CAPCON4|=0x03;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC3_P04_CAP3_BothEdge_Capture                CAPCON1&=0x0F;CAPCON1|=0x20;CAPCON4&=0xF0;CAPCON4|=0x04;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC4_P01_CAP3_BothEdge_Capture                CAPCON1&=0x0F;CAPCON1|=0x20;CAPCON4&=0xF0;CAPCON4|=0x05;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC5_P03_CAP3_BothEdge_Capture                CAPCON1&=0x0F;CAPCON1|=0x20;CAPCON4&=0xF0;CAPCON4|=0x06;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC6_P05_CAP3_BothEdge_Capture                CAPCON1&=0x0F;CAPCON1|=0x20;CAPCON4&=0xF0;CAPCON4|=0x07;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;
//#define    IC7_P15_CAP3_BothEdge_Capture                CAPCON1&=0x0F;CAPCON1|=0x20;CAPCON4&=0xF0;CAPCON4|=0x08;CAPCON0|=SET_BIT6;CAPCON2|=SET_BIT6;

//#define TIMER2_IC2_DISABLE                                    CAPCON0&=~SET_BIT6             
//#define TIMER2_IC1_DISABLE                                    CAPCON0&=~SET_BIT5            
//#define TIMER2_IC0_DISABLE                                    CAPCON0&=~SET_BIT4    

///*----------------------------------------------------------------------------------------------------------
//*    Timer2 mode define
//------------------------------------------------------------------------------------------------------------*/

//#define     TIMER2_CAP0_Capture_Mode            T2CON&=~SET_BIT0;T2MOD=0x89
//#define     TIMER2_CAP1_Capture_Mode            T2CON&=~SET_BIT0;T2MOD=0x8A
//#define     TIMER2_CAP2_Capture_Mode            T2CON&=~SET_BIT0;T2MOD=0x8B

///*----------------------------------------------------------------------------------------------------------
//*   Timer devider define
//----------------------------------------------------------------------------------------------------------*/
//#define TIMER2_DIV_4            T2MOD|=0x10;T2MOD&=0x9F
//#define TIMER2_DIV_16            T2MOD|=0x20;T2MOD&=0xAF
//#define TIMER2_DIV_32            T2MOD|=0x30;T2MOD&=0xBF
//#define TIMER2_DIV_64            T2MOD|=0x40;T2MOD&=0xCF
//#define TIMER2_DIV_128        T2MOD|=0x50;T2MOD&=0xDF
//#define TIMER2_DIV_256        T2MOD|=0x60;T2MOD&=0xEF
//#define TIMER2_DIV_512        T2MOD|=0x70
#endif


/************************************************************************************************************
*    Timer2 Capture interrupt subroutine
************************************************************************************************************/
void Capture_ISR (void) interrupt 12
{
        clr_CAPF0;                          // clear capture0 interrupt flag
        P1 = C0L;                                                        // For capture mode CxL/CxH with data capture from I/O pin
        P2 = C0H;                                                        
        P12 = ~P12;                                                    //toggle GPIO1 to show int
                printf("\n TM2 CAP 0x%bX",C0H);
                clr_TF2;
}
/************************************************************************************************************
*    Main function 
************************************************************************************************************/
void main (void)
{
    Set_All_GPIO_Quasi_Mode;
        InitialUART0_Timer3(115200);
        P00_Input_Mode;
        P00 = 1;

        TIMER2_CAP0_Capture_Mode;
        IC3_P00_CAP0_BothEdge_Capture;
            
        set_ECAP;                                   //Enable Capture interrupt
        set_TR2;                                    //Triger Timer2
        set_EA;

    while(1);
}

 


#define TIMER2_CAP0_Capture_Mode T2CON&=~SET_BIT0;T2MOD=0x89
#define TIMER2_CAP1_Capture_Mode T2CON&=~SET_BIT0;T2MOD=0x8A
#define TIMER2_CAP2_Capture_Mode T2CON&=~SET_BIT0;T2MOD=0x8B

#define IC0_P12_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
#define    IC1_P11_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x01;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
#define    IC2_P10_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x02;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
#define    IC3_P00_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x03;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
#define    IC3_P04_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x04;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
#define    IC4_P01_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x05;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
#define    IC5_P03_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x06;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
#define    IC6_P05_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x07;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4
#define    IC7_P15_CAP0_BothEdge_Capture                CAPCON1&=0xFC;CAPCON1|=0x02;CAPCON3&=0xF0;CAPCON3|=0x08;CAPCON0|=SET_BIT4;CAPCON2|=SET_BIT4

 

 

 

 

想用定時(shí)器2的捕獲功能,就是我捕獲的信號可能要超過定時(shí)器最高值65536。請教各位高手當(dāng)超出了會不會引起定時(shí)器2中斷

捕獲也是一種定時(shí)器中斷,定時(shí)器計(jì)數(shù)到頭也是一種,兩種不同,因?yàn)榭赡軜侵髡f的情況發(fā)生,當(dāng)然會提供一個(gè)中斷,這樣你可以知道你計(jì)時(shí)長度啊,要不然不準(zhǔn)了。

 

set_ECAP

#define set_ECAP EIE |= SET_BIT2

set_TR2

 

void Capture_ISR (void) interrupt 12
{
        clr_CAPF0;                          // clear capture0 interrupt flag
        P1 = C0L;                                                        // For capture mode CxL/CxH with data capture from I/O pin
        P2 = C0H;                                                        
        P12 = ~P12;                                                    //toggle GPIO1 to show int
                printf("\n TM2 CAP 0x%bX",C0H);
                clr_TF2;
}

 



聯(lián)系方式0755-82591179

傳真:0755-82591176

郵箱:vicky@yingtexin.net

地址:深圳市龍華區(qū)民治街道民治大道973萬眾潤豐創(chuàng)業(yè)園A棟2樓A08

始兴县| 扶风县| 明星| 洪洞县| 鸡西市| 上林县| 石河子市| 锡林浩特市| 德格县| 山东省| 云浮市| 朝阳市| 卓尼县| 光泽县| 白沙| 诏安县| 乌兰县| 富阳市| 油尖旺区| 新田县| 东乌| 浙江省| 祁阳县| 顺平县| 芦溪县| 宾阳县| 靖远县| 临海市| 滨州市| 灵川县| 象州县| 犍为县| 江川县| 东乌珠穆沁旗| 博兴县| 肇东市| 太仆寺旗| 齐齐哈尔市| 屏南县| 赞皇县| 泽普县|