/*------------------------------------------------------------------------ main - |------------------------------------------------------------------------*/ void main(void) { PCON = 0x80; /* power control byte, set SMOD bit for serial port */ SCON = 0x50; /* serial control byte, mode 1, RI active */ TMOD = 0x21; /* timer control mode, byte operation */ TCON = 0; /* timer control register, byte operation */ TH1 = 0xFA; /* serial reload value, 9,600 baud at 11.0952Mhz */ TR1 = 1; /* start serial timer */ EA = 1; /* Enable Interrupts */ TI = 0; /* clear this out */ SBUF = '.'; /* send an initial '.' out serial port */ //ES = 1; /* Enable serial interrupts IE.4 */ tx_str("Hello World\n"); RI = 0; g_dc = 0; for (;;) { if (RI) // we have new serial rx data { g_dc = SBUF; // read the serial char RI = 0; // reset serial rx flag tx_char(g_dc); // echo back out as serial tx data if ((g_dc == 0x0d) || (g_dc == '.') || (g_dc == 0x0a)) // if CR, then end of line { tx_char(0xd); // CR tx_char(0xa); // LF lbuf[li] = 0; li = 0; tx_str("You typed in this["); tx_str(lbuf); tx_str("]\n"); } else { lbuf[li] = g_dc; if (li < 11) ++li; } } } }
static void tx_hex(char *str, unsigned int num) { const char c[] = "0123456789abcdef"; int s = 28; tx_str(str); while(s >= 0) { tx(c[(num >> s)&0x0f]); s -= 4; } tx('\n'); tx('\r'); }