📄 pca_isr.c
字号:
//
// PROGRAM DESCRIPTION:
// This are the PCA interrupt service routines, which generate the
// tone pulse. The CEX2_isr function is the tone detect routine. there is two
// kind of caculation for the tone. The first one is count the pulse in one
// fixed period. The another way is timing
// between two pulse.
//
// ADDITIONAL DOCUMENTATION:
// Flow Chart:
// Support Doc's:
//
// INPUTS:
// OUTPUTS:
// SUBROUTINE CALLS:
// CALLED BY: Interrupt entrence in main
//
// REVISION HISTORY:
//
// DATE REVISED BY DESCRIPTION OF CHANGE
// -------------------------------------------------------------------------
#include<intrins.h>
#include<reg51f.h>
#include"PCA.h"
#include"CFSK.h"
bit CEX2_first_period; // first time of the count pulse mode
unsigned char PCA_buf0_high; // PCA module 0 register high byte buffer
unsigned char PCA_buf0_low; // PCA module 0 register low byte buffer
unsigned char PCA_buf1_high; // PCA module 1 register high byte buffer
unsigned char PCA_buf1_low; // PCA module 1 register low byte buffer
unsigned char PCA_capture_count; // store capture pulse count.
/*
This is the CEX2 interrupt service routine. Called by the main.
*/
void CEX2_isr(void)
{
unsigned int i;
if(DTMF_capture_flag)
{
// caculate frequency by pulse count in a fixed period
if(CEX2_first_period)
{
// this is the first rasing pulse capture
PCA_capture_count=0;
CEX2_first_period=0;
}
else
{
// increase the count
PCA_capture_count++;
}
}
else if(CFSK_capture_flag)
{
//caculate 4 cycle's period
if(CFSK_edge_counter == 0)
{
// this is the first pulse, do some initialization
// CFSK_capture_finish = 0;
current_period=0;
// first edge have been detected.
CFSK_edge_counter = 1;
}
else if(CFSK_edge_counter < 2)
{
// accumulate period into the buffer;
i = CCAP2H;
i<<=8;
i=i+CCAP2L;
i=i-previous_period;
current_period+=i;
// increase the rasing edge counter.
CFSK_edge_counter++;
}
else
{
// we have get 2 cycles period. let's do something and see what's
// reset flag
CFSK_edge_counter = 0;
//caculate the interval period between two PCA interrupt
i = CCAP2H;
i<<=8;
i=i+CCAP2L;
i=i-previous_period;
current_period+=i;
if(CFSK_start_bit)
{
// just turn off the PCA when we are receiving the bit of one byte.
CCAPM2=PCA_OFF;
}
else if((0x3bc<current_period)&&(current_period<0x40E))
{//
//start bit detected here;up limit 2125hz, low limit 1925hz
//received bit is 0:2070HZ
// start bit is detected here, set the flag bit;
CFSK_start_bit=1;
CFSK_bit_counter=0;
CFSK_received_byte=0;
CCAPM2 = PCA_OFF;
// set the sample point in the middle of the next bit.
TH2=0Xf6;//0XF6-F0
TL2=0Xe0;
TR2=1;
TF2=0;
ET2=1;
// the start bit have been detected and next interrupt will enable
// PCA capture module.
}
}
//update the previous period buffer with current time point;
previous_period = CCAP2H;
previous_period<<=8;
previous_period+= CCAP2L;
}
}
/*
This is the CEX0 interrupt service routine. Called by the main.
This routine generate the high freqency tone.
*/
void CEX0_isr(void)
{
//----------------------pin CEX0 interrupt serviece routine
//reverse the Pin CEX0 status
CEX0 = ~CEX0;
//add the period low byte.
CCAP0L += PCA_buf0_low;
//add the period high byte.
if(CY)
{
CCAP0H += PCA_buf0_high;
CCAP0H++;
}
else
{
CCAP0H += PCA_buf0_high;
}
// so after a period the interrupt will hapen again.
}
/*
This is the CEX1 interrupt service routine. Called by the main.
This routine generate the low freqency tone.
*/
void CEX1_isr(void)
{//pin CEX1 interrupt serviece routine
CEX1 = ~CEX1;
CCAP1L += PCA_buf1_low;
if(CY)
{
CCAP1H += PCA_buf1_high;
CCAP1H++;
}
else
{
CCAP1H += PCA_buf1_high;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -