Advertisement
ivosexa

sens

Oct 23rd, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #define F_CPU 1000000UL
  2. #include <avr/io.h>
  3. #include <avr/interrupt.h>
  4. #include "LCD4b.h"
  5. #include <unit/delay.h>
  6. #include <math.h>
  7.  
  8.  
  9. void red();
  10.  
  11. int main(void)
  12. {
  13. int distance;
  14.  
  15.  
  16. InitalizeLCD();
  17. SendStringToLocation(1,1,"Distance in cm:");
  18.  
  19. ADCSRA |= 1<<ADPS2;
  20. ADMUX |= 0b00000101;
  21. ADCSRA |= 1<<ADIE;
  22. ADCSRA |= 1<<ADEN;
  23.  
  24. sei();
  25.  
  26. ADCSRA |= 1<<ADSC;
  27.  
  28.  
  29.  
  30.  
  31. while (1)
  32. {
  33.  
  34.  
  35.  
  36. }
  37. }
  38.  
  39.  
  40. ISR(ADC_vect)
  41. {
  42. int theLowADC = ADCL;
  43. int theTenBitResults = ADCH<<8 | theLowADC;
  44.  
  45. float volts = ((theTenBitResults)*0.0048828125) ;
  46. int distance = (-10 + (65*pow(volts, -1.10)));
  47.  
  48.  
  49.  
  50. SendIntegerToLocation(1,2,distance);
  51. _delay_ms(50);
  52.  
  53.  
  54. ADCSRA |= 1<<ADSC;
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement