I would like to make comparison between two kind of PIC microcontroller compilers mikroC & CCS as example using pointers indirect addressing
Here is the code: mcu /pic 16f877A
//////////////////////////////////////////////////////
1- For mikroC write this C code
Char cntr =3 absolute 0x121;
char*ptr =&cntr;
void main() {
trisb = 0;
portb = *ptr;
}
//////////////////////////////////////////////
2- for CCS write this C code
#BYTE portb= 0x6
#BYTE cntr=0x121
char*ptr = &cntr;
void main()
{
SET_TRIS_B( 0x00 );
cntr = 3;
portb = *ptr:
}
After you compile the code upload the hex file to mcu 16f877 or you can test it by simulator like proteus the result by CCS hex file is working fine but in the contrary by mikroc hex file , if we check the lst asm file belong to ccs & mikroC compilers
1- mikroC asm lst file
;ex1.c,11 :: portb = *ptr;
BCF STATUS, 6
MOVF _ptr, 0
MOVWF FSR
MOVF INDF, 0
MOVWF PORTB
///////////////////////////////////////////////////////////
2- CCS asm lst file
.................... portb = *ptr;
BCF 03.6
MOVF 20,W
MOVWF 04
BCF 03.7
BTFSC 21.0
BSF 03.7
MOVF 00,W
MOVWF 06
If we check the data sheet PIC :
REGISTER 2-1: STATUS REGISTER (ADDRESS 03h, 83h, 103h, 183h)
bit 7 IRP: Register Bank Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h - 1FFh)
0 = Bank 0, 1 (00h - FFh)
////////////////////////////////////////////////////////////
Conclusion :
I find that Mikroc don’t care of IRP bit for indirect addressing as you note before .
On other side if we update c file by adding an asm line of code like this
Mikroc write this C file :
char cntr absolute 0x121;
char*ptr =&cntr;
void main() {
trisb = 0;
cntr = 3;
asm BSF STATUS, IRP
portb = *ptr;
}
///////////////////////////////////////////////////////
On that we can resolve our problems on mikroC pointers indirect addressing.
About me I don’t like any one . but I note that CCS is pro compiler
About mikroC is easy one but if you are professional programmer you don’t prefer it any way .