In the last test I did on this, I did comment out the global "i" when I used the local, and that was the non-working version. Disassembly below. I had pretty much skipped learning the 18F assembly instructions and went to C when I moved from 16F's, so when I started walking through the disassembly and I realized I was spending much time to figure out the access/banked thing, 18F indirect addressing, etc. So I decided to try MPLABX/XC8 instead. This code works properly with either a global or local variable in XC8. So now I'm in the process of porting my much larger code (which is the one that started this whole test) over to XC8, and reading through the docs on that. I'm currently trying to figure out how interrupt code needs to be setup in XC8. Not a setback I need right now, but perhaps it's better than trying to figure out a bug in a deprecated IDE/compiler. Cheers, -Neil. Quoting smplx : > > Hi Neil, > > In a previous post you said that in one case the compiler would stop > working. This is what attracted my attention. This further info about the > global / local problem is also very interesting. > > Try changing the name of the global "i" variable to something else, > something unique and unused anywhere else. Uncomment out the definition o= f > the local "i" variable. Does it still work? > > I wonder if the compiler is getting confused and using the address of the > global "i" as an offset into the runtime stack. > > Regards > Sergio Masci > > ... --- C:\32GB FD\Moi-Newer\PICDev\PICWin\Sandbox\C\DelayIssue01-v01.c ---------------------------- 9: #include 10: 13: #pragma config FOSC =3D INTIO67 14: //#pragma config FOSC =3D HSHP 15: #pragma config WDTEN =3D OFF 16: #pragma config LVP =3D OFF 17: #pragma config MCLRE =3D INTMCLR 18: 19: #pragma config PLLCFG =3D OFF 20: #pragma config PRICLKEN =3D OFF 21: #pragma config FCMEN =3D OFF 22: #pragma config IESO =3D OFF 23: #pragma config PWRTEN =3D ON 24: #pragma config BOREN =3D ON 25: #pragma config BORV =3D 285 26: #pragma config PBADEN =3D OFF 27: #pragma config STVREN =3D ON 28: #pragma config XINST =3D OFF 29: #pragma config DEBUG =3D OFF 30: #pragma config CP0 =3D OFF 31: #pragma config CP1 =3D OFF 32: #pragma config CPB =3D OFF 33: #pragma config CPD =3D OFF 34: #pragma config WRT0 =3D OFF 35: #pragma config WRT1 =3D OFF 36: #pragma config WRTC =3D OFF 37: #pragma config WRTB =3D OFF 38: #pragma config WRTD =3D OFF 39: #pragma config EBTR0 =3D OFF 40: #pragma config EBTR1 =3D OFF 41: #pragma config EBTRB =3D OFF 42: 45: // Variables... 46: //unsigned char i; 47: 49: void main(void) 00A6 CFD9 MOVFF 0xfd9, 0xfe6 00A8 FFE6 NOP 00AA CFE1 MOVFF 0xfe1, 0xfd9 00AC FFD9 NOP 00AE 52E6 MOVF 0xfe6, F, ACCESS 50: { 51: unsigned char i; // <--- Comment this out an= d the code works 52: 53: 54: OSCCON =3D 0b00010000; // 1 Mhz internal 00B0 0E10 MOVLW 0x10 00B2 6ED3 MOVWF 0xfd3, ACCESS 55: OSCCON2 =3D 0b00000000; 00B4 6AD2 CLRF 0xfd2, ACCESS 56: 57: OSCTUNE =3D 0b00000000; 00B6 6A9B CLRF 0xf9b, ACCESS 58: 59: TRISA =3D 0b11011111; 00B8 0EDF MOVLW 0xdf 00BA 6E92 MOVWF 0xf92, ACCESS 60: TRISB =3D 0b00000000; 00BC 6A93 CLRF 0xf93, ACCESS 61: TRISC =3D 0; 00BE 6A94 CLRF 0xf94, ACCESS 62: 63: ANSELA =3D 0b00000011; 00C0 010F MOVLB 0xf 00C2 0E03 MOVLW 0x3 00C4 6F38 MOVWF 0x38, BANKED 64: ANSELB =3D 0; 00C6 010F MOVLB 0xf 00C8 6B39 CLRF 0x39, BANKED 65: ANSELC =3D 0; 00CA 010F MOVLB 0xf 00CC 6B3A CLRF 0x3a, BANKED 66: 67: LATA =3D 0b00000000; 00CE 6A89 CLRF 0xf89, ACCESS 68: LATB =3D 0; 00D0 6A8A CLRF 0xf8a, ACCESS 69: LATC =3D 0; 00D2 6A8B CLRF 0xf8b, ACCESS 70: 71: while (1) 0118 D7DD BRA 0xd4 72: { 73: LATC =3D 0b01010101; // '0's will turn= LED's on. 00D4 0E55 MOVLW 0x55 00D6 6E8B MOVWF 0xf8b, ACCESS 74: for (i=3D0; i<250; i++) 00D8 6ADF CLRF 0xfdf, ACCESS 00DA 50DF MOVF 0xfdf, W, ACCESS 00DC 6E02 MOVWF 0x2, ACCESS 00DE 6A03 CLRF 0x3, ACCESS 00E0 90D8 BCF 0xfd8, 0, ACCESS 00E2 5003 MOVF 0x3, W, ACCESS 00E4 E604 BN 0xee 00E6 0EFA MOVLW 0xfa 00E8 5C02 SUBWF 0x2, W, ACCESS 00EA 0E00 MOVLW 0 00EC 5803 SUBWFB 0x3, W, ACCESS 00EE E203 BC 0xf6 00F2 2ADF INCF 0xfdf, F, ACCESS 00F4 D7F2 BRA 0xda 75: Nop(); 00F0 0000 NOP 76: LATC =3D 0b10101010; // '0's will turn= LED's on. 00F6 0EAA MOVLW 0xaa 00F8 6E8B MOVWF 0xf8b, ACCESS 77: for (i=3D0; i<250; i++) 00FA 6ADF CLRF 0xfdf, ACCESS 00FC 50DF MOVF 0xfdf, W, ACCESS 00FE 6E02 MOVWF 0x2, ACCESS 0100 6A03 CLRF 0x3, ACCESS 0102 90D8 BCF 0xfd8, 0, ACCESS 0104 5003 MOVF 0x3, W, ACCESS 0106 E604 BN 0x110 0108 0EFA MOVLW 0xfa 010A 5C02 SUBWF 0x2, W, ACCESS 010C 0E00 MOVLW 0 010E 5803 SUBWFB 0x3, W, ACCESS 0110 E203 BC 0x118 0114 2ADF INCF 0xfdf, F, ACCESS 0116 D7F2 BRA 0xfc 78: Nop(); 0112 0000 NOP 79: } 80: } // main() 011A 52E5 MOVF 0xfe5, F, ACCESS 011C 52E5 MOVF 0xfe5, F, ACCESS 011E CFE7 MOVFF 0xfe7, 0xfd9 0120 FFD9 NOP 0122 0012 RETURN 0 --- E:\c18v3.46\pic18-lt\cxx-framework\src\traditional\proc\p18f25k22.asm ---------------------- 0124 0E00 MOVLW 0 0126 6EF3 MOVWF 0xff3, ACCESS 0128 EE00 LFSR 0, 0 012A F000 NOP 012C 0E06 MOVLW 0x6 012E D801 RCALL 0x132 0130 0012 RETURN 0 0132 60EA CPFSLT 0xfea, ACCESS 0134 D002 BRA 0x13a 0136 6AEE CLRF 0xfee, ACCESS 0138 D7FC BRA 0x132 013A 50F3 MOVF 0xff3, W, ACCESS 013C 60E9 CPFSLT 0xfe9, ACCESS 013E 0012 RETURN 0 0140 6AEE CLRF 0xfee, ACCESS 0142 D7FC BRA 0x13c --- E:\c18v3.46\pic18-lt\cxx-framework\src\traditional\startup\c018i.c ------------------------- 0000 EFA2 GOTO 0x144 0002 F000 NOP 0004 0012 RETURN 0 0144 EE15 LFSR 0x1, 0x500 0146 F000 NOP 0148 EE25 LFSR 0x2, 0x500 014A F000 NOP 014C 6AF8 CLRF 0xff8, ACCESS 014E 9C01 BCF 0x1, 0x6, ACCESS 0150 EC04 CALL 0x8, 0 0152 F000 NOP 0154 ECB0 CALL 0x160, 0 0156 F000 NOP 0158 EC53 CALL 0xa6, 0 015A F000 NOP 015C D7FB BRA 0x154 015E 0012 RETURN 0 0008 0E06 MOVLW 0x6 000A 6EF6 MOVWF 0xff6, ACCESS 000C 0E00 MOVLW 0 000E 6EF7 MOVWF 0xff7, ACCESS 0010 0E00 MOVLW 0 0012 6EF8 MOVWF 0xff8, ACCESS 0014 0100 MOVLB 0 0016 0009 TBLRD*+ 0018 50F5 MOVF 0xff5, W, ACCESS 001A 6F65 MOVWF 0x65, BANKED 001C 0009 TBLRD*+ 001E 50F5 MOVF 0xff5, W, ACCESS 0020 6F66 MOVWF 0x66, BANKED 0022 E103 BNZ 0x2a 0024 6765 TSTFSZ 0x65, BANKED 0026 D001 BRA 0x2a 0028 D03D BRA 0xa4 002A 0009 TBLRD*+ 002C 50F5 MOVF 0xff5, W, ACCESS 002E 6F60 MOVWF 0x60, BANKED 0030 0009 TBLRD*+ 0032 50F5 MOVF 0xff5, W, ACCESS 0034 6F61 MOVWF 0x61, BANKED 0036 0009 TBLRD*+ 0038 50F5 MOVF 0xff5, W, ACCESS 003A 6F62 MOVWF 0x62, BANKED 003C 0009 TBLRD*+ 003E 0009 TBLRD*+ 0040 50F5 MOVF 0xff5, W, ACCESS 0042 6EE9 MOVWF 0xfe9, ACCESS 0044 0009 TBLRD*+ 0046 50F5 MOVF 0xff5, W, ACCESS 0048 6EEA MOVWF 0xfea, ACCESS 004A 0009 TBLRD*+ 004C 0009 TBLRD*+ 004E 0009 TBLRD*+ 0050 50F5 MOVF 0xff5, W, ACCESS 0052 6F63 MOVWF 0x63, BANKED 0054 0009 TBLRD*+ 0056 50F5 MOVF 0xff5, W, ACCESS 0058 6F64 MOVWF 0x64, BANKED 005A 0009 TBLRD*+ 005C 0009 TBLRD*+ 005E CFF6 MOVFF 0xff6, 0x67 0060 F067 NOP 0062 CFF7 MOVFF 0xff7, 0x68 0064 F068 NOP 0066 CFF8 MOVFF 0xff8, 0x69 0068 F069 NOP 006A C060 MOVFF 0x60, 0xff6 006C FFF6 NOP 006E C061 MOVFF 0x61, 0xff7 0070 FFF7 NOP 0072 C062 MOVFF 0x62, 0xff8 0074 FFF8 NOP 0076 0100 MOVLB 0 0078 5363 MOVF 0x63, F, BANKED 007A E102 BNZ 0x80 007C 5364 MOVF 0x64, F, BANKED 007E E007 BZ 0x8e 0080 0009 TBLRD*+ 0082 50F5 MOVF 0xff5, W, ACCESS 0084 6EEE MOVWF 0xfee, ACCESS 0086 0763 DECF 0x63, F, BANKED 0088 E2F8 BC 0x7a 008A 0764 DECF 0x64, F, BANKED 008C D7F9 BRA 0x80 008E C067 MOVFF 0x67, 0xff6 0090 FFF6 NOP 0092 C068 MOVFF 0x68, 0xff7 0094 FFF7 NOP 0096 C069 MOVFF 0x69, 0xff8 0098 FFF8 NOP 009A 0100 MOVLB 0 009C 0765 DECF 0x65, F, BANKED 009E 0E00 MOVLW 0 00A0 5B66 SUBWFB 0x66, F, BANKED 00A2 D7BF BRA 0x22 00A4 0012 RETURN 0 --- E:\c18v3.46\pic18-lt\cxx-framework\src\traditional\stdclib\__init.c ------------------------ 0160 0012 RETURN 0 -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .