1 /*------------------------------------------------------------------------
2 hello.c - This is a simple program designed to operate on basic MCS51
3 hardware at 11.0592Mhz. It sets up the baudrate to 9600 and responds
4 to simple ascii commands on the serial port.
6 Its intended to be a simple example for SDCC and ucSim.
7 The redirection of the simluated serial port to a TCP port
10 1.) type>s51 -k 5678 hi.ihx
11 2.) (Now telnet to 127.0.0.1 Port 5678)
12 3.) At the s51 prompt, type: run
13 4.) At the telnet prompt, type in a few keys followed by CR
14 5.) You should see this program send back what you typed.
16 6-28-01 Written by Karl Bongers(karl@turbobit.com)
17 |------------------------------------------------------------------------*/
20 typedef unsigned char byte;
21 typedef unsigned int word;
22 typedef unsigned long l_word;
24 data byte li = 0; // index into lbuf
26 data byte lbuf[12]; // this is our line buffer, chars gather here till CR seen
28 /*------------------------------------------------------------------------
29 tx_char - transmit(tx) a char out the serial uart.
30 |------------------------------------------------------------------------*/
39 /*------------------------------------------------------------------------
40 tx_str - transmit(tx) a string out the serial uart.
41 |------------------------------------------------------------------------*/
42 void tx_str(char *str)
49 /*------------------------------------------------------------------------
51 |------------------------------------------------------------------------*/
54 PCON = 0x80; /* power control byte, set SMOD bit for serial port */
55 SCON = 0x50; /* serial control byte, mode 1, RI active */
56 TMOD = 0x21; /* timer control mode, byte operation */
57 TCON = 0; /* timer control register, byte operation */
59 TH1 = 0xFA; /* serial reload value, 9,600 baud at 11.0952Mhz */
60 TR1 = 1; /* start serial timer */
62 EA = 1; /* Enable Interrupts */
64 TI = 0; /* clear this out */
65 SBUF = '.'; /* send an initial '.' out serial port */
66 //ES = 1; /* Enable serial interrupts IE.4 */
68 tx_str("Hello World\n");
74 if (RI) // we have new serial rx data
76 g_dc = SBUF; // read the serial char
77 RI = 0; // reset serial rx flag
79 tx_char(g_dc); // echo back out as serial tx data
80 if ((g_dc == 0x0d) || (g_dc == '.') || (g_dc == 0x0a)) // if CR, then end of line
86 tx_str("You typed in this[");