Listing 1—This is a sample of what happens in the command handler. First, the command is determined and then the appropriate case handles the data or parameters.

 

void processCommand(void)
{
	int tempInt;
	char tempChar;
	int readBufferIndex;
	//int aoBufferIndex;
	tempChar = *readBuffer; //get fist char from global read buffer
	tempChar = toupper(tempChar); //ensure upper case for switch statement
	tempInt = atoi(readBuffer + 1); //read integer value if command has one
	switch(tempChar)	
	{
			case ‘A’: //set up pwm values and run the pwm
	{
				PWMTCR = 0x0000002; //counter reset
				PWMMR0 = tempInt; //set period
				PWMMR2 = (tempInt / 10); //set PWM2 (P0.7) duty to 10%
				PWMMR5 = ((tempInt / 10) * 8); //set PWM5 (P0.21) duty to 80%
				PWMTCR = 0x00000009; //Enable counter and PWM
				IOSET1 |= 0x00020000; //P1.17 LED ON (PWM enabled)
				break;
			}
			case ‘B’: //disable pwm
			{
				PWMTCR = 0x0000002; //counter reset (disable PWM outputs)
				IOCLR1 |= 0x00020000; //P1.17 LED OFF (PWM disabled)
				break;
			}