hi I am using 89c51. for using serial port I am using these commands
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ TMOD = 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ TH1 = 0xfd; /* TH1: reload value for 9600 baud */ TR1 = 1; /* TR1: timer 1 run */
these are working correctly ------------ but in main function i am calling 2 functions
for example ---------------------
void main() { while(1) { if(RI) { GetData(); } if(??????????) { DisplayData(); } } }
At the location "??????????" I want to call the DisplayData() after a specific clock period, for example after every 1000 clocks. is it possible to set the timer0 of 89c51 for this purpose.
Note that the above is not specific to the 8051 - the approach would work for any processor with a timer that can generate an interrupt.
Set up a timer to generate an interrupt at the required rate;
In the timer's Interrupt Service Routine, set a flag;
In the main loop, test this flag
void main() { while(1) { if(RI) { GetData(); } if( time_to_display_data ) { // The flag is set - it's time to display the data DisplayData(); // Clear the flag ready for next time... time_to_display_data = 0; } } }
Simples!
View all questions in Keil forum