Dear SDCC developers,
I found a bug when I tried to compile a code for pic16F1938. (14 bit enhanced
core)
The problem is: The optimizer breaks the code. Makes part of the code
unreachable.
Error message is:
test.c:51: warning 110: conditional flow changed by optimizer: so said EVELYN
the modified DOG
test.c:52: warning 126: unreachable code
The compiler has problem with this line in the interrupt routine: "if ((irx1tmp
& 0x01) != 0) {"
Compiler thinks, the condition is always false, but it is not true.
irx1tmp contains the received byte from serial port.
By the way: How to disable optimizations?
What kind of optimizations are enabled by default?
Compilation:
sdcc -S -mpic14 -p16f1938 -I. test.c
Version:
SDCC : mcs51/gbz80/z80/z180/r2k/ds390/pic16/pic14/TININative/ds400/hc08 3.1.1 #7
148 (Jan 3 2012) (MINGW32)
Here is my demonstration code:
----------------------------------------
// This code has an error with SDCC. Compiles well with HTC.
#include "pic16f1938.h"
// Configuration: 8MHz crystal, PLL (x4 = 32MHz), WDT disabled, Flash self
write disabled.
unsigned short __at(_CONFIG1) config1Reg = (_FCMEN_OFF & _IESO_OFF & _BOREN_ON
& _CPD_ON & _CP_ON & _MCLRE_OFF & _PWRTE_ON & _WDTE_OFF & _FOSC_HS);
unsigned short __at(_CONFIG2) config2Reg = (_LVP_ON & _BORV_HI & _STVREN_ON &
_PLLEN_ON & _WRT_ALL);
static unsigned char irx1tmp, doLedChange, ledState;
void _sdcc_gsinit_startup(void) { // Entry point required by sdcc.
//__asm pagesel _main __endasm;
__asm goto _main __endasm;
}
void Intr(void) __interrupt 0 {
if (RCIF) { // UART interrupt: Byte arrived
irx1tmp = RCREG;
if ((irx1tmp & 0x01) != 0) {
ledState = 0;
} else {
ledState = 1;
}
doLedChange = 1;
}
}
void main (void) {
doLedChange = 0;
ledState = 0;
TRISA = 0b00000000;
TRISC = 0b11000000;
LATA = 0x00;
LATC = 0x00;
// UART configuration
BAUDCON = 0;
SPBRGL = 207; // 9600 Baud, 32MHz
SPBRGH = 0;
TXSTA = 0b00100100; // TXEN = 1, BRGH = 1
RCSTA = 0b10010000; // CREN = 1 (receiver enable), SPEN = 1 (SPEN =
Serial port enable)
RCIE = 1; // Enable serial port receive interrupt
PEIE = 1; // Enable peripheral interrupts. Needed for uart
GIE = 1; // Global interrupt enable
while (1) {
if (doLedChange) {
doLedChange = 0;
if (ledState) {
LATA = 0x00;
} else {
LATA = 0x20;
}
}
}
}
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user