The compiler is smart
If the compiler thinks that some code does nothing useful, then it will optimise that bit of code away to nothing.
This is why your listing file shows most of the code missing
Real code will usually make use of all variables, so this would not usually be an issue
Your test code does not "use" the results, so one option is to "use" the results in any way you prefer.
I usually send the results of variables to any old LAT register (which is sometimes handy for view attached LEDs)
There is a second issue. There is a strange debugger issue, whereby local variables may not show.
A work-around is to use only global variables - at least while debugging.
Annoying, but sometimes necessary.
Using only global variables has the added benefit of fooling the compiler into compiling all code without optimising away unused code
This seems to work for me:
Code: Select all
// PIC18F2550 on StartUSB board with 8MHz 2-pin crystal fitted
// build the project and run the debugger and step-over to get cycles count (delta)
// you are using StartUSB board, so you will need to run software simulator debugger, not hardware debugger
// I see at Watch window only Ports and pPort.
// Other are not visible.
// At the final I want to make the code working, but at the time i is not.
// I can not get unsigned int address (&LATB for example) stored in DLByte (oxf8a)
// of structure PortsStruct as 4-th element of array Ports using pointer to the array.
typedef struct PortsStruct {
unsigned char PortNum;
unsigned int* DLByte;
unsigned int* PLByte;
unsigned char DLBit; // should be sbit, but error
unsigned char PLBit; // should be sbit, but error
// sbit DLBit at LATA3_bit;
} PortsStruct, *pPortsStruct;
// all variables global to avoid debugger bug where variables do not show in watch window
const struct PortsStruct* pPort;
struct PortsStruct* pPortTmp;
unsigned char portNumP;
unsigned int pPortNum;
unsigned int* DLByteTmp = 0;
unsigned int Tmp;
void main() {
const struct PortsStruct Ports[9] = {
{1, &LATA, &LATA, 0, 1}, // Port1[0] - LATA RA0 & RA1
{2, &LATA, &LATA, 2, 3}, // Port2[1] - LATA RA2 & RA3
{3, &LATA, &LATA, 4, 5}, // Port3[2] - LATA RA4 & RA5
{4, &LATB, &LATB, 0, 1}, // Port4[3] - LATB RB0 & RB1
{5, &LATB, &LATB, 4, 8}, // Port5[4] - LATB RB2 & RB3
{6, &LATB, &LATB, 4, 5}, // Port6[5] - LATB RB4 & RB5
{7, &LATC, &LATC, 0, 1}, // Port7[6] - LATC RC0 & RC1
{8, &LATC, &LATC, 2, 3}, // Port8[7] - LATC RC2 & RC6
{9, &LATC, &LATC, 7, 7} // Port9[8] - LATC RC7
};
pPort = &Ports;
portNumP = 4;
pPortNum = (pPort + portNumP - 1);
DLByteTmp = *(pPortTmp)->DLByte;
// compiler will optimise away any unused variables, so let's send variables to LATC to "use" them
//LATC = portNumP; // pointless unless debugging - comment out if using gobal variables
//LATC = pPortNum; // pointless unless debugging - comment out if using gobal variables
//LATC = DLByteTmp; // pointless unless debugging - comment out if using gobal variables
while(1); // infinite loop to aid debugging
}