Hello, I would continue with the problem. Attached is my test code and LST. I compile C source with > /opt/sdcc/bin/sdcc -V -mpic16 -p18f2580 main.c + "/opt/sdcc/bin/sdcpp" -nostdinc -Wall -Dpic18f2580 -D__18f2580 -DSTACK_MODEL_SMALL -obj-ext=.o -DSDCC_MODEL_SMALL -DSDCC=284 -DSDCC_REVISION=5252 -DSDCC_pic16 -D__pic16 -I"/opt/sdcc/bin/../share/sdcc/include/pic16" -I"/usr/local/share/sdcc/include/pic16" -I"/opt/sdcc/bin/../share/sdcc/include" -I"/usr/local/share/sdcc/include" "main.c" main.c:215: warning 85: in function main unreferenced local variable : 'j' + "gpasm" -DSDCC_MODEL_SMALL -DSTACK_MODEL_SMALL -c "main.asm" -o "main.o" + "gplink" -I"/opt/sdcc/bin/../share/sdcc/lib/pic16" -I"/usr/local/share/sdcc/lib/pic16" -I"/opt/sdcc/bin/../share/sdcc/lib" -I"/usr/local/share/sdcc/lib" -w -r -o main main.o crt0i.o libdev18f2580.lib libsdcc.lib libc18f.lib message: using default linker script "/usr/share/gputils/lkr/18f2580.lkr"
> /opt/sdcc/bin/sdcc --version SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.8.4 #5252 (Oct 20 2008) (UNIX) The output below is in HEX as ASCII is unreadable from address 0x1e. It begins with "PIC printf test" but then in "CAN" loop, output gets garbled. Does anybody have a clue what is going wrong ? Thank you, Vaclav 00000000: 50 49 43 20 70 72 69 6E 74 66 20 74 65 73 74 0A 00000010: 70 72 69 6E 74 66 28 29 20 74 65 73 74 16 FF 83 00000020: CB 3B 1B BB 66 90 FF E7 FF FF C0 78 FF FF FF FF 00000030: FF FF BE 4D B5 7E DF 5A 0A B3 C5 CE C4 C9 DE C7 00000040: 40 C4 C1 E4 C1 1A 83 F9 C3 CC C5 40 FF F7 FF FF 00000050: C0 78 FF FF FF FF FF FF BE 5D B5 7E CF 4A 0A A3 00000060: C5 CE C4 C9 CE C7 40 C4 C1 F4 C1 1A 83 F9 C3 CC 00000070: C5 40 FF F7 FF FF C0 78 FF FF FF FF FF FF BE 4D 00000080: A5 7E CF 4A 0A B3 C5 CE C4 D9 DE C7 40 C4 C1 F4 00000090: C1 1A 83 F9 C3 CC C5 40 FF F7 FF FF C0 78 FF FF 000000A0: FF FF FF FF BE 4D B5 7E CF 4A 0A B3 C5 CE C4 C9 000000B0: DE C7 40 C4 C1 F4 C1 1A 83 F9 C3 CC C5 40 FF E7 000000C0: FF FF C0 78 FF FF FF FF FF FF BE 4D B5 7E CF 4A 000000D0: 0A B3 C5 CE C4 C9 CE C7 40 C4 C1 F4 C1 1A 83 F9 000000E0: C3 DC C5 40 FF F7 FF FF C0 78 FF FF FF FF FF FF 000000F0: BE 4D B5 7E CF 4A 0A B3 C5 CE C4 D9 DE C7 40 C4 00000100: C1 E4 C1 1A 83 F9 C3 CC C5 40 FF F7 FF FF C0 78 00000110: FF FF FF FF FF FF BE 5D A5 7E CF 4A 0A B3 C5 CE 00000120: C4 C9 CE C7 40 C4 C1 E4 C1 1A 83 F9 C3 CC C5 40 00000130: FF E7 FF FF C0 78 FF FF FF FF FF FF BE 4D B5 7E 00000140: CF 4A 0A B3 C5 CE C4 C9 CE C7 40 C4 C1 F4 C1 1A 00000150: 83 F9 C3 CC C5 40 FF F7 FF FF C0 78 FF FF FF FF 00000160: FF FF BE 5D A5 7E CF 4A 0A B3 C5 CE C4 C9 CE C7 00000170: 40 C4 C1 F4 C1 1A 83 F9 C3 DC C5 40 FF F7 FF FF 00000180: C0 78 FF FF FF FF FF FF BE 4D B5 7E CF 5A 1A A3 00000190: C5 DE C4 C9 CE C7 40 C4 C1 F4 C1 1A > ---------------------------------------- > Hi, > > Seems very similair to a problem i had recently with an 18f4520. > As someone on this mailinglist pointed out, the extended instruction set had > to be disabled. > To do this add _XINST_OFF_4L to the __CONFIG4L initialisation. > > Regards, > -Bastiaan > > On Thursday 30 October 2008 09:35:36 Vaclav Peroutka wrote: > > Hello all, > > > > yesterday I experimented with printf() on PIC18F2580. I included stdio.h, I > > defined void PUTCHAR(char c) and I set stdout=STREAM_USER. > > > > PIC sent some proper string just during the programming. But after I > > switched normal supply, I got nothing on UART. But program run ok (flashing > > LED loop). > > > > So I removed stdio.h and wrote > > void printf( char * aStr) { > > while (*aStr) { > > PUTCHAR(*aStr); > > aStr++; > > } > > } > > > > With this function I get funny characters. If I tried printf("CAN terminal > > test"); , I got following sequence of characters: 0xC3, 0xC1, 0xCE, 0x20, > > 0xF4, 0xE5, ... etc. Thus, with bit7 set for any character except space. If > > I used PUTCHAR('C'); PUTCHAR('A'); just before printf(), for couple of > > chars it went well. But then again after approx. 10 characters, it got > > crazy. After I change something small (for example I add or remove one > > PUTCHAR() ) the program even freezes somewhere. > > > > I found that strings are put into program memory and inside my printf(), > > gptrget() is used. Can I have some problem with internal libraries of PIC16 > > ? > > > > Thank you for help, > > Vaclav > > > > ------------------------------------------------------------------------- > > This SF.Net email is sponsored by the Moblin Your Move Developer's > > challenge Build the coolest Linux based applications with Moblin SDK & win > > great prizes Grand prize is a trip for two to an Open Source event anywhere > > in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ > > _______________________________________________ > > Sdcc-user mailing list > > Sdcc-user@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/sdcc-user > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Sdcc-user mailing list > Sdcc-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sdcc-user > > >
/* PRINTF Test * * * Change Log: * ----------- * 2008/11/03 - first trial */ #define LED_TRIS TRISCbits.TRISC0 #define LED_PIN PORTCbits.RC0 #define CANTX_TRIS TRISBbits.TRISB2 #define CANRX_TRIS TRISBbits.TRISB3 // ------------------------------------------------ // this #include pulls in the correct processor-specific registers // definition file #include "pic18fregs.h" #include <stdio.h> #pragma stack 0x300 64 __code char __at(__CONFIG1H) conf1h = 0x06; // Select XT OSC __code char __at(__CONFIG2L) conf2l = 0x00; // BOREN disabled, PWRTEN enabled __code char __at(__CONFIG2H) conf2h = 0x00; // WDT disabled __code char __at(__CONFIG3H) conf3h = 0x00; // digi RB pins, TMR1 normal __code char __at(__CONFIG4L) conf4l = 0x81; // Disable LVP, disable ext. mode //__code eeprom __at 0x2100 __EEPROM[] = { 0xAA, 0x1E, 0x00, 0x01, 0x0A, 0x64, 0x1E, 0x01 }; // buffer for USART #define USART_BUFLEN (40) unsigned char g_BufPointer; unsigned char g_Buffer[USART_BUFLEN]; #define CAN_BUFLEN (6) unsigned char can_outdata[CAN_BUFLEN] = { 0xde, 0xad, 0x55, 0xbe, 0xef, 0xaa }; unsigned char can_indata[CAN_BUFLEN]; unsigned int can_in_id; unsigned char can_in_dlen; volatile unsigned char g_MainloopTimer; // counter of TMR0 10ms interrupts // TMR0 counter constants for 40MHz (presc :4 ) #define C_TMR0H (0x9E) #define C_TMR0L (0x57) void PUTCHAR( char c ) { // Wait for TXREG to be ready while(!PIR1bits.TXIF); // Place char in TXREG - this starts transmition TXREG = c; } // -------------------------------------------------- // high priority interrupt void isr(void) interrupt 1 { // UART RX interrupt if (PIR1bits.RCIF) { PIR1bits.RCIF=0; g_Buffer[g_BufPointer] = RCREG; if ((RCSTA&0x06) != 0x00) { // clear the USART RCSTAbits.CREN = 0; RCSTAbits.CREN = 1; } if( (g_BufPointer++) > USART_BUFLEN) { g_BufPointer--; } } if (INTCONbits.TMR0IF) { INTCONbits.TMR0IF=0; TMR0H = C_TMR0H; TMR0L = C_TMR0L; if (g_MainloopTimer) { g_MainloopTimer--; } } } // -------------------------------------------------- // and our main entry point void main() { /* unsigned char ring[5] = "AT\n\r"; */ /* unsigned char ring_pointer; */ unsigned char i,j; /* unsigned char blikspeed; */ /* unsigned char okreceived; */ /* unsigned char lnib,hnib; */ OSCCON = 0x70; // set pin to output LED_TRIS = 0; // USART TRISCbits.TRISC6 = 0; // (0 = pin set as output) TRISCbits.TRISC7 = 1; // (1 = pin set as input) RCSTA = 0x90; TXSTA = 0x22; BAUDCON = 0; SPBRG = 0x3f; // OSC 40MHz stdout = STREAM_USART; printf ("PIC printf test\n"); //interrupt RCONbits.IPEN = 0; INTCON = 0xc0; PIE1bits.TXIE = 0; // (1 = enabled) PIE1bits.RCIE = 0; // (1 = enabled) // timer 0 - set 0x9E57 to have 10ms TMR0INT TMR0H = C_TMR0H; TMR0L =C_TMR0L; T0CON = 0x81; // 16bit, presc :4 INTCONbits.TMR0IE = 1; // enable TMR0 g_BufPointer = 0; LED_PIN = 1; g_MainloopTimer = 250; while( g_MainloopTimer) ; //wait for zero LED_PIN = 0; printf ("printf() test\n"); // sample CAN configuration and test CANTX_TRIS = 0; CANRX_TRIS = 1; // init - XTAL=8MHz, CAN=50kbps: SJW=1Tq, BRP=2x2/fosc, PH1=8, PH2=8, PROP=3 // CANInitialize(1,4,8,8,3, CAN_CONFIG_STD_MSG); CANCON = 0x80; //set CONFIG mode while ( (CANSTAT&0xe0) != 0x80) ; // wait until mode is acknowledged // now we have full 40MHz, CAN=50kbps: SJW=1Tq, BRP=2*20/Fosc, PH1=8Tq, ph2=8Tq, PROP=3Tq BRGCON1 = 0x13; BRGCON2 = 0xBA; BRGCON3 = 0x87; // Acceptance filters and masks - receiver all the messages RXM0SIDH = 0x00; // In Mode0 RXM0 and RXF0 for RXB0 RXM0SIDL = 0x00; RXM1SIDH = 0xff; // In Mode0 RXM1 and RXF2 for RXB1 RXM1SIDL = 0xf0; // We will receive just in RXB0 RXF0SIDH = 0x00; RXF0SIDL = 0x00; RXF2SIDH = 0x00; RXF2SIDL = 0x00; // Set the loopback // CANSetOperationMode(CAN_OP_MODE_LOOP); CANCON = 0x40; //set LoopBack mode while ( (CANSTAT&0xe0) != 0x40) ; // wait until mode is acknowledged // All other registers can be configured in working mode RXB0CON = 0x20; RXB1CON = 0x20; // send and receive maximum 10 messages // can_outdata - is statically initialized for (i = 0; i < 10; i++) { printf("Cycle %d\n", i); if (!TXB0CONbits.TXREQ) { //we can send some message // set data TXB0D0 = can_outdata[0]; TXB0D1 = can_outdata[1]; TXB0D2 = can_outdata[2]; TXB0D3 = can_outdata[3]; TXB0D4 = can_outdata[4]; TXB0D5 = can_outdata[5]; // set length TXB0DLC = 0x06; // set Frame ID TXB0SIDH = 0x24+i; TXB0SIDL = 0x60; printf("Sending data\n"); // start transmission TXB0CON = 0x40; } if (RXB0CONbits.RXFUL) { // we have some message in RXB0 // get ID can_in_id = (RXB0SIDH<<3) | (RXB0SIDL>>5); // Get message length can_in_dlen = RXB0DLC & 0x0f; printf("Received data, ID = 0x%X ", can_in_id); printf(", LEN = %d\n", can_in_dlen); // Get the data /* mempntr = & RXB0D0; */ /* mempntr2 = can_indata; */ /* for (j = 0; j < can_in_dlen; j++) { */ /* *(mempntr2++) = *(mempntr++); */ /* } */ RXB0CONbits.RXFUL = 0; } g_MainloopTimer = 250; while( g_MainloopTimer) ; //wait for zero } /* Flashing by TMR0INT */ for(;;) { LED_PIN = 1; g_MainloopTimer = 5; while( g_MainloopTimer) ; //wait for zero LED_PIN = 0; g_MainloopTimer = 95; while( g_MainloopTimer) ; //wait for zero } } void CharToAsc( unsigned int inp, unsigned char * out1, unsigned char * out2) { *out1 = ((inp&0xf0) >> 4) + 0x30; if (*out1 > 0x39) *out1 += 7; *out2 = (inp&0x0f) + 0x30; if (*out2 > 0x39) *out2 += 7; }
main.lst.gz
Description: application/save-as
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user