We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
There is a string buffer referenced by both an ISR and the main(). The ISR collects a sentence from UART and put it into the buffer. Once the received sentence is completed a flag is raised. The main() checks the flag and copies the sentence to another buffer. The code is like
unsigned char xdata RxBuffer[]; unsigned char xdata buffer[]; bit RxFlag = 0; void uart( void ) { //receive data from sbuf RxBuffer[] = sbuf; //if done RxFlag = 1; } void main( void ) { while( 1 ) { if( RxFlag ) strcpy( buffer, RxBuffer ); } }
"Should I declare RxBuffer as volatile?" Yes. "RxFlag doesn't need to be volatile" Yes it does, although it may be the case that bit variables are implicitly volatile in Keil. I'm not sure. To the compiler 'volatile' essentially means "don't optimise any usage of this variable". "Does the reentrancy play any significant role here" No, as you are not calling functions from your ISR. "What is the difference between memcpy() and strcpy()? What are the advantages and disadvatages on each?" memcpy() copies the specified number of bytes from source to destination, strcpy() copies bytes until the first zero byte in source. Check your C book. Stefan