daily pastebin goal
18%
SHARE
TWEET

maxEmbedded Raghu Sensors

a guest Dec 16th, 2012 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/io.h>
  2.  
  3. void adc_init()
  4. {
  5. ADMUX=(1&lt;&lt;REFS0);
  6. ADCSRA=(1&lt;&lt;ADEN)|(1&lt;&lt;ADPS1);
  7. }
  8.  
  9.  
  10. uint16_t adc_read(uint8_t ch)
  11. {
  12. ch&amp;=0b00000111;
  13. ADMUX=(ADMUX &amp; 0XF8)|ch;
  14. ADCSRA|=(1&lt;&lt;ADSC);
  15. while(ADCSRA &amp; (1&lt;&lt;ADSC));
  16. return(ADC);
  17. }
  18.  
  19.  
  20.  
  21.  
  22. int main(void)
  23. {
  24. DDRC=0X00;
  25. DDRB=0XFF;
  26. DDRC=0XFF;
  27. DDRD=0XFF;
  28. adc_init();
  29. while(1)
  30. {
  31. OCR2B=adc_read(3);// adc value to output campare pin to generate pwm signal
  32.  
  33. }
  34. return(0);
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top