atmega128 온도센서 이용 모터 제어 질문드립니다.
페이지 정보
작성자 우와우와웅 작성일19-12-09 14:09 조회5,677회 댓글0건본문
온도센서를 이용하여 선풍기를 제어하는것을 공부중입니다...이때 lcd에 온도를 표현 한 후 30도 이상일 경우 모터가 작동되는 것을 구현하고 싶은데 안되네요..
회로도도 첨부합니다!
근데 에러가
avr-gcc -mmcu=atmega128 -Wl,-Map=test1.map test1.o -o test1.elf
c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr51/crtm128.o: file not recognized: File format not recognized
make: *** [test1.elf] Error 1
Build failed with 1 errors and 7 warnings...
#ifndef F_CPU
#define F_CPU 1600000UL
#define LCD_DISP_ON_CURSOR
#endif
#include <avr/io.h>
#include <util/delay.h>
void adc_init()
{
// AREF = AVcc
ADMUX = (1<<REFS0);
// ADC Enable and prescaler of 128
ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
}
// read adc value
uint16_t adc_read(uint8_t ch)
{
// select the corresponding channel 0~7
ch &= 0b00000111; // AND operation with 7
ADMUX = (ADMUX & 0xF8)|ch;
// start single conversion
// write '1' to ADSC
ADCSRA |= (1<<ADSC);
// wait for conversion to complete
// ADSC becomes '0' again
while(ADCSRA & (1<<ADSC));
return (ADC);
}
int main()
{
DDRB=0xff;
uint16_t adc_result0;
int temp;
int far;
char buffer[10];
// initialize adc and lcd
adc_init();
lcd_init(LCD_DISP_ON_CURSOR); //CURSOR
lcd_clrscr();
lcd_gotoxy(0,0);
_delay_ms(50);
while(1)
{
adc_result0 = adc_read(0); // read adc value at PA0
temp=adc_result0/2.01; // finding the temperature
//lcd_gotoxy(0,0);
//lcd_puts("Adc=");
//itoa(adc_result0,buffer,10); //display ADC value
//lcd_puts(buffer);
lcd_gotoxy(0,0);
itoa(temp,buffer,10);
lcd_puts("Temp="); //display temperature
lcd_puts(buffer);
lcd_gotoxy(7,0);
lcd_puts("C");
far=(1.8*temp)+32;
lcd_gotoxy(9,0);
itoa(far,buffer,10);
lcd_puts(buffer);
lcd_gotoxy(12,0);
lcd_puts("F");
_delay_ms(1000);
if(temp>=30)
{lcd_clrscr();
lcd_home();
lcd_gotoxy(0,1);
lcd_puts("FAN ON");
PORTB=(1<<PINB0);
}
if (temp<=30)
{
lcd_clrscr();
lcd_home();
lcd_gotoxy(7,1);
lcd_puts("FAN OFF");
PORTB=(0<<PINB0);
}
}
}
댓글 : 0
조회수 : 5,677
등록된 댓글이 없습니다.