欢迎来到天天文库
浏览记录
ID:37908971
大小:153.00 KB
页数:16页
时间:2019-06-02
《AVRAD采集转换程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、AVRAD采集转换程序,带数字滤波 1.//本例使用内部参考电压,ADc0输入,采集的信号通过LED显示。 2. 3.//ICC-AVRapplicationbuilder:2006-9-311:42:36 4.//Target:M32 5.//Crystal:7.3728Mhz 6.//2.56v片内基准电压,输入a1:即adc0 7.//误差为:连续测量模式。 8.//精度8,输出左对齐ADLAR=1 9.//注意:参考电压一定要高于被测电压。 10.#include 11.#include 12./
2、/数字滤波 13.#definea0xF4 14.//a=0.95 15.#defineb0x0D 16.//b=1-a=0.05 17.constled_table[16]={0xa0,0xfc,0xc1,0xd0,0x9c,0x92,0x82,0xf8,0x80,0x90,0x88,0x86,0xc7,0xc4,0x83,0x8b};//0~~f 18.typedefunsignedcharuint8; 19.uint8value,value1=0; 20.intx;//最终的值10位 21.volatileuint8i,j=0; 22. 23.//dela
3、y 24./***********************************/ 25.voidDelay100us(uint8n) 26.{ 27. uint8i; 28. for(i=36;n!=0;n--) 29. while(--i); 30.} 31. 32.voidDelay1s(uint8n) 33.{ 34. n=n*10; 35. for(;n!=0;n--){ 36. Delay100us(200); 37. } 38.} 39./******************************/ 40. 41.void
4、port_init(void) 42.{ 43.PORTA=0x00; //做adc输入时不可上拉。 44.DDRA=0x00; 45.PORTB=0xFF; 46.DDRB=0xFF; 47.PORTC=0xFF; 48.DDRC=0x00; 49.PORTD=0xFF; 50.DDRD=0x00; 51.} 52. 53.//ADCinitialize 54.//Conversiontime:225uS 55.voidadc_init(void) 56.{ 57.ADCSR=0x00;//disableadc 58.ADMUX=0xC0
5、(1<6、);//2.56v片内基准电压/selectadcinput0/ 59.ACSR=0x80;//使能adc可用,不用修改 60.ADCSRA=0xA8;//ADC使能,自动触发模式使能,触发源由SFIOR确定,中断使能,分频因子为2 61.SFIOR=0X60;//触发源设置为:定时器比较匹配 62.} 63. 64.//TIMER0initialize-prescale:1024 65.//WGM:Normal 66.//desiredvalue:1Hz 67.//actualvalue:35.556mSec(-3455.6%) 68.voidtimer0_i7、nit(void) 69.{ 70.TCCR0=0x00;//stop 71.TCNT0=0x01;//setcount 72.OCR0=0x02;//setcompare//FF 73.TCCR0=0x0D;//starttimer1024分频CTC比较输出定时时间:256/(7.3728Mhz/1024)=35.556ms 74.} 75. 76.#pragmainterrupt_handlertimer0_ovf_isr:10 77.voidtimer0_ovf_isr(void) 78.{ 79.TCNT0=0x01;//reloadcounterval8、ue 80.j++; 81.if(j==0)CLI(); 82.} 83. 84.#pragmainterrupt_handlertimer0_comp_isr:20 85.voidtimer0_comp_isr(void) 86.{ 87.//compareoccuredTCNT0=OCR0 88.TCNT0=0x01;//reloadcountervalue 89.i++; 90.if(i==0)CLI(); 91.} 92. 93.#pragmainterrupt_handleradc_isr:15 94.voidadc_isr(void) 95.{ 969、.//conversio
6、);//2.56v片内基准电压/selectadcinput0/ 59.ACSR=0x80;//使能adc可用,不用修改 60.ADCSRA=0xA8;//ADC使能,自动触发模式使能,触发源由SFIOR确定,中断使能,分频因子为2 61.SFIOR=0X60;//触发源设置为:定时器比较匹配 62.} 63. 64.//TIMER0initialize-prescale:1024 65.//WGM:Normal 66.//desiredvalue:1Hz 67.//actualvalue:35.556mSec(-3455.6%) 68.voidtimer0_i
7、nit(void) 69.{ 70.TCCR0=0x00;//stop 71.TCNT0=0x01;//setcount 72.OCR0=0x02;//setcompare//FF 73.TCCR0=0x0D;//starttimer1024分频CTC比较输出定时时间:256/(7.3728Mhz/1024)=35.556ms 74.} 75. 76.#pragmainterrupt_handlertimer0_ovf_isr:10 77.voidtimer0_ovf_isr(void) 78.{ 79.TCNT0=0x01;//reloadcounterval
8、ue 80.j++; 81.if(j==0)CLI(); 82.} 83. 84.#pragmainterrupt_handlertimer0_comp_isr:20 85.voidtimer0_comp_isr(void) 86.{ 87.//compareoccuredTCNT0=OCR0 88.TCNT0=0x01;//reloadcountervalue 89.i++; 90.if(i==0)CLI(); 91.} 92. 93.#pragmainterrupt_handleradc_isr:15 94.voidadc_isr(void) 95.{ 96
9、.//conversio
此文档下载收益归作者所有