سلام ببین این به دردت می خوره.
قبلا با این کتابخونه سنسور MQ2 را راه اندازی کردم و مشکلی نداشته.(البته با AVRSTUDIO)
[PHP]#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
#include "global.h"
#include "a2d.h"
#define F_CPU 1000000UL
const uint8_t LCDwelcomeln1[] PROGMEM="POORIA";
void program( uint8_t adc_result){
if (adc_result>180){
PORTD=0x3;
}
else {
PORTD=0;
};
}
int main(void)
{
uint8_t adc_result;
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
LCDcursorOFF();
a2dInit();
DDRA = 0x00;
DDRD = 0xFF;
// make sure pull-up resistors are turned off
PORTA = 0x00;
// set the a2d prescaler (clock division ratio)
// - a lower prescale setting will make the a2d converter go faster
// - a higher setting will make it go slower but the measurements
// will be more accurate
// - other allowed prescale values can be found in a2d.h
a2dSetPrescaler(ADC_PRESCALE_DIV8);
// set the a2d reference
// - the reference is the voltage against which a2d measurements are made
// - other allowed reference values can be found in a2d.h
a2dSetReference(ADC_REFERENCE_AVCC);
a2dSetChannel(0);
a2dStartConvert();
LCDGotoXY(1,0);
LCDstring("POORIA_A",8);
LCDGotoXY(1,1);
LCDstring("MAGID_BA",8);
_delay_ms(2000);
LCDclr();//clears LCD
while(1)
{
LCDGotoXY(0,0);
LCDstring("L ",8);
LCDGotoXY(8,0);
LCDstring("M",1);
LCDGotoXY(15,0);
LCDstring("D",1);
LCDGotoXY(0,1);
LCDprogressBar(a2dConvert8bit(0),255,16);
adc_result=a2dConvert8bit(0); // Read Analog value from channel-0
//LCDGotoXY(2,0);
//LCDWriteInt(adc_result,4); //Print the value in 4th column second line
program(adc_result);
_delay_ms(100);
}
}[/PHP]