Beispiel #1
0
// This function allows the program to pass an RX or TX mode flag for switching between modes on the
// half duplex UART serial communication line.
void commToggle(int mode)
{
	if(mode == RX_MODE)
	{
		// Stop from transmitting any more.
		TRANSMIT_Stop();
		// Write a constant high to the data bus.  This in combination with disconnecting the pin
		// from the global bus is to avoid a false start bit (a zero) when we unload the configuration.
		PRT0DR |= 0b10000000;
		// Disconnect P07 from the global bus.
		PRT0GS &= 0b01111111;
		// Unload the transmitter configuration.
		UnloadConfig_transmitter_config();
		// Load the receiver configuration.
		LoadConfig_receiver_config();
		// Reconnect to the global bus.
		PRT0GS |= 0b10000000;
		
		// If this module is configured, allow modules past this to listen on P27.
		// Otherwise, we make sure they're deaf.
		if((configured) && (!MASTER))
		{
			// Turn on relay-like object
			
			// Make sure the timer is off, although a config reload should have it off by default.
			Timer8_1_Stop();
		}
		else if((!configured) && (!MASTER))
		{
			// Turn off relay-like object.
			
			// Start response timeout timer and enable its interrupt routine.
			Timer8_1_EnableInt();
			Timer8_1_Start();
		}
		
		// Start the receiver.
		RECEIVE_Start(RECEIVE_PARITY_NONE);
	}
	else if(mode == TX_MODE)
	{
		// Stop receiving information.
		RECEIVE_Stop();
		// Disconnect from the global bus.
		PRT0GS &= 0b01111111;
		// Unload the receiver configuration.
		UnloadConfig_receiver_config();
		// Load the transmitter configuration.
		LoadConfig_transmitter_config();
		// Reconnect to the global bus.
		PRT0GS |= 0b10000000;
		// Start the transmitter.
		TRANSMIT_Start(TRANSMIT_PARITY_NONE);
	}
}
Beispiel #2
0
void init_timer(void){
	Timer8_1_EnableInt();
	Timer8_1_Start();
}