BASIC4MCU | 센서 | 가스센서 | 알콜센서 MQ-3 & MQ-6
페이지 정보
작성자 키트 작성일2017-08-29 14:28 조회2,440회 댓글0건본문
좌우 바뀌어도 상관 없습니다.
가운데 홈 파인것 기준으로 위처럼 연결 합니다.
//=======================================================
#include
#include
float ADC_F;
int ADC_I;
void main(void){
DDRB=0xFF;
ADMUX=0x40; ADCSRA=0xE7; //프리런닝 ADC0 한개만 사용 함
while(1){
delay_us(250); // 변환시간동안 딜레이
ADC_I=ADCW;
ADC_F=(float)ADC_I*5.0/1023.0; // 0V~5.0V 전압으로 변환
if (ADC_F<1.7)PORTB=0x00; // 0.0 ~ 1.7 포트B=0x00 1단계
else if(ADC_F<3.4)PORTB=0x0F; // 1.7 ~ 3.4 포트B=0x0f 2단계
else PORTB=0xFF; // 3.4 ~ 5.0 포트B=0xFf 3단계
}
}
//=======================================================
#include
#include
float ADC_F;
int ADC_I;
void main(void){
DDRB=0xFF;
ADMUX=0x40; ADCSRA=0xE7; //프리런닝 ADC0 한개만 사용 함
while(1){
delay_us(250); // 변환시간동안 딜레이
ADC_I=ADCW;
ADC_F=(float)ADC_I*5.0/1023.0; // 0V~5.0V 전압으로 변환
if (ADC_F<1.0)PORTB=0x00; // 0.0 ~ 1.0 포트B=0x00 1단계
else if(ADC_F<2.0)PORTB=0x0F; // 1.0 ~ 2.0 포트B=0x0f 2단계
else if(ADC_F<3.0)PORTB=0x0F; // 2.0 ~ 3.0 포트B=0x0f 3단계
else if(ADC_F<4.0)PORTB=0x0F; // 3.0 ~ 4.0 포트B=0x0f 4단계
else PORTB=0xFF; // 4.0 ~ 5.0 포트B=0xFf 5단계
}
}
//=======================================================
#include
#include
//#asm
.equ __lcd_port=0x1B ;포트A
#endasm#include
//
float ADC_F;
int ADC_I;
//
void main(void){
DDRA=0xFF;lcd_init(16); // lcd초기화
ADMUX=0x40; ADCSRA=0xE7; //프리런닝 ADC0lcd_gotoxy(0, 0); lcd_putsf("cafe.naver.com");
while(1){
ADC_I=ADCW;
ADC_F=(float)ADC_I*5.0/1023.0; // 0V~5.0V
lcd_gotoxy(0, 1);if (ADC_F<1.7)lcd_putsf("Ok! "); //0.0~1.7
else if(ADC_F<3.4)lcd_putsf("License Stop! "); //1.7~3.4
else lcd_putsf("License Cancle! "); //3.4~5.0
delay_ms(250); // delay
}
}////=======================================================
#include
#define F_CPU 16000000UL // 16 MHz#include
float ADC_F;
int ADC_I;
int main(void){
DDRB=0xFF;
ADMUX=0x40; ADCSRA=0xE7; //프리런닝 ADC0 한개만 사용 함while(1){
_delay_us(250); // 변환시간동안 딜레이
ADC_I=ADCW;
ADC_F=(float)ADC_I*5.0/1023.0; // 0V~5.0V 전압으로 변환
if (ADC_F<1.7)PORTB=0x00; // 0.0 ~ 1.7 포트B=0x00 1단계
else if(ADC_F<3.4)PORTB=0x0F; // 1.7 ~ 3.4 포트B=0x0f 2단계
else PORTB=0xFF; // 3.4 ~ 5.0 포트B=0xFf 3단계
}
}
//=======================================================
#include
#define F_CPU 16000000UL // 16 MHz#include
float ADC_F;
int ADC_I;
int main(void){
DDRB=0xFF;
ADMUX=0x40; ADCSRA=0xE7; //프리런닝 ADC0 한개만 사용 함
while(1){
_delay_us(250); // 변환시간동안 딜레이
ADC_I=ADCW;
ADC_F=(float)ADC_I*5.0/1023.0; // 0V~5.0V 전압으로 변환
if (ADC_F<1.0)PORTB=0x00; // 0.0 ~ 1.0 포트B=0x00 1단계
else if(ADC_F<2.0)PORTB=0x0F; // 1.0 ~ 2.0 포트B=0x0f 2단계
else if(ADC_F<3.0)PORTB=0x0F; // 2.0 ~ 3.0 포트B=0x0f 3단계
else if(ADC_F<4.0)PORTB=0x0F; // 3.0 ~ 4.0 포트B=0x0f 4단계
else PORTB=0xFF; // 4.0 ~ 5.0 포트B=0xFf 5단계
}
}
//=======================================================
Avcc는 5V에 연결 합니다.
시판중인 모듈의 내부 회로도입니다.
댓글 0
조회수 2,440등록된 댓글이 없습니다.