Hi, I'm trying to simulate working of a UART. When I write into SBUF, the TI flag doesn't go high even though I have enabled interrupts. Is there any way I can simulate it using SOUT VTREG. can't find example how to use SOUT.
The same code which I posted above, the same when modified as shown below works. The only difference between the two which brings the change is the for loop inside the main(). I am not sure why this delay is needed but then with this delay I am able to see 'Y' getting repeatedly displayed on the com port. Any idea as to why this delay is needed or what am I doing wrong? If I could get the same code modified with corrections then it would help in understanding. ------------------------------------------- #include <AT89S52.H> void serial_int (void) interrupt 4 { if (RI == 1) /* it was a receive interrupt */ { RI = 0; /* clear the received interrupt flag */ } else if (TI == 1) /* otherwise, assume it was a transmit interrupt */ { TI = 0; /* clear the transmit interrupt flag */ } } void main(void) { SCON = 0x50; /* mode 1, 8-bit uart, enable receiver */ TMOD = 0x20; /* timer 1, mode 2, 8-bit reload */ TH1 = 0xFD; /* reload value for 2400 baud */ ET0 = 0; /* we don't want this timer to make interrupts */ TR1 = 1; /* start the timer */ TI = 1; /* clear the buffer */ ES = 1; /* allow serial interrupts */ EA = 1; /* enable interrupts */ while (1) { unsigned int i; for (i = 0; i < 120; i++) {;} /* delay */ SBUF = 'Y'; } } ---------------------------------------