AVRAD采集转换程序.docVIP

  • 14
  • 0
  • 约1.18万字
  • 约 15页
  • 2018-03-09 发布于河南
  • 举报
AVRAD采集转换程序

AVR AD采集转换程序,带数字滤波?? 1. //本例使用内部参考电压,ADc0输入,采集的信号通过LED显示。 ?? 2. ?? 3. //ICC-AVR application builder : 2006-9-3 11:42:36 ?? 4. // Target : M32 ?? 5. // Crystal: 7.3728Mhz ?? 6. // 2.56v 片内基准电压,输入a1:即adc0 ?? 7. // 误差为: 连续测量模式。 ?? 8. // 精度8,输出左对齐 ADLAR=1 ?? 9. // 注意:参考电压一定要高于被测电压。 ? 10. #include iom32v.h ? 11. #include macros.h ? 12. //数字滤波 ? 13. #define a 0xF4 ? 14. // a=0.95 ? 15. #define b 0x0D ? 16. // b=1-a=0.05 ? 17. const led_table[16]={0xa0,0xfc,0xc1,0xd0,0x9c,0x92,0x82,0xf8,0x80,0x90,0x88,0x86,0xc7,0xc4,0x83,0x8b};// 0~~f ? 18. typedef unsigned char uint8; ? 19. uint8 value,value1=0; ? 20. int x; //最终的值 10位 ? 21. volatile uint8 i,j=0; ? 22. ? 23. //delay ? 24. /***********************************/ ? 25. void Delay100us(uint8 n) ? 26. { ? 27.?? uint8 i; ? 28.?? for(i=36;n!=0;n--)?? ? 29.?? while(--i); ? 30. } ? 31. ? 32. void Delay1s(uint8 n) ? 33. { ? 34.?? n=n*10; ? 35.?? for (;n!=0;n--){ ? 36.???? Delay100us(200); ? 37.?? } ? 38. } ? 39. /******************************/ ? 40. ? 41. void 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. //ADC initialize ? 54. // Conversion time: 225uS ? 55. void adc_init(void) ? 56. { ? 57. ADCSR = 0x00; //disable adc ? 58. ADMUX = 0xC0|(1ADLAR); // 2.56v 片内基准电压 /select adc input 0 / ? 59. ACSR = 0x80; // 使能adc可用,不用修改 ? 60. ADCSRA = 0xA8; // ADC使能,自动触发模式使能,触发源由SFIOR确定,中断使能,分频因子为2 ? 61. SFIOR = 0X60; // 触发源设置为:定时器比较匹配 ? 62. } ? 63. ? 64. //TIMER0 initialize - prescale:1024 ? 65. // WGM: Normal ? 66. // desired value: 1Hz ? 67. // actual value: 35.556mSec (-3455.6%) ? 68. void timer0_init(void) ? 69. { ? 70. TCCR0 = 0x00; //stop ? 71. TCNT0 = 0x01; //set count ? 72. OCR0 = 0x02; //set compare //FF ? 73. TCCR0 = 0x0D; //start timer 1024分频 CTC比较输出 定时时间:256/(7.3728Mhz/1024)=35.556ms ? 74. } ? 75. ? 76. #pragma interrupt_handler timer0_ovf_isr:10 ? 77. void t

文档评论(0)

1亿VIP精品文档

相关文档