# Include <PIC. h> # define uchar unsigned char uchar rtemp, sflag; void serialinit (void) {txsta = 0x24; // enable the transmitting enable and high baud rate, the initial value of trmt can be 0 to 1 rcsta = 0x90; // enable serial port, continuous receiving, spbrg = 0x19; // 4 m crystal oscillator, baud rate 9600, then, the initial value of spbrg is 25 rcie = 1; // enable the serial port reception to complete the interruption. The gie = 1; // enable the global interruption peie = 1; // enable the first peripheral interrupt} void interrupt serialservice (void) // receives the interrupt {If (rcie & rcif) {rcif = 0; // indicates the number of rtemp = rcreg after receiving is cleared. // read and Receive Buffer sflag = 1 ;}} void main (void) {serialinit (); While (1) {If (sflag = 1) {rcie = 0; // disable receiving before sending Disallow bit sflag = 0; txreg = rtemp; // data sending buffer while (! Txif); // wait until the sending is completed. trmt is queried in the tutorial, and trmttxif = 0 is not cleared after sending. // The rcie = 1 flag is cleared; // enable allowed receiving interrupt when sending is complete }}}