From 77b18aa5d2617328a22a07847c92937cd432e94c Mon Sep 17 00:00:00 2001 From: vrokas Date: Wed, 6 Apr 2005 06:06:20 +0000 Subject: [PATCH] * device/include/pic16/usart.h: added, missing in previous commit, * device/include/pic16/adc.h: fixed typo, * device/lib/pic16/libc/utils/cvtdec.S: added missing in previous commit, * device/lib/pic16/libc/stdlib/g_ftoa.S: modified to include * device/lib/pic16/libc/stdio/streams.c: leave stdin, stdout uninitialized because a bug appears with gplink * device/lib/pic16/{some makefiles}: moved $(CSTD) from CFLAGS to COMPILE_FLAGS and added CPPFLAGS with -nostdinc because sdcpp complains for unrecognised option git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3718 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 14 ++ device/include/pic16/adc.h | 2 +- device/include/pic16/usart.h | 79 +++++++ device/lib/pic16/debug/Makefile.rules | 5 +- device/lib/pic16/libc/Makefile.rules | 6 +- device/lib/pic16/libc/stdio/streams.c | 6 +- device/lib/pic16/libc/stdlib/g_ftoa.S | 2 +- device/lib/pic16/libc/utils/cvtdec.S | 286 ++++++++++++++++++++++++ device/lib/pic16/libm/Makefile | 4 +- device/lib/pic16/libsdcc/Makefile.rules | 11 +- 10 files changed, 402 insertions(+), 13 deletions(-) create mode 100644 device/include/pic16/usart.h create mode 100644 device/lib/pic16/libc/utils/cvtdec.S diff --git a/ChangeLog b/ChangeLog index f6c3900f..5cc0a663 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-04-06 Vangelis Rokas + + * device/include/pic16/usart.h: added, missing in previous commit, + * device/include/pic16/adc.h: fixed typo, + * device/lib/pic16/libc/utils/cvtdec.S: added missing in previous + commit, + * device/lib/pic16/libc/stdlib/g_ftoa.S: modified to include + + * device/lib/pic16/libc/stdio/streams.c: leave stdin, stdout + uninitialized because a bug appears with gplink + * device/lib/pic16/{some makefiles}: moved $(CSTD) from CFLAGS to + COMPILE_FLAGS and added CPPFLAGS with -nostdinc because sdcpp + complains for unrecognised option + 2005-04-05 Raphael Neider * src/pic16/gen.c (pic16_popCopyReg): made copying work for extended diff --git a/device/include/pic16/adc.h b/device/include/pic16/adc.h index b36fc231..333e9909 100644 --- a/device/include/pic16/adc.h +++ b/device/include/pic16/adc.h @@ -91,7 +91,7 @@ void adc_conv(void); /* return 1 if AD is performing a conversion, 0 if done */ char adc_busy(void) __naked; -/* get value of convertion */ +/* get value of conversion */ int adc_read(void) __naked; /* setup conversion channel */ diff --git a/device/include/pic16/usart.h b/device/include/pic16/usart.h new file mode 100644 index 00000000..0b119f37 --- /dev/null +++ b/device/include/pic16/usart.h @@ -0,0 +1,79 @@ + +/* + * USART communications module library header + * + * written for SDCC/pic16 port by Vangelis Rokas, 2005 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + * $Id$ + */ + +#ifndef __USART_H__ +#define __USART_H__ + +#pragma library io + + +#define RAM_SCLS __data + +/* configuration bit masks for open function */ +#define USART_TX_INT_ON 0xff +#define USART_TX_INT_OFF 0x7f +#define USART_RX_INT_ON 0xff +#define USART_RX_INT_OFF 0xbf +#define USART_BRGH_HIGH 0xff +#define USART_BRGH_LOW 0xef +#define USART_CONT_RX 0xff +#define USART_SINGLE_RX 0xf7 +#define USART_SYNC_MASTER 0xff +#define USART_SYNC_SLAVE 0xfb +#define USART_NINE_BIT 0xff +#define USART_EIGHT_BIT 0xfd +#define USART_SYNCH_MODE 0xff +#define USART_ASYNCH_MODE 0xfe + + +/* status bits */ +union USART +{ + unsigned char val; + struct + { + unsigned RX_NINE:1; + unsigned TX_NINE:1; + unsigned FRAME_ERROR:1; + unsigned OVERRUN_ERROR:1; + unsigned fill:4; + }; +}; + +void usart_open(unsigned char config, unsigned int spbrg) __wparam; +void usart_close(void); + +unsigned char usart_busy(void) __naked; +unsigned char usart_drdy(void) __naked; + +unsigned char usart_getc(void); +void usart_gets(RAM_SCLS char *buffer, unsigned char len); + +void usart_putc(unsigned char data) __wparam __naked; +void usart_puts(char *data); + + +void usart_baud(unsigned char baudconfig) __wparam; + +#endif diff --git a/device/lib/pic16/debug/Makefile.rules b/device/lib/pic16/debug/Makefile.rules index c76ece10..b1048c9c 100644 --- a/device/lib/pic16/debug/Makefile.rules +++ b/device/lib/pic16/debug/Makefile.rules @@ -21,7 +21,8 @@ LIBC_INC_DIR = $(PRJDIR)/device/include/pic16 COMPILE_FLAGS += $(MODELFLAGS) $(OPT_FLAGS) -CFLAGS = --nostdinc -I$(LIBC_INC_DIR) +CPPFLAGS := -nostdinc -I$(LIBC_INC_DIR) +CFLAGS += --nostdinc -I$(LIBC_INC_DIR) CFILES = $(patsubst %,%.c,$(SRCS)) OFILES = $(patsubst %.c,%.o,$(CFILES)) @@ -42,7 +43,7 @@ clean: clean-intermediate dep .depend: rm -f .depend for temp in $(CFILES); do \ - $(CPP) $(MM) $(CFLAGS) $$temp > .tmpdepend; \ + $(CPP) $(MM) $(CPPFLAGS) $$temp > .tmpdepend; \ $(SED) s/.rel/.o/g .tmpdepend >> .depend; \ $(RM) -f .tmpdepend; \ done; diff --git a/device/lib/pic16/libc/Makefile.rules b/device/lib/pic16/libc/Makefile.rules index f20e26f2..78e04f11 100644 --- a/device/lib/pic16/libc/Makefile.rules +++ b/device/lib/pic16/libc/Makefile.rules @@ -21,10 +21,12 @@ LIBC_INC_DIR = $(PRJDIR)/device/include/pic16 #OPT_FLAGS += --pstack-model=large #OPT_FLAGS += --stack-auto -COMPILE_FLAGS += $(MODELFLAGS) $(OPT_FLAGS) +COMPILE_FLAGS += $(MODELFLAGS) +COMPILE_FLAGS += $(OPT_FLAGS) +COMPILE_FLAGS += $(CSTD) -CFLAGS = $(CSTD) -I$(LIBC_INC_DIR) +CFLAGS = -I$(LIBC_INC_DIR) CFILES = $(patsubst %,%.c,$(SRCS)) COFILES = $(patsubst %.c,%.o,$(CFILES)) diff --git a/device/lib/pic16/libc/stdio/streams.c b/device/lib/pic16/libc/stdio/streams.c index 65fa6c04..58eb209e 100644 --- a/device/lib/pic16/libc/stdio/streams.c +++ b/device/lib/pic16/libc/stdio/streams.c @@ -29,5 +29,7 @@ #include -FILE *stdout = STREAM_USER; -FILE *stdin = STREAM_USER; +FILE *stdout; +// = STREAM_USER; +FILE *stdin; +// = STREAM_USER; diff --git a/device/lib/pic16/libc/stdlib/g_ftoa.S b/device/lib/pic16/libc/stdlib/g_ftoa.S index fd7b0154..e1381fdd 100644 --- a/device/lib/pic16/libc/stdlib/g_ftoa.S +++ b/device/lib/pic16/libc/stdlib/g_ftoa.S @@ -21,7 +21,7 @@ list r=dec, n=96, st=off, mm=off nolist - include "/usr/local/share/gputils/header/p18f452.inc" + include list udata diff --git a/device/lib/pic16/libc/utils/cvtdec.S b/device/lib/pic16/libc/utils/cvtdec.S new file mode 100644 index 00000000..10633dda --- /dev/null +++ b/device/lib/pic16/libc/utils/cvtdec.S @@ -0,0 +1,286 @@ +;-- +; +; File: cvtdec.asm +; Author: George Gallant +; Date: 19OCT04 +; +; $Id$ +; +; This routine is based on the code and algorithm by +; Nikolai Golovchenko and Scott Dattalo presented in +; the piclist webb site on radix conversion methods. +; Modified to support integers from 0 to 65535 and coded +; for the pic18 chip set. +; +; Digit +; BIT Weight 4 3 2 1 0 +; --- ------ --- --- --- --- --- +; 0 1 0 0 0 0 1 +; 1 2 0 0 0 0 2 +; 2 4 0 0 0 0 4 +; 3 8 0 0 0 0 8 +; +; 4 16 0 0 0 1 6 +; 5 32 0 0 0 3 2 +; 6 64 0 0 0 6 4 +; 7 128 0 0 1 2 8 +; +; 8 256 0 0 2 5 6 +; 9 512 0 0 5 1 2 +; 10 1024 0 1 0 2 4 +; 11 2048 0 2 0 4 8 +; +; 12 4096 0 4 0 9 6 +; 13 8192 0 8 1 9 2 +; 14 16384 1 6 3 8 4 +; 15 32768 3 2 7 6 8 +; +;-- + nolist + include + list + + udata + + global digits + +digits: res 6 + + code + + global cvt_dec_word + +;-- +; +; Convert a 16-bit binary word to 5 BCD bytes +; +; On Call +; PROD 16 bit word +; FSR0 pointer to ascii buffer +; +; On Return +; digits[4:0] contain the BCD integers +; +; Notes: 1. strip leading zeros +; 2. only positive integers on input +; 3. FSR0, PROD & W are modified and not preserved +; +;-- +cvt_dec_word: clrw ;calculate digit 0 - lsd + + btfsc PRODL,0 ;bit0 + addlw 1 + + btfsc PRODL,1 ;bit1 + addlw 2 + + btfsc PRODL,2 ;bit2 + addlw 4 + + btfsc PRODL,3 ;bit3 + addlw 8 + + btfsc PRODL,4 ;bit4 + addlw 6 + + btfsc PRODL,5 ;bit5 + addlw 2 + + btfsc PRODL,6 ;bit6 + addlw 4 + + btfsc PRODL,7 ;bit7 + addlw 8 + + btfsc PRODH,0 ;bit8 + addlw 6 + + btfsc PRODH,1 ;bit9 + addlw 2 + + btfsc PRODH,2 ;bit10 + addlw 4 + + btfsc PRODH,3 ;bit11 + addlw 8 + + btfsc PRODH,4 ;bit12 + addlw 6 + + btfsc PRODH,5 ;bit13 + addlw 2 + + btfsc PRODH,6 ;bit14 + addlw 4 + + btfsc PRODH,7 ;bit15 + addlw 8 + + clrf digits+1 ;setup for carry in 10's +@1: addlw -10 + bnc @2 + incf digits+1,f + bra @1 + +@2: addlw 10 + movwf digits+0 + +; calculate digit 1 + + movf digits+1,w + + btfsc PRODL,4 ;bit4 + addlw 1 + + btfsc PRODL,5 ;bit5 + addlw 3 + + btfsc PRODL,6 ;bit6 + addlw 6 + + btfsc PRODL,7 ;bit7 + addlw 2 + + btfsc PRODH,0 ;bit8 + addlw 5 + + btfsc PRODH,1 ;bit9 + addlw 1 + + btfsc PRODH,2 ;bit10 + addlw 2 + + btfsc PRODH,3 ;bit11 + addlw 4 + + btfsc PRODH,4 ;bit12 + addlw 9 + + btfsc PRODH,5 ;bit13 + addlw 9 + + btfsc PRODH,6 ;bit14 + addlw 8 + + btfsc PRODH,7 ;bit15 + addlw 6 + + clrf digits+2 ;setup for carry into 100's +@3: addlw -10 + bnc @4 + incf digits+2,f + bra @3 + +@4: addlw 10 + movwf digits+1 + +; calculate digit 2 + + movf digits+2,w + + btfsc PRODL,7 ;bit7 + addlw 1 + + btfsc PRODH,0 ;bit8 + addlw 2 + + btfsc PRODH,1 ;bit9 + addlw 5 + + btfsc PRODH,5 ;bit13 + addlw 1 + + btfsc PRODH,6 ;bit14 + addlw 3 + + btfsc PRODH,7 ;bit15 + addlw 7 + + clrf digits+3 ;setup for carry into 1000's +@5: addlw -10 + bnc @6 + incf digits+3,f + bra @5 +@6: addlw 10 + + movwf digits+2 + +; calculate digit 3 + + movf digits+3,w + + btfsc PRODH,2 ;bit10 + addlw 1 + + btfsc PRODH,3 ;bit11 + addlw 2 + + btfsc PRODH,4 ;bit12 + addlw 4 + + btfsc PRODH,5 ;bit13 + addlw 8 + + btfsc PRODH,6 ;bit14 + addlw 6 + + btfsc PRODH,7 ;bit15 + addlw 2 + + clrf digits+4 ;setup for carry into 10000's +@7: addlw -10 + bnc @8 + incf digits+4,f + bra @7 + +@8: addlw 10 + movwf digits+3 + +; calculate digit 4 + + movf digits+4,w + + btfsc PRODH,6 ;bit14 + addlw 1 + + btfsc PRODH,7 ;bit15 + addlw 3 + +@9: addlw -10 + bc @9 + + addlw 10 +; movwf digits+4 + +; movf digits+4,w + bnz @11 + movf digits+3,w + bnz @12 + movf digits+2,w + bnz @13 + movf digits+1,w + bnz @14 + bra @15 + +@11: addlw 0x30 + movwf POSTINC0 + + movf digits+3,w +@12: addlw 0x30 + movwf POSTINC0 + + movf digits+2,w +@13: addlw 0x30 + movwf POSTINC0 + + movf digits+1,w +@14: addlw 0x30 + movwf POSTINC0 + +@15: movf digits+0,w + addlw 0x30 + movwf POSTINC0 + + return + + end diff --git a/device/lib/pic16/libm/Makefile b/device/lib/pic16/libm/Makefile index d9ba0a0c..65209245 100644 --- a/device/lib/pic16/libm/Makefile +++ b/device/lib/pic16/libm/Makefile @@ -61,9 +61,9 @@ SRCS = acosf \ tanhf COMPILE_FLAGS += $(MODELFLAGS) $(OPT_FLAGS) +COMPILE_FLAGS += $(CSTD) -CFLAGS += $(CSTD) -CFLAGS += -I $(PRJDIR)/device/include/pic16 +CFLAGS += -I $(PRJDIR)/device/include/pic16 CFILES = $(patsubst %,%.c,$(SRCS)) diff --git a/device/lib/pic16/libsdcc/Makefile.rules b/device/lib/pic16/libsdcc/Makefile.rules index 529b2a7b..3e0bec8e 100644 --- a/device/lib/pic16/libsdcc/Makefile.rules +++ b/device/lib/pic16/libsdcc/Makefile.rules @@ -23,11 +23,16 @@ DEBUG = OPT_FLAGS += --optimize-cmp #OPT_FLAGS += --stack-auto -COMPILE_FLAGS += $(MODELFLAGS) $(OPT_FLAGS) $(DEBUG) -CFLAGS += $(CSTD) +COMPILE_FLAGS += $(MODELFLAGS) +COMPILE_FLAGS += $(OPT_FLAGS) $(DEBUG) +COMPILE_FLAGS += $(CSTD) + +CPPFLAGS := -nostdinc $(CFLAGS) -I$(LIBC_INC_DIR) + CFLAGS += --nostdinc -I$(LIBC_INC_DIR) + CFILES = $(patsubst %,%.c,$(SRCS)) COFILES = $(patsubst %.c,%.o,$(CFILES)) @@ -57,7 +62,7 @@ clean: clean-intermediate dep .depend: rm -f .depend for temp in $(CFILES); do \ - $(CPP) $(MM) $(CFLAGS) $$temp > .tmpdepend; \ + $(CPP) $(MM) $(CPPFLAGS) $$temp > .tmpdepend; \ $(SED) s/.rel/.o/g .tmpdepend >> .depend; \ $(RM) -f .tmpdepend; \ done; -- 2.47.2