New user here, and I need some serious help. I’m using an atmega168 to create a parking lot management tool. It has a flexforce sensor and photoelectric sensor (similar to a garage door sensor) as a way of seeing when a car enters or exits the lot. I’m using the ADC pins since the sensors give out a strictly analog signal and have set up my code as such so that it displays out to an LCD, which I will also be connecting wireless with a pair of Xbees. My code is as such:
void adc_init()
{
ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); //Enable ADC and set 128 prescale
}
int main(void)
{
ADCSRA |= 1<<ADPS2;
ADMUX |= 0<<REFS0 | 0<<REFS1;
ADCSRA |= 1<<ADIE; //enables the use of interrupts for the program
ADCSRA |= 1<<ADEN; //ADC enabled
sei();
ADCSRA |= 1<<ADSC;
while(1)
{
}
}
ISR(ADC_vect)
{
uint8_t Entrance = ADCL;
uint16_t Exit = ADCH<<8 | Entrance;
lcd_init();
FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE); //these functions are included in lcd.c and lcd.h to initialize the LCD
lcd_home();
uart_init();
FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); //these functions are in the UART include files and are used to send data from the uart to the lcd
stdin = stdout = &uart_stream;
int x = 0;
switch (ADMUX)
{
case 0xC0:
++x; //increment the counter to show a vehicle passed
fprintf_P(&lcd_stream, PSTR("Amt in lot:%d\n"), x);
lcd_line_one(); //clears the other LCD rows so that the output is only on the first line of the LCD
PORTB |= (1<<PB0);
delay_ms(10);
PORTB &= ~(1<<PB0);
ADMUX = 0xC1;
break;
case 0xC1:
--x;
fprintf_P(&lcd_stream, PSTR("Amt in lot:%d\n"), x);
lcd_line_one();
PORTB |= (1<<PB1);
delay_ms(10);
PORTD &= ~(1<<PD1);
ADMUX = 0xC0;
break;
default:
//Do nothing
break;
}
ADCSRA |= 1<<ADSC;
}
So I ran an Isis simulation using pot resisters as the two sensors, but I can’t get anything to run and nothing is displaying on the LCD. What am I doing wrong? :?: