You have to understand that the "code" Y VAR PORTA.0 isn't something that is actually being executed on the PIC itself. It's simply a way to inform the compiler that you, in your code, want bit 0 of PortA to be "named" Y. And since it IS something that the compiler handles when it converts your program from PBP into ASM (which is then assembled by the assembler) it can not later be changed by the running program.Yes I see.
Even this does not works:
Code:IF X=1 then Y var PORTA.0 else Y var PORTA.1
You can call it a limitation if you like but it's just the way it works.So this is just compiler limitation, right?
No. But you can do this:For the arrays, can be port name in it?Here, idx acts as an offset from PortA.0Code:idx VAR BYTE idx = 9 PortA.0[idx] = 1
If you look at the datasheet for the PIC you'll find that the Port registers are consecutive in the memory map so by counting 9 bits from bit 0 of PortA.0 you'll end up PortB.1.
So with this method you can use an Array to hold your seven offsets and redifine those offsets at will, something like this (untested and uncompiled, treat it accordingly):Code:X VAR BYTE[7] ' Array to hold the bit offset from PortA.0 idx VAR BYTE ' Temporary variable needed to actually use the indexing Main: GOSUB DG1 idx = X[2] ' Since X[2] contains the value 17, so will idx PortA.0[idx] = 1 ' Write to "PortA.17" which in real life will be PortC.1 GOSUB DG2 idx = X[2] ' Now that we've changed the values in the X-Array, X[2] contains the value 18 and so will idx PortA.0[idx] = 1 ' Write to PortC.2 END DG1: X[0] = 27 ' AX VAR PORTD.3 X[1] = 20 ' BX VAR PORTC.4 X[2] = 17 'CX VAR PORTC.1 X[3] = 18 'DX VAR PORTC.2 X[4] = 24 'EX VAR PORTD.0 X[5] = 26 'FX VAR PORTD.2 X[6] = 21 'GX VAR PORTC.5 RETURN DG2: X[0] = 28 ' AX VAR PORTD.4 X[1] = 21 ' BX VAR PORTC.5 X[2] = 18 'CX VAR PORTC.2 X[3] = 19 'DX VAR PORTC.3 X[4] = 25 'EX VAR PORTD.1 X[5] = 27 'FX VAR PORTD.3 X[6] = 22 'GX VAR PORTC.6 RETURN




Bookmarks