⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frequency.c

📁 本程序实现基于pic16f877的CCP输入捕捉和频率测量功能。
💻 C
字号:
#include<pic.h>
char a;
static volatile char table[16]={0x30,0x31,0x32,0x33,0x34,
    0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46 };
union lio
{long li;
char data[2];}xianshi;

unsigned int b,c,d,e,f;

unsigned long  frq;
void DELAY()
{unsigned int i;
for (i=999;i>0;i--);
}

void ENABLE()
{RA1=0;RA2=0;RA3=0;
DELAY();
RA3=1;
}

void ENABLE1()
{RA1=1;RA2=0;RA3=0;
DELAY();
RA3=1;
}

void display_initialize()
{TRISA=0x01;TRISD=0;
 ADCON1=0x07;//设置RA口全部为普通数字I/O口
 DELAY();
 PORTD=1;
 ENABLE();
 PORTD=0x38;
 ENABLE();
 PORTD=0x0c;
 ENABLE();
 PORTD=0x06;
 ENABLE();
 PORTD=0X80;
 ENABLE();
}
void display()
{  PORTD=0X80;
  ENABLE();
  PORTD=0x50;
  ENABLE1();
  PORTD=0x3a;
  ENABLE1();
  a=xianshi.li/10000;//十六进制转化成十进制 并显示
  PORTD=table[a];
  ENABLE1();
  a=xianshi.li/1000%10;
  PORTD=table[a];
  ENABLE1();
  a=xianshi.li/100%10;
  PORTD=table[a];
  ENABLE1();
  a=xianshi.li/10%10;
  PORTD=table[a];
  ENABLE1();
  a=xianshi.li%10;
  PORTD=table[a];
  ENABLE1(); 
  PORTD=0X75;//"u"
  ENABLE1();
  PORTD=0X53;//"S"显示单位  显示周期
  ENABLE1();
  xianshi.li=1000000/xianshi.li;  //转换成频率
  frq=xianshi.li;
  PORTD=0Xc0;
  ENABLE();
  PORTD=0x46;
  ENABLE1();
  PORTD=0x3A;
  ENABLE1();
  a=frq/10000;
  PORTD=table[a];
  ENABLE1();
  a=frq/1000%10;
  PORTD=table[a];
  ENABLE1();
  a=frq/100%10;
  PORTD=table[a];
  ENABLE1();
  a=frq/10%10;
  PORTD=table[a];
  ENABLE1();
  a=frq%10;
  PORTD=table[a];
  ENABLE1();
  PORTD=0X48;//"H"
  ENABLE1();
  PORTD=0X5a;//"Z"显示频率
  ENABLE1();
}





void interrupt ccp1_int()
{CCP1IF=0;
xianshi.data[1]=CCPR1H;
xianshi.data[0]=CCPR1L;
TMR1L=TMR1H=0;
return;
}



void main()
{
 xianshi.li=65535;
 INTCON=0;PIR1=0;PIR2=0;PIE1=0;PIE2=0;
 TRISC=0X04;
 T1CON=0X00;
 CCP1IE=1;
 PEIE=1;GIE=1;
 CCP1CON=0B00000100;//下降沿捕捉
 TMR1ON=1;
 display_initialize();
 while(1){
 display();
         }

}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -