/***************************************************************

   SER0_DEM.C

   BL11xx/Little Giant, Tiny Giant, BL13xx/Protocol Switch, SmartBlock

	If you are using z0 for your progamming port you cannot use this
	program.
	
   Demonstration of serial port driver for Z180 ASCI port 0. 
   
   BL11xx/Little Giant, RS-232:

                  J7

           1      0     0     2

           3 TX0  0     0 CTS 4
                  |     |
           5 RX0  0     0 RTS 6

           7      0     0     8

           9      0     0     10


   Tiny Giant:
            J8, Jumper the same as the BL11xx/Little Giant

   BL13xx/Protocol Switch:
      8-pin mini DIN, connect P1 as follows:
                ......
                |    |
           TXA0 6  7 8  RXA0
               5   4  3
           RTS   1  2   CTS
                 |  |
                 ~~~~
      25-pin DB connector, connect 2 to 3 (RX/TX) and 4 to 5 (CTS/RTS).

   SmartBlock:
      Depends on your application board.

   This will loop the serial port back on itself so that the signal
   that is sent is received on the same port.  Z-World serial drivers
   are interrupt driven and continue to run while the program executes.

**********************************************************************/

#use "serial.lib"

char buf[] = "This message sent over serial line!";
char cc;             /* transmit buffer down counter */

char rbuf[50];       /* receive buffer */
char rcc;            /* receive buffer down counter */

main()
{
   int  tt;                    /* time out counter */

   ser_init_z0(4,9600/1200);  /* setup serial port, 8 bits, no parity */
   cc=sizeof(buf);            /* get number of characters to send */
   rcc=cc;                    /* make it the number of characters to receive */
   rbuf[0]=0;                 /* in case print null string */

   ser_rec_z0(rbuf,&rcc);     /* make sure receiver is ready */
   ser_send_z0(buf,&cc);      /* OK, now send the string */

   tt=0;
   while (rcc && --tt) hitwd(); /* wait for receive counter to 0 or time out */

   if(!tt) 
      printf("Timed out - port not loop connected?\n");
   printf("%s\n",rbuf);
}

/*********************************************End of SER0_DEM.C *****/


