The code in the ADC channels are updated to reflect the slope intercept formula so the trimmer potentiometers show a range or 0 - 33 rather than the raw ADC result of 0 - 1023.
#include <avr/io.h>
#include "MrLCD.h"
#include <avr/interrupt.h>
int static volatile InchesOfHg, High, Low = 0;
int main(void)
{
InitializeMrLCD();
Send_A_StringToMrLCDWithLocation(1, 1, "Inches of Hg:");
Send_A_StringToMrLCDWithLocation(1, 2, "H: L:");
DDRD |= 1<<PIND0;
ADCSRA |= 1<<ADPS2;
ADMUX |= 1<<REFS0;
ADCSRA |= 1<<ADIE;
ADCSRA |= 1<<ADEN;
sei();
ADCSRA |= 1<<ADSC;
uint8_t enoughVacuum = 0;
while (1)
{
if (InchesOfHg > High) enoughVacuum = 1;
if (InchesOfHg < Low) enoughVacuum = 0;
if (enoughVacuum == 0 && bit_is_clear(PORTD, PIND0)) PORTD |= 1<<PIND0;
if (enoughVacuum == 1 && bit_is_set(PORTD, PIND0)) PORTD &= ~(1<<PIND0);
}
}
ISR(ADC_vect)
{
uint8_t theLowADC = ADCL;
uint16_t TenBitResult = ADCH<<8 | theLowADC;
switch (ADMUX)
{
case 0x40:
InchesOfHg = -0.0376 * TenBitResult + 35.532;
Send_An_IntegerToMrLCD(15, 1, InchesOfHg, 4);
ADMUX = 0x41;
break;
case 0x41:
High = .034 * TenBitResult -.68;
Send_An_IntegerToMrLCD(4, 2, High, 3);
ADMUX = 0x42;
break;
case 0x42:
Low = .034 * TenBitResult -.68;
Send_An_IntegerToMrLCD(14, 2, Low, 3);
ADMUX = 0x40;
break;
default:
//Default code
break;
}
ADCSRA |= 1<<ADSC;
}
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.