This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

More Pointer Problems

Here's another good one. Again, works fine on simulator/debugger, but not on the target hardware.

If I do this:

BYTE process_Help(char *cmdBuffer) reentrant
{
cmdBuffer[0] = '\0';
printf( "Help Message");
return TRUE;
}

everything works fine. But if I do this:

BYTE process_Help(char *cmdBuffer) reentrant
{
char *strHelp = "Help Message";
cmdBuffer[0] = '\0';
printf(strHelp);
return TRUE;
}

it works fine on the simulator/debugger, but nothing is displayed when executed on the target hardware.

Any/All help welcome and appreciated.

Thanks,
Chris Beattie

Parents
  • Your code uses funtion pointers. They are tricky to use in the Keil c51 compiler. If you can, delare them in the function that uses them. Otherwise you have to do some tricky stuff with the linker.

    I suggest to change HandleNormalData to:

    BYTE process_EraseFlash(char xdata *cmdBuf);
    BYTE process_ProgramFlash(char xdata *cmdBuf);
    BYTE process_GO(char xdata *cmdBuf);
    BYTE process_DisplayMemory(char xdata *cmdBuf);
    BYTE process_Help(char xdata *cmdBuf);
    
    
    void uart0_HandleNormalData(void)
    {
    	static const CmdData code gCmdTable[] = {
    	    { "EF",   process_EraseFlash          },
    	    { "PF",   process_ProgramFlash        }, 
    	    { "GO",   process_GO                  },
    	    { "DM",   process_DisplayMemory       },
    	    { "HELP", process_Help                },
    	    { "?",    process_Help                }
    	};
    	static const BYTE code gNumCmds = sizeof(gCmdTable) / sizeof(CmdData);
    
    
    //..the rest of the code
    <\pre>
    

Reply
  • Your code uses funtion pointers. They are tricky to use in the Keil c51 compiler. If you can, delare them in the function that uses them. Otherwise you have to do some tricky stuff with the linker.

    I suggest to change HandleNormalData to:

    BYTE process_EraseFlash(char xdata *cmdBuf);
    BYTE process_ProgramFlash(char xdata *cmdBuf);
    BYTE process_GO(char xdata *cmdBuf);
    BYTE process_DisplayMemory(char xdata *cmdBuf);
    BYTE process_Help(char xdata *cmdBuf);
    
    
    void uart0_HandleNormalData(void)
    {
    	static const CmdData code gCmdTable[] = {
    	    { "EF",   process_EraseFlash          },
    	    { "PF",   process_ProgramFlash        }, 
    	    { "GO",   process_GO                  },
    	    { "DM",   process_DisplayMemory       },
    	    { "HELP", process_Help                },
    	    { "?",    process_Help                }
    	};
    	static const BYTE code gNumCmds = sizeof(gCmdTable) / sizeof(CmdData);
    
    
    //..the rest of the code
    <\pre>
    

Children