| ??? 06/01/01 15:10 Read: times |
#12110 - RE: serial programming |
Hi Charles,
With C or C++ you can program the uart pretty much as if you were using assembler. First initialize the uart and timers, for example: /* Initialize T1 for baud rate generator */ TMOD = (TMOD & 0x0F) | 0x20; /* timer 1 mode 2 */ SCON = 0x50; /* uart mode 1 */ PCON = 0x00; /* SMOD = 0 */ TCLK = RCLK = 0; /* not using T2 */ TR1 = 0; /* stop timer */ TH1 = TL1 = 0xFD; /* 9600 baud */ TR1 = 1; /* restart timer */ ES = 1; /* enable sio int */ (Sorry, the comments wrapped around, not as readable as on my editor). Then either create a serial interrupt service routine or simply poll the RI/TI flags. A simple ISR: interrupt [0x0023] void SCON_int (void) { if (TI) { TI = 0; /* reset flag */ SBUF = next_character_to_send; } if (RI) { RI = 0; received_character = SBUF; } } The 8051 C compilers I've seen have pre-defined header files for registers and such. Good luck! Dennis |
| Topic | Author | Date |
| serial programming | 01/01/70 00:00 | |
| RE: serial programming | 01/01/70 00:00 | |
| RE: serial programming | 01/01/70 00:00 | |
RE: serial programming | 01/01/70 00:00 |



