Hi..
I write a DLL to simulate communication between an Serial instrument and 8051.
my work is: 1.DefineSFR SCON 2.DefineVTR SIN, SOUT 3.Add WatchSFR(SCON..., ReadWrite) 4.Add WatchVTR(SIN, Read)
in Watch SCON function: if the condition "TI.CurrentValue=True and TI.PreviousValue=False" i think the 8051 send a char to my DLL, then read the VTR SOUT as the char. Does this idea right?
and also in watch SCON function: if the condition "RI.CurrentValue=False and RI.PreviousValue=True" I consider 8051 received a char from Uart(sended by my DLL).Does this idea right? then after this function call, I can write VTR SIN value in my dll as send a new char to 8051?
in Watch SIN Read function I read VTR SIN Value . Is this Value 8051 has received from Uart?
at my DLL, Send a char to 8051, by write char value to VTR SIN. does this write? my program sometimes will lost data. I ask for the reason may be? And can anyone give me a sample of AGSI serial instrument?
Sorry for my poor English.
Your assumptions are not correct. If you write a value to SIN, the simulator handles it as if a new character has been received by the UART. This causes the RI flag to be set and this character can then be read from SBUF by the 8051 application.
When your 8051 application sends a character with the UART, it gets written into SOUT.
I would do the following things: 1) Define VTR SIN and SOUT. You will get a handle to these already existing VTRs. 2) Define a WatchVTR (SOUT, write)
In your callback function for 'write SOUT', you can read the value of SOUT. This is the value that was sent from the 8051 application to your serial instrument.
If you want to send characters from your serial instrument to the 8051 microcontroller you can write the character to SIN. Before you write a new value to this register, you should check if SIN is 0xFFFF. This tells you that the previous SIN value is already processed by your 8051 application (SBUF was read).