BASIC4MCU | 질문게시판 | 답변 : while문 안 if문 빠져나오는 방법
페이지 정보
작성자 master 작성일2022-05-16 07:19 조회1,266회 댓글1건본문
#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>
//
#define CDS_10 341
//
#define MOTOR_CW 0xd0
#define MOTOR_CCW 0x70
#define MOTOR_BRAKE 0xd0
#define MOTOR_STOP 0x30
#define NULL 0
//
char One[]="BLUETOOTH MODE";
char Two[]="STOP";
char Three[]="DOWN";
char Four[]="UP";
char re[]="retry";
//
char getch1(){ if(UCSR1A&0x80)return UDR1; }
void putch1(char c){ while(!(UCSR1A &(1<<UDRE1))); UDR1=c; }
void puts1(char *s){ while(*s)putch1(*s++); }
//
int main(void){
char c,mode=0;; int value;
DDRB=0xf0; DDRA=0x0f;
UCSR1B=0x18; UBRR1L=8;
ADMUX=0x40; ADCSRA=0xE7;
while(1){
if(UCSR1A&0x80){
c=UDR1;
if(c=='1'){ mode=1; }
if(c=='2'){ mode=0; PORTB=MOTOR_STOP; }
if(c=='3'){ mode=0; PORTB=MOTOR_CW; }
if(c=='4'){ mode=0; PORTB=MOTOR_CCW; }
}
//
if(mode){
_delay_ms(1); value=ADCW; // value=ADC;
if(value<=CDS_10){ PORTB=MOTOR_CW; PORTA=0x01; }
else { PORTB=MOTOR_CCW; PORTA=0x02; }
}
}
}
질문 코드에서 문제가 될만한 것을 발견하지 못하였습니다.
시리얼 데이터를 전송하는 곳에서 '1' 다음에 LF,CR 등의 문자가 추가되는 것으로 생각됩니다.
이 코드로 돌려보세요
댓글 1
조회수 1,266kyho3855님의 댓글
kyho3855 작성일
올려주신 답변이 문제를 해결하는데 큰 도움이 되었고 많이 배워갑니다.
답변해주셔서 감사드립니다.