add simple2
authorkbongers <kbongers@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 18 Jul 2001 19:06:09 +0000 (19:06 +0000)
committerkbongers <kbongers@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 18 Jul 2001 19:06:09 +0000 (19:06 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1084 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/examples/mcs51/simple2/go [new file with mode: 0755]
device/examples/mcs51/simple2/go.bat [new file with mode: 0755]
device/examples/mcs51/simple2/hi.c [new file with mode: 0644]
device/examples/mcs51/simple2/test [new file with mode: 0755]
device/examples/mcs51/simple2/test.bat [new file with mode: 0755]

diff --git a/device/examples/mcs51/simple2/go b/device/examples/mcs51/simple2/go
new file mode 100755 (executable)
index 0000000..7b41b17
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+sdcc hi.c
+
diff --git a/device/examples/mcs51/simple2/go.bat b/device/examples/mcs51/simple2/go.bat
new file mode 100755 (executable)
index 0000000..c3a9048
--- /dev/null
@@ -0,0 +1,10 @@
+; this is a windows batch file to compile hi.c
+
+; set SDCCINC=c:\usr\local\sdcc\device\include
+; set SDCCLIBS=c:\usr\local\sdcc\device\lib\small
+
+set SDCCINC=c:\sdcc\include
+set SDCCLIBS=c:\sdcc\lib\small
+
+sdcc -I %SDCCINC% -L %SDCCLIBS% hi.c
+
diff --git a/device/examples/mcs51/simple2/hi.c b/device/examples/mcs51/simple2/hi.c
new file mode 100644 (file)
index 0000000..06f3400
--- /dev/null
@@ -0,0 +1,99 @@
+/*------------------------------------------------------------------------
+ hello.c - This is a simple program designed to operate on basic MCS51
+   hardware at 11.0592Mhz.  It sets up the baudrate to 9600 and responds
+   to simple ascii commands on the serial port.
+
+   Its intended to be a simple example for SDCC and ucSim.
+   The redirection of the simluated serial port to a TCP port
+   is cool, try this:
+   Try: 
+   1.) type>s51 -k 5678 hi.ihx
+   2.) (Now telnet to 127.0.0.1 Port 5678)
+   3.) At the s51 prompt, type: run
+   4.) At the telnet prompt, type in a few keys followed by CR
+   5.) You should see this program send back what you typed.
+
+ 6-28-01  Written by Karl Bongers(karl@turbobit.com)
+|------------------------------------------------------------------------*/
+#include <8052.h>
+
+typedef unsigned char byte;
+typedef unsigned int word;
+typedef unsigned long l_word;
+
+data byte li = 0;  // index into lbuf
+data byte g_dc;
+data byte lbuf[12];  // this is our line buffer, chars gather here till CR seen
+
+/*------------------------------------------------------------------------
+  tx_char - transmit(tx) a char out the serial uart.
+|------------------------------------------------------------------------*/
+void tx_char(char c)
+{
+  while (!TI)
+    ;
+  TI = 0;
+  SBUF = c;
+}
+
+/*------------------------------------------------------------------------
+  tx_str - transmit(tx) a string out the serial uart.
+|------------------------------------------------------------------------*/
+void tx_str(char *str)
+{
+  
+  while (*str)
+    tx_char(*str++);
+}
+
+/*------------------------------------------------------------------------
+  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;
+      }
+    }
+  }
+}
+
diff --git a/device/examples/mcs51/simple2/test b/device/examples/mcs51/simple2/test
new file mode 100755 (executable)
index 0000000..2b39083
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+s51 -k 5678 hi.ihx
+
diff --git a/device/examples/mcs51/simple2/test.bat b/device/examples/mcs51/simple2/test.bat
new file mode 100755 (executable)
index 0000000..7f02b95
--- /dev/null
@@ -0,0 +1,3 @@
+s51 -k 5678 hi.ihx
+
+