Serial Port Complete - Latest Microcontroller projects

(lily) #1
An RS-485 Network

If delay_before_responding isn’t defined, the timer never starts and communi-
cations never enter the “d” state.

 prepare_to_respond:


response_index = 0;
if (delay_before_responding = 1) then
gosub start_response_delay_timer
network_state = "d"
else
network_state = "t"
endif
return

 void prepare_to_respond(void)
{
response_index = 0;
#if defined(delay_before_responding)
start_response_delay_timer();
network_state = 'd';
#else
network_state = 't';
#endif
}
The start_response_delay_timer function initializes and starts the timer.


 start_response_delay_timer:


' This example sets a delay of around 0.5 second assuming FOSC = 4 MHz.

' Timer enabled, 16-bit, internal clock, prescaler = 256.

T0CON = $87

' Load the timer with F800h.

TMR0L = $00
TMR0H =$F8

return
Free download pdf