胡斯哲 发表于 2013-6-13 22:21
我用中断弄了 低频的怎么不好使 你说的脉冲捕捉怎么弄啊 #include "reg51.h"
#include "intrins.h"
typedef unsigned char BYTE;
typedef unsigned int WORD;
/*Declare SFR associated with the PCA */
sfr CCON = 0xD8; //PCA control register
sbit CCF0 = CCON^0; //PCA module-0 interrupt flag
sbit CCF1 = CCON^1; //PCA module-1 interrupt flag
sbit CR = CCON^6; //PCA timer run control bit
sbit CF = CCON^7; //PCA timer overflow flag
sfr CMOD = 0xD9; //PCA mode register
sfr CL = 0xE9; //PCA base timer LOW
sfr CH = 0xF9; //PCA base timer HIGH
sfr CCAPM0 = 0xDA; //PCA module-0 mode register
sfr CCAP0L = 0xEA; //PCA module-0 capture register LOW
sfr CCAP0H = 0xFA; //PCA module-0 capture register HIGH
sfr CCAPM1 = 0xDB; //PCA module-1 mode register
sfr CCAP1L = 0xEB; //PCA module-1 capture register LOW
sfr CCAP1H = 0xFB; //PCA module-1 capture register HIGH
sfr PCAPWM0 = 0xf2;
sfr PCAPWM1 = 0xf3;
sbit PCA_LED = P1^0; //PCA test LED
void PCA_isr() interrupt 7 using 1
{
CCF0 = 0; //Clear interrupt flag
PCA_LED = !PCA_LED; //toggle the test pin while CEX0(P1.3) have a falling edge
}
void main()
{
CCON = 0; //Initial PCA control register
//PCA timer stop running
//Clear CF flag
//Clear all module interrupt flag
CL = 0; //Reset PCA base timer
CH = 0;
CMOD = 0x00; //Set PCA timer clock source as Fosc/12
//Disable PCA timer overflow interrupt
CCAPM0 = 0x11; //PCA module-0 capture by a negative tigger on CEX0(P1.3) and enable PCA interrupt
// CCAPM0 = 0x21; //PCA module-0 capture by a rising edge on CEX0(P1.3) and enable PCA interrupt
// CCAPM0 = 0x31; //PCA module-0 capture by a transition (falling/rising edge) on CEX0(P1.3) and enable PCA interrupt
CR = 1; //PCA timer start run
EA = 1;
while (1);
}
|