From: Hartley, J.D. <jd...@le...> - 2008-05-07 13:20:18
|
Hi. I've been using SDCC for 8051s for a while so I thought I'd give the PIC16 port a go. Everything is working correctly except for my UART_WriteString() function. It's the same function I used with the 8051 port. The code, output and my expected output are below. Have I make a silly mistake or are passing and incrementing pointers not supported yet? Device: PIC18F2525 SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.8.1 #5153 (May 6 2008) (UNIX) Also tried with V2.8.0 Complied with: sdcc -mpic16 -p18f2525 main.c /******************************************************************************* main.c ********************************************************************************/ #include "pic18fregs.h" code char at __CONFIG1H __conf1 = _OSC_INTIO7_1H & _FCMEN_OFF_1H & _IESO_OFF_1H; code char at __CONFIG2H __conf2 = _WDT_DISABLED_CONTROLLED_2H; #pragma stack 0x200 0xFF void UART_Init(void); void UART_Write(/*unsigned*/ char); unsigned char UART_Read(void); void UART_WriteString(unsigned char* string); void main(void) { unsigned char Uart_Input; unsigned char TEMP_s[8] = "FGH\n\r"; OSCCON = 0xF0; ADCON1=0x0F; CMCON=0x0F; TRISA=0; TRISC=0xC0; PORTA=0; PORTA=1; UART_Init(); UART_Write('A'); // works ok UART_Write('B'); UART_Write('C'); UART_Write('D'); UART_Write('\n'); UART_Write('\r'); PORTA=2; UART_WriteString("Test1\n\r"); // not working UART_WriteString(TEMP_s); // not working UART_WriteString("test2\n\r\0"); // not working UART_Write(*(TEMP_s+0)); // works ok UART_Write(*(TEMP_s+1)); UART_Write(*(TEMP_s+2)); UART_Write(*(TEMP_s+3)); UART_Write(*(TEMP_s+4)); PORTA=4; while(1) { PORTA=8; Uart_Input = UART_Read(); if(Uart_Input > 0) { UART_Write(Uart_Input); } PORTA=16; } } void UART_Init(void) { RCSTAbits.SPEN = 1; SPBRGH = 0; SPBRG = 51; //9600 @ 4MHz TXSTAbits.BRGH = 1; BAUDCONbits.BRG16 = 0; TXSTAbits.SYNC = 0; TXSTAbits.TXEN = 1; RCSTAbits.CREN = 1; } void UART_Write(/*unsigned*/ char dat) { while(TXSTAbits.TRMT==0); TXREG = dat; //return; } unsigned char UART_Read(void) { if (PIR1bits.RCIF) { return RCREG; } return 0; } void UART_WriteString(unsigned char* string) { unsigned char count = 0; do { UART_Write(*string); string++; count++; } while((*string != '\0') && (count < 120)); } /******************************************************************************* end of main.c ********************************************************************************/ Display on cutecom: ABCD \0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9d\0x9dFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88\0x88FGH Should be: ABCD Test1 FGH test2 FGH |