Crossware

Table of Contents        Previous topic       Next topic       

Serial I/O

It is often useful to be able to perform serial I/O from your program when it is running in the debug monitor.  This is possible using some specially provided functions located in the debug monitors startup.asm.  You can use these calls in your own versions of getch(), putch() and kbhit().  This is how they should be written (for non-reeantrant code) for inclusion in your program:

int getch()
{
  _asm(" extrn data(__CW51D001)");
  _asm(" lcall 0105h");
  _asm(" mov __CW51D001,A");
  _asm(" mov __CW51D001+1,#0");
}

int putch(int ch)
{
#ifdef _X_I51LM
  _asm(" mov dptr,#{ch}");
  _asm(" movx A,@dptr");
#else
  _asm(" mov A,{ch}");
#endif
  _asm(" lcall 0100h");
}

unsigned char kbhit()
{
  _asm(" extrn data(__CW51D001)");
  _asm(" lcall 010Bh");
  _asm(" mov __CW51D001,A");
}
    
You should comment them out when not running in the debug monitor.  The default versions from the library will then be used instead.

A Debug Monitor window will be created to handle this I/O.  Output from your program will be written to it and you can type characters into it as input to your program.  If the window does not appear automatically, select Output from the View menu (or press Alt+2) and click on the Debug Monitor tab.

For Atmel's T89C51RD2 and T89C51AC2 chips, the UART Code Creation Wizard can be used to create getch(), putch() and kbhit().  When it does so, it will create them in two forms  one for stand-alone use and one as above for use with the debug monitor.  The appropriate form will automatically be included through the selection of either Standard Operation or Debug Monitor as the Configured for option that is available for these chips.