From bccf42a99cc1fb70ebd1e33c35aeb48e66e86ea2 Mon Sep 17 00:00:00 2001 From: kbongers Date: Sat, 9 Feb 2002 07:10:37 +0000 Subject: [PATCH] add Makefile, test3.c for testing debugger git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1910 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- device/examples/Makefile | 60 ++++++++++++++++++ device/examples/test3.c | 131 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 device/examples/Makefile create mode 100644 device/examples/test3.c diff --git a/device/examples/Makefile b/device/examples/Makefile new file mode 100644 index 00000000..b640cff2 --- /dev/null +++ b/device/examples/Makefile @@ -0,0 +1,60 @@ + +#DO_GCC=1 +DO_Z80=1 +#DO_MCS51=1 + +ifdef DO_GCC +CC = gcc -Wall -g +endif + +ifdef DO_Z80 +OBJEXT=o +CC = sdcc +MFLAGS = --debug -mz80 +endif + +ifdef DO_MCS51 +OBJEXT=rel +CC = sdcc +MFLAGS = --debug --model-small --stack-after-data +#CFLAGS = -V +#MFLAGS = --debug --model-large --stack-after-data +#LFLAGS = --xram-loc 0x4000 --code-loc 0x0000 +endif + + +#OBJECTS = test3.c itoa.$(OBJEXT) crc.$(OBJEXT) +OBJECTS = test3.c itoa.$(OBJEXT) + +all: test3.ihx + +ifdef DO_MCS51 +an429.ihx : an429.c + sdcc --model-small an429.c + +test2.ihx : test2.c + sdcc --model-small test2.c +endif + +%.$(OBJEXT): %.c + $(CC) -c $(CFLAGS) $(MFLAGS) $< + +itoa.rel : itoa.c + $(CC) -c $(CFLAGS) $(MFLAGS) itoa.c + +#crc.rel : crc.c +# $(CC) -c $(CFLAGS) $(MFLAGS) crc.c + +test3.ihx: $(OBJECTS) + $(CC) $(MFLAGS) $(LFLAGS) $(OBJECTS) + +test3.bin: test3.ihx + makebin < test3.ihx > test3.bin + +clean: + rm -f core *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map *.o \ + *.rst *.sym *.lnk *.lib *.bin + +testser: test3.ihx + s51 -Sout=serial.log test3.ihx + diff --git a/device/examples/test3.c b/device/examples/test3.c new file mode 100644 index 00000000..ae808b91 --- /dev/null +++ b/device/examples/test3.c @@ -0,0 +1,131 @@ +/*------------------------------------------------------------------------ + test3.c - A simple multiple module example, uses itoa() and crc() + routines from other modules in same directory. Compile with: + make -f maketest3 +|------------------------------------------------------------------------*/ +#if defined(__mcs51) +#include <8052.h> +#endif +#if defined(__ds390) +#include +#endif +#include + +typedef unsigned char byte; +typedef unsigned int word; +typedef unsigned long l_word; + +void uitoa(unsigned int value, char* string, int radix); +void itoa(int value, char* string, int radix); +byte accum_checksum(byte cs, byte val); + +char tmpstr[30]; + +int i; + +#if defined(__mcs51) || defined(__ds390) +/*------------------------------------------------------------------------ + tx_char - transmit(tx) a char out the serial uart. +|------------------------------------------------------------------------*/ +void tx_char(char c) +{ + SBUF = c; + while (!TI) + ; + TI = 0; +} + +/*------------------------------------------------------------------------ + my_puts - +|------------------------------------------------------------------------*/ +void my_puts(char *str) +{ + + while (*str) + tx_char(*str++); +} + +/*------------------------------------------------------------------------ + init_mcs51 - +|------------------------------------------------------------------------*/ +void init_mcs51(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 */ +} +#else +/*------------------------------------------------------------------------ + my_puts - +|------------------------------------------------------------------------*/ +void my_puts(char *str) +{ + + while (*str) + putchar(*str++); /* putchar() is lib routine which calls simulator trap */ +} +#endif + +/*------------------------------------------------------------------------ + main - Simple test program to send out something to the serial port. +|------------------------------------------------------------------------*/ +int main(void) +{ + byte ccs; + unsigned int tmp; + +#if defined(__mcs51) || defined(__ds390) + init_mcs51(); +#endif + + ccs = 0x3f; + tmp = (ccs<<7); + my_puts("0x3f<<7 hex="); + uitoa(tmp, tmpstr, 10); + my_puts(tmpstr); + my_puts("\n"); + +#if 0 + byte r,cs,val; + unsigned int tmp; + cs = 0xff; + val = 0; + tmp = ((cs<<7) | (cs>>1)) + val; + printf("tmp=%xH(0x7fff)\n", tmp); + cs = 0xfd; + tmp = ((cs<<7) | (cs>>1)) + val; + printf("tmp=%xH(0x7efe)\n", tmp); + // return (byte)tmp + ((byte) (tmp>>8) & 1); +#endif + + + my_puts("Test3 - multiple module test\n"); + + my_puts("1023 decimal="); + uitoa(1023, tmpstr, 10); + my_puts(tmpstr); + my_puts(" hex="); + uitoa(1023, tmpstr, 0x10); + my_puts(tmpstr); + my_puts("\n"); + + my_puts(" chksum="); +// i = accum_checksum(50, 20); + uitoa(i, tmpstr, 10); + my_puts(tmpstr); + my_puts("\n"); + + for (;;) + { + } + return 0; +} + -- 2.30.2