Keil C51 character echo test for UART1


/ Published in: C
Save to your folder(s)

From Keil C51 examples, TEST.C: ISD51 Demo for TI MSC 1210.
Polled (non-interrupt) mode.

Work-around for dropped-characters related to stop-bit problem: Clear SCON1.5 (or SM2_1).


Copy this code and paste it in your HTML
  1. void TestSerial(void)
  2. {
  3. // for UART1, use TI_1, RI_1 and SBUF1.
  4. // for UART0, use TI, RI and SBUF.
  5.  
  6. char c = 'A';
  7.  
  8. TI_1 = 1;
  9. while (1) // forever.
  10. {
  11. if (RI_1) // if a char is ready...
  12. {
  13. c = SBUF1; // Read a char.
  14. RI_1 = 0; // Indicate that we've read the char.
  15. }
  16. while (!TI_1) {;} // wait for TX to be ready.
  17. TI_1 = 0;
  18. SBUF1 = c; // Send a char
  19. }
  20. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.