RSS

测频率的源程序

来源:网络 作者:未知 时间:2007-01-05 Tag: 点击:

<!--StartFragment-->// 测频率,信号从AT90S8515的ICP引脚输入

#include <io8515.h>

#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long

#define Number 20
#define A 40

#define bit(x) (1 << x)
#define Enable_Interrupt SREG |= bit(7)
#define Disable_Interrupt SREG &= ~bit(7)

#define T1 bit(5) //(1 << 5)

uchar DATA_7SEG[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
       0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

uchar XmtDat[6];
uint  count;
uint volue;
 
uchar tempn;
uchar cnt;
uchar flag;


void convert(void)
{
uchar i,k;
uint tmp_data;

tmp_data=volue;

for(i=0;i<6;i++)
  {
  k=tmp_data%10;
  tmp_data=tmp_data/10;
 
XmtDat[i]=DATA_7SEG[k];
  }
}

void delay(uchar t)
{
uchar i;

for(i=0;i<t;i++);
}

void disp(void)
{
uchar i;

for(i=0;i<6;i++)
  {
  PORTD=~(0X01<<i);
  PORTB=XmtDat[i];
  delay(100);
  }
PORTB=0x00;
PORTD=0xFF;
}

void system_init(void)
{
DDRB=0XFF;
DDRD=0X7F;
PORTD |= 0X80;
}

void sys(void) //初始化
{
TIMSK=0x08;
TCCR1B=0xC0;
count=0;
tempn=0;
cnt=A;
}

void main(void)
{
uint out_data;

Disable_Interrupt;

system_init();

sys();

Enable_Interrupt;

flag=0;

while(1)
  {
  if( flag == 1 )
    {
  convert();
    }
   
  disp();
 
  }
 
}

#pragma vector = TIMER1_CAPT1_vect        //向量说明
__interrupt void timer1_capt(void)
{
//icp触发中断子程序
if( tempn==0 )
  {
count++;
TCNT0=0x3A;
TCCR0=0x05;
TIMSK=0x0A; //开timer0
// TCCR1B=0xC0; //致timer0中断和捕捉中断
tempn=1;
  }
else
count++;
}

#pragma vector = TIMER0_OVF0_vect        //向量说明
__interrupt void timer0(void)
{
//timer0溢出中断子程序
TCNT0 = 0x3A;

cnt--;
if( cnt == 0 )
  {
  volue=count;
  sys();
 
flag=1;
  }
}

1.部分资源来自网络,经ET电子归类整理,旨在服务电子爱好者并无商业目的,不保证正确性与完整性.
2.如果您觉得本站资源对您有用,请告知您的好友,用搜索引擎搜"ET电子"即可.


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
合作站点