BASIC4MCU | 질문게시판 | 답변 : atmega128 ADC 입력에 대한 코인형 진동모터 출력 질문입니다.
페이지 정보
작성자 master 작성일2022-12-02 10:23 조회675회 댓글0건본문
#define F_CPU 12000000UL
#include
#include
#include
#include
//
volatile int cnt=0,delayCnt=0,normal=0,danger=0,BACK=0,LEFT=0,RIGHT=0;
//
ISR(TIMER0_OVF_vect){
TCNT0=68;
//
if(cnt==0){ cnt=1; BACK =ADCW; ADMUX=0x41; }
if(cnt==1){ cnt=2; LEFT =ADCW; ADMUX=0x42; }
if(cnt==2){ cnt=0; RIGHT=ADCW; ADMUX=0x40;
delayCnt++;
if((BACK>LEFT)&&(BACK>RIGHT)){
if((BACK>normal)&&(BACK<=danger)){
if (delayCnt<=100){ PORTE=0x01; PORTB=0x01; }
else if(delayCnt<=150){ PORTB=0x00; }
else { delayCnt=0; }
}
}
if((LEFT>BACK)&&(LEFT>RIGHT)){
if((LEFT>normal)&&(LEFT<=danger)){
if (delayCnt<=50){ PORTB=0x02; }
else if(delayCnt<100){ PORTB=0x00; }
else { delayCnt=0; }
}
}
if((RIGHT>BACK)&&(RIGHT>LEFT)){
if((RIGHT>normal)&&(RIGHT<=danger)){
if (delayCnt<=50)){ PORTB=0x04; }
else if(delayCnt<100)){ PORTB=0x00; }
else { delayCnt=0; }
}
}
//
if((PINA&1)==0){ PORTC=1; normal=300; danger=500; }
if((PINA&2)==0){ PORTC=2; normal=400; danger=900; }
//
if (BACK< 500){ PORTE=0x00; }
else if(BACK< 700){ PORTE=0x01; }
else if(BACK<1000){ PORTE=0x02; }
else { PORTE=0x04; }
}
}
//
int main(void){
DDRA=0x00; // LED 스위치 입력 (A0,A1)
DDRC=0XFF; // LED 출력 (C0,C1)
DDRB = 0xff; // vibration motor output진동모터 출력
DDRD = 0xff;
DDRE = 0xff;
cli();
TCCR0=0x04; TCNT0=68; TIMSK=0x01;
ADCSRA=0xE7;
sei();
while(1){}
}
헤더파일 지워졌으니까 추가하시고
코드를 정리 해드렸으니까 다시 잘 체크 해보세요
댓글 0
조회수 675등록된 댓글이 없습니다.