求大神指教利用atmega16读脉冲宽度
我利用外部中断1和外部中断2配合定时器1读脉冲宽度,发现结果很不准确,请各位看看问题出在哪里。#include <iom16v.h>
#include <macros.h>
#defineuchar unsigned char
#defineuintunsigned int
#include <math.h>
uchar i=0,j=0,k=0,l,m,n;
#pragma interrupt_handler catch:3
#pragma interrupt_handler start:2
#pragma interrupt_handler miao:10
#pragma data:code
voidmiao()
{
i++;
j++;
k++;
if(i<=l) PORTD|=BIT(4);
else if(i<200) PORTD&=~BIT(4);
else {i=0 ;PORTD&=~BIT(4);}
if(j<=m) PORTD|=BIT(5);
else if(j<200) PORTD&=~BIT(5);
else {j=0 ;PORTD&=~BIT(5);}
if(k<=n) PORTD|=BIT(7);
else if(k<200) PORTD&=~BIT(7);
else {k=0 ;PORTD&=~BIT(7);}
TCNT0=183;
}
void start()
{
TCNT1H=0X00;
TCNT1L=0X00;
TCCR1B=0X01;
}
void catch()
{
uchar a,b,c;
TCCR1B=0X00;
a=TCNT1L;
b=TCNT1H;
c=255*b;
c=c+a;
l=c/20;
}
void main()
{
DDRD=0xF3;
PORTD|=BIT(1);
PORTD&=~BIT(0);
l=10;n=10;m=10;
TCCR0=0X02;
TCNT0=155;
//TCCR1B=0X06;
TCNT1H=0X00;
TCNT1L=0X00;
TIMSK|=BIT(0);
MCUCR=0X0B;
GICR|=BIT(6);
GICR|=BIT(7);
SREG|=BIT(7);
while(1);
}
页:
[1]