📄 ccp.c.bak
字号:
#include "PIC18.h"
#include "def.h"
#include "lib.h"
void tmr3_isr(void)
{
}
void ccp1_isr(void)
{
}
void ccp1_init(void)
{
GIE=0;//关全局中断
PEIE=1;//开中断优先级
IPEN=1;
T3CON=0xc8; //1100 1000B T3以16位读写,作为CCP1的时钟源,1/4内部信号,分频1:1,T3暂停
CCP1CON=0x05;//CCP1模块设置为捕获模式,每1个上升沿捕获一次
TMR3IE=0;//暂停T3中断
CCP1IE=0;//暂停CCP1中断
TMR3IP=0;//T3溢出中断为低优先级
CCP1IP=0;//CCP1捕获中断为低优先级
TMR3IF=0;//清空T3中断标志
CCP1IF=0;//清空CCP1中断标志
CCPR1H=0X00;
CCPR1L=0X00;//清空捕捉定时器
TMR3H=0X00;//T3计时器清零,先写入高8位,再写入低8位
TMR3L=0X00;//
}
void ccp(void)
{
now_channel=0x00;//现在转换的通道
channel_int_num=0xff;//通道中断的次数 BIT
channel_error=0x00;
channel_open_close=0x01;//
ccp_over=0;
high_int=0;
while(now_channel<8)
{
if((channel_open_close&(1<<now_channel))==0)//当前通道是关闭的
{
now_channel++;
continue;
}
CHANNEL_PORT=now_channel;//输出通道选择码
delay(1000);
TMR3ON=0;//暂停T3
TMR3H=0X00;
TMR3L=0X00;//重载T3数值
TMR3IE=1;//使能T3中断
TMR3ON=1;//打开T3
CCP1IE=1;//使能CCP中断
while(!ccp_over&&high_int==0)//等待CCP过程结束,并且没有高优先级的中断
CLRWDT() ;
if(high_int==1)//有更高优先级中断发生过,重新开始本通道检测
{
high_int=0;
ccp_over=0;
continue;
}
else
{
if((channel_error&(1<<now_channel))==0)//当前通道没有错误
{
channel_int_num|=(1<<now_channel);//将通道中断次数置1
channel_period[now_channel][2]=channel_period[now_channel][1]-channel_period[now_channel][0];
}
now_channel++;//端口号+1,下一端口转换
ccp_over=0;
}
}
}
void frequency_caculate(void)
{
uchar i;
for(i=0;i<8;i++)
{
if((channel_open_close&(1<<i))==0)
{
display_point[0]=(uchar*)&ASCII[('C'-0x20)*5];
display_point[1]=(uchar*)&ASCII[('L'-0x20)*5];
display_point[2]=(uchar*)&ASCII[('O'-0x20)*5];
display_point[3]=(uchar*)&ASCII[('S'-0x20)*5];
display_point[4]=(uchar*)&ASCII[('E'-0x20)*5];
display_point[5]=(uchar*)&ASCII[('D'-0x20)*5];
display_ascii(6,display_point,i,0);
}
else
if((channel_error&(1<<i))==1)//不正常
{
display_point[0]=(uchar*)&ASCII[('E'-0x20)*5];
display_point[1]=(uchar*)&ASCII[('R'-0x20)*5];
display_point[2]=(uchar*)&ASCII[('R'-0x20)*5];
display_point[3]=(uchar*)&ASCII[('O'-0x20)*5];
display_point[4]=(uchar*)&ASCII[('R'-0x20)*5];
display_point[5]=(uchar*)&ASCII[0];
display_ascii(6,display_point,i,0);
}
else
{
frequency[i]=(uint)((FOSC/channel_period[i][2])>>2);
data_change(channel_period[i][2]);
display_point[0]=(uchar*)&ASCII[(display_data[3]+0x10)*5];
display_point[1]=(uchar*)&ASCII[(display_data[2]+0x10)*5];
display_point[2]=(uchar*)&ASCII[(display_data[1]+0x10)*5];
display_point[3]=(uchar*)&ASCII[(display_data[0]+0x10)*5];
display_point[4]=(uchar*)&ASCII[('H'-0x20)*5];
display_point[5]=(uchar*)&ASCII[('z'-0x20)*5];
display_ascii(6,display_point,i,0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -