szak1592
Newbie level 1
I have interfaced a single sensor and the code works, but when I try to interface two sensors at the same time, the simulation does not work at all. Please check the code and the simulation schematic in proteus and let me know what is wrong in the code. Here is the link to the proteus schematic screenshot
**broken link removed**
#define F_CPU 4000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
int main(void)
{
DDRC = 0xff;
DDRD = 0xff;
DDRA = 0x00;
ADMUX=0x00;
//ADMUX |= 1<<REFS0 | 1<<REFS1;
ADCSRA |= 1<<ADIE;
ADCSRA |= 1<<ADEN;
sei();
ADCSRA |= 1<<ADSC;
while (1);
return 0;
}
ISR(ADC_vect)
{
uint16_t adc_value;
uint16_t adc_value_2;
switch (ADMUX) {
case (0xC0):
// ADCSRA |= (1<<(ADSC));
// while ((ADCSRA &(1<<ADIF))==0);
adc_value=ADC;
if (adc_value<512)
{
PORTC = PORTC & 0b11111110;
}
else
{
PORTC = PORTC | 0b00000001;
}
//ADMUX = 0xE1;
break;
case (0xC1):
adc_value_2=ADC;
if (adc_value<512)
{
PORTC = PORTC & 0b11111101;
}
else
{
PORTC = PORTC | 0b00000010;
}
//ADMUX = 0xE1;
break;
default:
break; }
ADCSRA |= 1<<ADSC;
}
**broken link removed**
#define F_CPU 4000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
int main(void)
{
DDRC = 0xff;
DDRD = 0xff;
DDRA = 0x00;
ADMUX=0x00;
//ADMUX |= 1<<REFS0 | 1<<REFS1;
ADCSRA |= 1<<ADIE;
ADCSRA |= 1<<ADEN;
sei();
ADCSRA |= 1<<ADSC;
while (1);
return 0;
}
ISR(ADC_vect)
{
uint16_t adc_value;
uint16_t adc_value_2;
switch (ADMUX) {
case (0xC0):
// ADCSRA |= (1<<(ADSC));
// while ((ADCSRA &(1<<ADIF))==0);
adc_value=ADC;
if (adc_value<512)
{
PORTC = PORTC & 0b11111110;
}
else
{
PORTC = PORTC | 0b00000001;
}
//ADMUX = 0xE1;
break;
case (0xC1):
adc_value_2=ADC;
if (adc_value<512)
{
PORTC = PORTC & 0b11111101;
}
else
{
PORTC = PORTC | 0b00000010;
}
//ADMUX = 0xE1;
break;
default:
break; }
ADCSRA |= 1<<ADSC;
}