Listing 1—The routine in charge of transmitting the code word invokes WAIT_MODE to wait one-third bit time in Low Power mode. TX_ON and TX_OFF macros drive the RF module. The hardware.h file hides implementation details for the macros, making the code easier to read.

static void rf_encoder(unsigned int codeword)
{
	unsigned int mask;
	//Prepare for timer overflow every 0.33 ms (a bit third)
	//Overflow will wake up from Wait mode
  TMOD = CLOCK_FREQ * BIT_THIRD_DURATION;

	//Prepare mask for filtering leftmost bit
	mask = 1 << (CODE_BITS - 1);
	while( mask != 0 )
	{
		TSC_TSTOP = 0;	//Restart timer
		WAIT_MODE; 	//Go in low-power mode until a 0.33-ms 
					//period expires.
		if ( (codeword & mask) == 0 )
					//Are you transmitting a zero?
			TX_ON;	//Yes, force a 66% duty cycle.
		WAIT_MODE;	//Go in low-power mode until a 0.33-ms 
					//period expires.
		TX_ON;		//Set output to ensure a duty cycle no 
					//less than 33%.
		WAIT_MODE;	//Go in low-power mode until a 0.33-ms 
					//period expires.
		TX_OFF;		//Turn off transmitter 
		mask >>= 1;	//Prepare mask for filtering next bit.
    };
    TSC_TSTOP = 1;	//Stop timer before exit to reduce power 
					//consumption.
}