Page 1 of 1
Bug report: MikroC v 5.61 asm code compilation error
Posted: 09 Aug 2012 01:29
by sparks
Dear MikroElektronica team,
Coming from the assembler world I like to check, double check and triple check all the code MikroC generates. Today I found a annoying problem with BRA operand, here is an example:
PIC18F1847, simple check for a bit and BRAnch to the check point again if set:
Code: Select all
void chk_go(){
asm{
movlb 1; // banksel ADRESL, ADRESH, ADCON0
bsf ADCON0,GO;
rechk:
btfsc ADCON0,GO;
BRA $-1; // the BRAnch addres is not calculated properly
// BRA rechk; doesn't work either
// but goto $-1; or goto rechk; has no problems
....
....
}
Please advise how to resolve the issue, I do need BRA instead of GOTO for some other functions.
Re: Bug report: MikroC v 5.61 asm code compilation error
Posted: 09 Aug 2012 09:16
by janko.kaljevic
Hello,
I really was not able to reproduce this at my side.
In attachment you can check simple code.
Also I assumed that you referred on PIC16F1847 controller.
In my test BRA functions like it should and there were no issues at all.
I also used mikroC PRO for PIC v5.61.
If there is anything else that I need to reproduce this error, please point me to it.
Best regards.
Re: Bug report: MikroC v 5.61 asm code compilation error
Posted: 09 Aug 2012 11:42
by sparks
Thank you very much for your quick response. I tested your code today and it works. Then recompiled my problematic program and now BRA is pointing to the correct address. I guess it has something to do with restarting MikroC or the evil gnome that was spoiling my bits last night is still sleeping.
Once again, thank you and have a great and sunny day!
Re: Bug report: MikroC v 5.61 asm code compilation error
Posted: 09 Aug 2012 12:25
by sparks
Here is another issue i found with timers and some registers not updated in MikroC software debugger:
Code: Select all
// Example for MikroC software debugger issues
// PIC 16F1847 @16MHz - internal oscillator
// also tested on PIC18F26K22 with Timer0, Timer1, Timer2 - timers don't count
void pic_init() {
OSCCON = 0 << SPLLEN | 0b1111 << IRCF0 | 0b10 << SCS0; // 16 MHz
// ADC init:
FVRCON = 0 << FVREN | 0b10 << ADFVR0; // 2.048V
while(!FVRRDY_bit); // Wait for FVR to stabilize ||| Debugger hangs here |||
ADCON0 = 1 << ADON; // CHS4:0 = 0b0000 (AN0 selected to sample)
ADCON1 = 0 << ADFM |
0b101 << ADCS0 | // Tad = FOSC/16 (1us)
0b11 << ADPREF0; // Vref+ connected to FVR
// Timer2 init:
T2CON = 0b0100 << T2OUTPS0 // 1:5 postscaler
| 0b01 << T2CKPS0 // 1:4 prescaler
| 1 << TMR2ON; // Turn on Timer2
PR2 = 199; // Timer2 overflows every 1 ms
TMR2IF_bit = 0;
PIE1 = 1 << TMR2IE; // Enable Timer2 interrupt
INTCON = 1 << GIE | 1 << PEIE;
}
void main() {
unsigned short x;
pic_init();
GO_bit = 1;
while(GO_bit); // Wait for the ADC to sample ||| Debugger hangs here too |||
// No problems with MPLAB SIM or ICD 2 debuggers
x = ADRESH;
}
void interrupt() { // Timer2 never counts in MikroC software debugger,
TMR2IF_bit = 0; // so we never reach this point.
// Timer2 counts as expected when the code
// is imported in MPLAB v8.85 and run with
// MPLAB SIM
asm nop;
}
Can you please check if this code debugs fine or I have to blame the gnome again?
Re: Bug report: MikroC v 5.61 asm code compilation error
Posted: 09 Aug 2012 12:46
by janni
No gnome this time. Software simulator does not emulate hardware functions, like timers and interrupts (one may only force a jump to ISR). Such may only be tested with ICD (hardware debugger).