Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 1000000UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include "LCD4b.h"
- #include <unit/delay.h>
- #include <math.h>
- void red();
- int main(void)
- {
- int distance;
- InitalizeLCD();
- SendStringToLocation(1,1,"Distance in cm:");
- ADCSRA |= 1<<ADPS2;
- ADMUX |= 0b00000101;
- ADCSRA |= 1<<ADIE;
- ADCSRA |= 1<<ADEN;
- sei();
- ADCSRA |= 1<<ADSC;
- while (1)
- {
- }
- }
- ISR(ADC_vect)
- {
- int theLowADC = ADCL;
- int theTenBitResults = ADCH<<8 | theLowADC;
- float volts = ((theTenBitResults)*0.0048828125) ;
- int distance = (-10 + (65*pow(volts, -1.10)));
- SendIntegerToLocation(1,2,distance);
- _delay_ms(50);
- ADCSRA |= 1<<ADSC;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement