마이크로프로세서 - Motor Control with UART
본 자료는 3페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
해당 자료는 3페이지 까지만 미리보기를 제공합니다.
3페이지 이후부터 다운로드 후 확인할 수 있습니다.

목차

1. Introduction
2. Goal
3. Strategy
4. Process
5. Conclusion

본문내용

// FlushFileBuffers(hCom1);
// printf("Entering sendByte with parameter = %c\n", c);
// (void *) &c
if (!WriteFile(hCom1, (void *) &c,
1, &numBytes, NULL) || numBytes != 1) {
return -1;
}
// FlushFileBuffers(hCom1);
return 0;
}
/* sets the timeout for reading a byte
returns:
-6 on failure to set timeout
0 on success
(timeout is specified in milliseconds)
*/
int setreadtimeout(int initialTimeout){
COMMTIMEOUTS timeouts;
timeouts.ReadIntervalTimeout = 0;
timeouts.ReadTotalTimeoutMultiplier = initialTimeout;
timeouts.ReadTotalTimeoutConstant = 0;
if (!SetCommTimeouts(hCom1, &timeouts))
return (-6);
return 0;
}
// read a byte from serial port.
// returns 0 on success, -1 on failure or timeout.
int readword(unsigned char *ptr){
unsigned long numread=0;
ReadFile(hCom1, ptr, 1, &numread, NULL);
if (numread != 2)
return -1;
return 0;
}
void delay(clock_t sleep) // Delay 부분
{
clock_t cur = clock(), el;
for(;;){ // 무한루프
el = clock();
if((el - cur) > sleep)
break ;// 지정한 시간이 지나면 break
}
}
int main(void){// main 부분
int prompt, quit;
unsigned char rot, read_rot, temp;
while(1){
quit=0;
printf("1. ClockWise\n2. CounterClockWise\n3. Quit\nPrompt: ");
scanf("%d",&prompt);// 1, 2, 3의 선택을 받음
fflush(stdin);
switch(prompt){
case 1:// 1을 선택했을 경우 (CW)
printf("... Send Command 'CW' to AVR ...\n... Waiting ...\n");
openserial(1,2);// Serial Port 열기 명령
rot='r';// ‘r'은 CW 동작을 위한 데이터
sendword(rot);// ‘r'을 전송함
readword(&read_rot);
if(rot!=read_rot){
printf("Fail To Work!");// 동작 실패시 메시지 출력
break;
}
else{
printf("... Recive Sign 'CWOK' from AVR ...\n... OK\n");
delay(2000);// Delay를 2000만큼 줌
rot='s';// Delay후 자동으로 멈추게 함
sendword(rot);// ‘s'(멈추기) 전송
readword(&read_rot);
if(rot!=read_rot) printf("Fail to Stop!\n\n");
// 실패시 메시지 출력
else printf("Moter is Stopped\n\n");
closeserial();
break;
}
case 2:// 2을 선택했을 경우 (CCW)
printf("... Send Command 'CCW' to AVR ...\n... Waiting ...\n");
openserial(1,2);// Serial Port 열기 명령
rot='l';// ‘l'은 CCW 동작을 위한 데이터
sendword(rot);// ‘r'을 전송함
readword(&read_rot);
if(rot!=read_rot){
printf("Fail To Work!");// 동작 실패시 메시지 출력
break;
}
else{
printf("... Recive Sign 'CCWOK' from AVR ...\n... OK\n");
delay(2000);// Delay를 2000만큼 줌
rot='s';// Delay후 자동으로 멈추게 함
sendword(rot);// ‘s'(멈추기) 전송
readword(&read_rot);
if(rot!=read_rot) printf("Fail to Stop!\n\n");
// 실패시 메시지 출력
else printf("Moter is Stopped\n\n");
closeserial();
break;
}
case 3:// 프로그램 종료를 선택시
quit=1;// 종료 구문으로 이동
break;
default:
printf("Wrong Selection! Please Reselect!! \n\n");
// 기타 입력시 에러처리
break;
}
if(quit==1) {// 종료를 선택시
return 0;// 프로그램 종료
break;
}
}
}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
5. Conclusion
동작 결과 매뉴얼에서 요구한 사항을 모두 만족하였다.
1을 선택하면 CW 방향으로 모터가 돌아가다가 약간의 Delay후 멈추는 것을 확인할 수 있었으며, 2를 선택하면 CCW 방향으로 모터가 돌아가다가 마찬가지로 약간의 Delay후 멈추는 것을 확인할 수 있었고, 3을 선택하면 프로그램이 종료되는 것을 볼 수 있었다.
첫 프로젝트라서 쉬운 내용임에도 불구하고 Avredit나 Ponyprog등 프로그램을 새롭게 익혀야 했기 때문에 어려운 점이 많았다. Serial Port에 연결하는 케이블도 2개가 있어 어느 것을 어느 시기에 연결해야하는지 헷갈려 하기도 했다. 그래도 프로젝트를 성공적으로 마친 만큼, 다음 프로젝트는 더욱 자신 있게 할 수 있을 것이다.
  • 가격2,300
  • 페이지수11페이지
  • 등록일2008.02.27
  • 저작시기2007.3
  • 파일형식한글(hwp)
  • 자료번호#452392
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니