1 /*------------------------------------------------------------------------
2 test3.c - A simple multiple module example, uses itoa() and crc()
3 routines from other modules in same directory. Compile with:
5 |------------------------------------------------------------------------*/
14 typedef unsigned char byte;
15 typedef unsigned int word;
16 typedef unsigned long l_word;
18 void uitoa(unsigned int value, char* string, int radix);
19 void itoa(int value, char* string, int radix);
20 byte accum_checksum(byte cs, byte val);
26 #if defined(__mcs51) || defined(__ds390)
27 /*------------------------------------------------------------------------
28 tx_char - transmit(tx) a char out the serial uart.
29 |------------------------------------------------------------------------*/
38 /*------------------------------------------------------------------------
40 |------------------------------------------------------------------------*/
41 void my_puts(char *str)
48 /*------------------------------------------------------------------------
50 |------------------------------------------------------------------------*/
53 PCON = 0x80; /* power control byte, set SMOD bit for serial port */
54 SCON = 0x50; /* serial control byte, mode 1, RI active */
55 TMOD = 0x21; /* timer control mode, byte operation */
56 TCON = 0; /* timer control register, byte operation */
58 TH1 = 0xFA; /* serial reload value, 9,600 baud at 11.0952Mhz */
59 TR1 = 1; /* start serial timer */
61 EA = 1; /* Enable Interrupts */
63 TI = 0; /* clear this out */
66 /*------------------------------------------------------------------------
68 |------------------------------------------------------------------------*/
69 void my_puts(char *str)
73 putchar(*str++); /* putchar() is lib routine which calls simulator trap */
77 /*------------------------------------------------------------------------
78 main - Simple test program to send out something to the serial port.
79 |------------------------------------------------------------------------*/
85 #if defined(__mcs51) || defined(__ds390)
91 my_puts("0x3f<<7 hex=");
92 uitoa(tmp, tmpstr, 10);
101 tmp = ((cs<<7) | (cs>>1)) + val;
102 printf("tmp=%xH(0x7fff)\n", tmp);
104 tmp = ((cs<<7) | (cs>>1)) + val;
105 printf("tmp=%xH(0x7efe)\n", tmp);
106 // return (byte)tmp + ((byte) (tmp>>8) & 1);
110 my_puts("Test3 - multiple module test\n");
112 my_puts("1023 decimal=");
113 uitoa(1023, tmpstr, 10);
116 uitoa(1023, tmpstr, 0x10);
121 // i = accum_checksum(50, 20);
122 uitoa(i, tmpstr, 10);