??? 04/07/09 13:06 Modified: 04/07/09 13:19 Read: times |
#164456 - reply Kai Responding to: ???'s previous message |
Below is a portion of the main code.
/////////////////////////////////////////////////////////////////////// while(1) { if (STATE==1) { OutChar('C'); OutChar('R'); OutChar(' '); OutChar('1'); OutChar('8'); OutChar(' '); OutChar('3'); OutChar('2'); OutChar(' '); OutChar('1'); OutChar('7'); OutChar(' '); OutChar('0'); OutChar(' '); OutChar('1'); OutChar('9'); OutChar(' '); OutChar('3'); OutChar('3'); OutChar(13); i=0; while(SBUF!=':') { while(!RI); RI=0; TrmBuf[i]=SBUF; i++; } if((TrmBuf[0]=='A')&& (TrmBuf[1]=='C')&& (TrmBuf[2]=='K')) { STATE++; } else { STATE=1; } } . . . . if (STATE == 2) . . . . and so on } ////////////////////////////////////////////////////////////////////////////////////////////// outchar is used to send ASCII characters as following: void OutChar(unsigned char c) { while(!TI); TI=0; SBUF=c; } ////////////////////////////////////////////////////////////////////////////////////////// TrmBuf is a array character use to store the receive ASCII character. Then I have to check on receive character is either ACK or NCK to determine on next state. Baudrate is 9600 for cmucam2 and 8051. pool mode is used which means one instruction will feedback one message. For example above, ASCII character of 'CR 18 44 17 2 19 31'is send then immediately either 'ACK' or 'NCK' is receive. Similiar things are in the next few stage but ASCII characters are different in terms of number. In the last stage, it contains the keyword to move the stepper motor in different direction.(when interrupt occurs the keyword is bring to ISR) Timer 2 is used as counter and interrupt for every 1ms. Stepper motor moves smoothly (which is not stated in above)just the operation cameraa is not working. I have change the timer value but it still cant works. This struggles and tortures me very much T_T. |