示例#1
0
int main(void)
{
	char string[64];
	unsigned char count = 0;
	
	// run the initialization routines
	initializer();

   	 //Begin forever chatting with the PC
	 for(;;) 
	 {	
		// Check to see if a character is waiting
		if( isCharAvailable() == 1 )
		{
			// If a new character is received, get it
			string[count++] = receiveChar();
			
			// receive a packet up to 64 bytes long
			if(string[count-1] == '\n')// Hyperterminal string ends with \r\n
			{	
				string[count-2] = '\0'; //convert to a string
				parseInput(string);
				string[0] = '\0';
				count = 0;
			}
			else if(count > 64)
			{
				count = 0;
				string[0] = '\0';
				sendString("Error - received > 64 characters");			
			}		
		}
    }
	return 0;
}
示例#2
0
文件: comm.c 项目: HoboJ/avr
void getString ( char *string, unsigned char *flag )
{
    unsigned char count = 0;

    while ( 1 )
    {
        if ( isCharAvailable() == 1 )
        {
            *( string + count ) = receiveChar ();

            if ( *( string + count ) == '\r' || *( string + count ) == '\n' )
                break;
            else if ( count > 24 )
            {
                sendString ( "Error - received > 24 characters \r" );
                break;
            }

            count++;
        }
    }
}