用gcc编译器,以下是内容: #include <inttypes.h> #include <avr/io.h> #include <avr/interrupt.h> #include <avr/signal.h> #include <avr/wdt.h> #include <compat/ina90.h> #include <avr/eeprom.h> #include <stdio.h> #include <avr/delay.h> #define uint unsigned int #define uchar unsigned char volatile unsigned int a1=25,a2=24687;//为测频设置的两个数 volatile unsigned int shu;//周期数 volatile unsigned char count1;//参数 static char duanma[]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09,0}; // static char duanma[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; void xianshi(uint a) {uchar j,weima=0x01,shuju[6]; uint i=a; PORTD=0xff; PORTC=0x01; shuju[0]=duanma[i/100000]; i%=100000; shuju[1]=duanma[i/10000]; i%=10000; shuju[2]=duanma[i/1000]; i%=1000; shuju[3]=duanma[i/100]; i%=100; shuju[4]=duanma[i/10]; i%=10; shuju[5]=duanma; for(j=0;j<6;j++) {PORTD=shuju[j]; PORTC=weima; _delay_ms(1); weima<<=1; } PORTC=PORTD=0; }//显示子程序 void ICP_init(void) {TCCR1A=0; TIMSK=1<<TICIE1;//使能icp中断 TCCR1B|=(0<<CS12)|(0<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//;//设置icp,分频1024 TCNT1=0; sei();//开中断 }//设置icp //ICP输入捕获中断处理程序 SIGNAL(SIG_INPUT_CAPTURE1) { a1=15694; TIFR=(1<<ICF1); count1++; switch(count1) { case 2://第一次捕获,则开始计数 { a1 = ICR1; } break; case 3: //第二次捕获,表示一个周期结束,计数结束 { a2 = ICR1; //TIMSK &= ~((1<<TICIE1)|(1<<TOIE1)); cli();//关闭中断使能 count1=0; } break; default: ; } } //icp捕获中断 void main() {uchar j; DDRC=DDRD=0xff;//d口和x口均为输出口 DDRB=0x0;//icp端口为输入 PORTB=0x0;//全部不带上拉电阻 ICP_init();//设置icp while(1) {count1=1; if(a2>a1)shu=a2-a1; else shu=65536-a1+a2; for(j=0; j<250; j++)_delay_ms(2); TIMSK |= (1<<TICIE1);//打开输入捕捉器中断使能 while(count1)xianshi(shu);//count1循环,等待捕获中断处理完成, xianshi(shu); }//return 0; } |