목차
1. Introduction
2. Goal
3. Strategy
4. Process
5. Conclusion
2. Goal
3. Strategy
4. Process
5. Conclusion
본문내용
d=whatever, 8 data bits, no parity, 1 stop bit.
dcb.BaudRate = baudRate;
dcb.fBinary = TRUE;
dcb.fParity = FALSE;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
fSucess = SetCommState(hCom, &dcb);
if (!fSucess) {
return (-3);
}
hCom1 = hCom;
return (0);
}
int closeserial() {
CloseHandle(hCom1);
return(0);
}
// sends a byte to the serial port. returns 0 on success and -1 on failure.
// 기존에 존재하던 sendword function을 1 byte만 전송하도록 수정하였다.
int sendword(unsigned char c){
unsigned long numBytes = 1;
// PurgeComm(hCom1, PURGE_RXCLEAR);
// 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.
// 기존에 존재하던 readword function을 1 byte만 읽어들이게 수정하였다.
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)
{
clock_t cur = clock(), el;
for(;;){ // 무한루프를 돌린다.
el = clock();
if((el - cur) > sleep)
break ;
}
} // Delay주는 함수
int main(void){
int prompt, quit;
unsigned char rot, read_rot, temp;
while(1){
quit=0;
printf("1. ClockWise\n2. CounterClockWise\n3. Quit\nPrompt: ");
scanf("%d",&prompt);
fflush(stdin);
switch(prompt){
case 1:
printf("... Send Command 'CW' to AVR ...\n... Waiting ...\n");
openserial(1,2);
rot='r';
sendword(rot);
readword(&read_rot);
if(rot!=read_rot){
printf("Fail To Work!");
break;
}
else{
printf("... Recive Sign 'CWOK' from AVR ...\n... OK\n");
delay(2000);
rot='s';
sendword(rot);
readword(&read_rot);
if(rot!=read_rot) printf("Fail to Stop!\n\n");
else printf("Moter is Stopped\n\n");
closeserial();
break;
}
case 2:
printf("... Send Command 'CCW' to AVR ...\n... Waiting ...\n");
openserial(1,2);
rot='l';
sendword(rot);
readword(&read_rot);
if(rot!=read_rot){
printf("Fail To Work!");
break;
}
else{
printf("... Recive Sign 'CCWOK' from AVR ...\n... OK\n");
delay(2000);
rot='s';
sendword(rot);
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
아래와 같은 결과를 얻을 수 있다.
55를 입력하고 7번의 Guess로 맞출 수 있었다.
이번 lab을 통하여 여러 가지를 배울 수 있었다. C를 배웠을 때 가장 기본적이고 중요한 부분이었던 if문과 for문 등을 어셈블리어로는 어떻게 구현하나 궁금했었는데, 이번 lab으로 약간은 해결된 느낌이다.
dcb.BaudRate = baudRate;
dcb.fBinary = TRUE;
dcb.fParity = FALSE;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
fSucess = SetCommState(hCom, &dcb);
if (!fSucess) {
return (-3);
}
hCom1 = hCom;
return (0);
}
int closeserial() {
CloseHandle(hCom1);
return(0);
}
// sends a byte to the serial port. returns 0 on success and -1 on failure.
// 기존에 존재하던 sendword function을 1 byte만 전송하도록 수정하였다.
int sendword(unsigned char c){
unsigned long numBytes = 1;
// PurgeComm(hCom1, PURGE_RXCLEAR);
// 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.
// 기존에 존재하던 readword function을 1 byte만 읽어들이게 수정하였다.
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)
{
clock_t cur = clock(), el;
for(;;){ // 무한루프를 돌린다.
el = clock();
if((el - cur) > sleep)
break ;
}
} // Delay주는 함수
int main(void){
int prompt, quit;
unsigned char rot, read_rot, temp;
while(1){
quit=0;
printf("1. ClockWise\n2. CounterClockWise\n3. Quit\nPrompt: ");
scanf("%d",&prompt);
fflush(stdin);
switch(prompt){
case 1:
printf("... Send Command 'CW' to AVR ...\n... Waiting ...\n");
openserial(1,2);
rot='r';
sendword(rot);
readword(&read_rot);
if(rot!=read_rot){
printf("Fail To Work!");
break;
}
else{
printf("... Recive Sign 'CWOK' from AVR ...\n... OK\n");
delay(2000);
rot='s';
sendword(rot);
readword(&read_rot);
if(rot!=read_rot) printf("Fail to Stop!\n\n");
else printf("Moter is Stopped\n\n");
closeserial();
break;
}
case 2:
printf("... Send Command 'CCW' to AVR ...\n... Waiting ...\n");
openserial(1,2);
rot='l';
sendword(rot);
readword(&read_rot);
if(rot!=read_rot){
printf("Fail To Work!");
break;
}
else{
printf("... Recive Sign 'CCWOK' from AVR ...\n... OK\n");
delay(2000);
rot='s';
sendword(rot);
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
아래와 같은 결과를 얻을 수 있다.
55를 입력하고 7번의 Guess로 맞출 수 있었다.
이번 lab을 통하여 여러 가지를 배울 수 있었다. C를 배웠을 때 가장 기본적이고 중요한 부분이었던 if문과 for문 등을 어셈블리어로는 어떻게 구현하나 궁금했었는데, 이번 lab으로 약간은 해결된 느낌이다.
키워드
추천자료
[컴문서]-어셈블러를 이용한 여러 응용출력문
Switching기술과 표준화 설명
[Wireless Control Micromouse] 무선 조정 마이크로마우스 with VHDL
라인트레이서-메인보드파트
Oracle9i 서버 구축 and 테스트
기계공작법
Biped Robot 제작
VHDL을이용한 2X4디코더, 4X2인코더 실험보고서
2비트 감산기, 4비트 가감산기
마이크로 프로세서 프로젝트 최종보고서
[마이크로 프로세서 및 실습 Ⅰ] 8051 어셈블리어를 이용한 자동인식거울
[논리회로설계] vhdl을 이용한 도어락(door lock) 설계
[전기,전자과] 졸업작품 인체감지선풍기 한학기간발표자료(ppt 7개 및 hwp 최종보고서)