BASIC4MCU | 질문게시판 | atmega128 센서값 led표현
페이지 정보
작성자 jasmint 작성일2019-12-02 16:51 조회3,489회 댓글0건본문
gp2y1014 센서를 구동하여 미세먼지 값을 나누어서 led로 표시할려고합니다!
빌드는 되던데 미세먼지 측정값을 led로 나누어 표현이 안됩니다.
어디를 수정해야되는지 조언 부탁드립니다!
#include <avr/io.h>
#include "ATmega128_v20.h"
#include "lcd_num.h"
#include "LCD.h"
int main(void){
int adc_val;
float volt;
float dust; //unsigned char str[50];
MCU_initialize();
Delay_ms(30);
LCDInit();
LCD_string(0x80," Donga ");
LCD_string(0xc0," Electronics ");
Delay_ms(1000);
LCD_string(0x80," ");
LCD_string(0xc0," ");
while(1){
PORTB = 0xF0;
Delay_ms(100);
PORTB&=~1;
Delay_us(280); // PA0,LED ON
adc_val=ad_conversion(6);
Delay_us(40);
PORTB|=1; // PC7,LED OFF
Delay_us(9680);
volt=(float)adc_val*5.0/1023.0; // 전압으로 변경
dust=((volt*0.17)-1); // 먼지농도 계산
Delay_ms(100);
LCD_string(0x84,"adc_val:");
LCD_string(0xc0,"dust:");
LCD_data(0x3A);
LCD_4d(adc_val);
LCD_data(0x3A);
LCD_4d(dust);
if(adc_val < 250)
{
PORTB = 0x80;
}
else if(adc_val < 500)
{
PORTB = 0x40;
}
else if(adc_val < 750)
{
PORTB = 0x20;
}
else if(adc_val < 1000)
{
PORTB = 0x10;
}
}
}
댓글 0
조회수 3,489등록된 댓글이 없습니다.