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

2468

Dear Sir:

I am using lpc 2468 processor and uvision compiler.

I have following c++ structure

struct{
BYTE a; //8bits
BYTE b; //8bits
WORD c; //16bit
}

in the begin, the corresponding memory is
00 00 00 00
after let's say, I assign a = 1, b = 2, I got
01 02 00 00
however, if I assign c some value, let's say, c = 0x0a0b,instead of have

01 02 0a 0b, which is what I want. I got
01 0b 0a 00.

if I change my struct to
struct{
BYTE b; //8bits
WORD c; //16bit
} and do similar assign as above, i will get
0b 0a 00 not 01 0a 0b.

Can you please tell me what is wrong and how to solve the problem?

Thank you!

Z

  • yes,

    pleaze showing the real code you be using for us to examining the detailes.

  • Please post the code where you actually do the assignment along with the actual variable definitions.
    A number of things can go wrong here. Don't forget the 'pre' and '/pre' tags.

  • Are the instructions really that difficult to see or understand:

    www.danlhenry.com/.../keil_code.png

    Don't manually re-type the code into the post - use only copy-and-paste;

    Note that TABs don't work (well) - use spaces instead,

    and don't forget to check it in the 'Preview'...

  • we is being scared he away me be thinks???

  • Dear Sir:

    Thank you all for your replies. It is a large program. Here is the part I believe it is related to this problem. Instead of getting

    0xa1 0xa2 0xc8 0x0c 0xa3 0xa4

    I actually get

    0xa1 0x0c 0xc8 0x00 0xa3 0xa4

    Thank you all.

    Regards,

    Zhan Liu

    P.S. After preview, it looks very weird and some part bbarely readable. However, I checked the "tips for postiing messages and did not know how to fix it. So I jjust post it anyway to see if it is o.k. If not, I will try to repost.

    typedef union
    {
            MP_FEEDBACK_HEADER                                                              m_Header;
            MP_UNIT_INFO_FEEDBACK                                                   m_UnitInfoFeedback;
    
            MP_UNIT_RESET_STATUS_FEEDBACK                                   m_UnitResetStatusFeedback;
    
            MP_READ_IV_FEEDBACK                                                             m_ReadIvFeedback;
    
            MP_READ_AUX_FEEDBACK                                                    m_ReadAuxFeedback;
            MP_READ_PULSE_FEEDBACK                                                  m_ReadPulseFeedback;
    
            MP_READ_IR_FEEDBACK                                                             m_ReadIrFeedback;
    
            MP_READ_SMART_BATTERY_STATE_FEEDBACK                    m_ReadSmartBatteryStateFeedback;
    
            MP_READ_SMART_BATTERY_WORD_FEEDBACK                             m_ReadSmartBatteryWordFeedback;
    
            MP_READ_SMART_BATTERY_STRING_FEEDBACK                   m_ReadSmartBatteryStringFeedback;
    
            MP_READ_SMART_BATTERY_CLOCK_STRETCH_FEEDBACK    m_ReadSmartBatteryClockStretchFeedback;
    
            MP_READ_ACI_FEEDBACK                                                    m_ReadAciFeedback;
    
            MP_READ_MCELL_ACI_FEEDBACK                                              m_ReadMCellAciFeedback;
    
            MP_POWER_ON_FEEDBACK                                                    m_PowerOnFeedback;
    
    } MP_FEEDBACK;
    
    typedef struct
    {
            BYTE m_btUnitId;
    
            BYTE m_btCmd;    // = MPC_UNIT_INFO
    
            WORD m_wFirmwareVersion;
    
            BYTE m_CheckSum[2];
    
    } MP_UNIT_INFO_FEEDBACK;
    
    
    
    void Cmd::MPUnitInfoFeedback(MP_UNIT_INFO_FEEDBACK* pFeedBack)
    {
            //zl, debug only
            pFeedBack->m_btUnitId = 0xa1;
            pFeedBack->m_btCmd = 0xa2;
            pFeedBack->m_CheckSum[0] = 0xa3;
            pFeedBack->m_CheckSum[1] = 0xa4;
            ///////////////////////////////////////
            //zl
    //      _swp(51212, &pFeedBack->m_wFirmwareVersion);
            pFeedBack->m_wFirmwareVersion)) = 51212;//zl,0xc80c
    }
    
    
    void Cmd::CmdParse(void) //a static
    
            case MPC_UNIT_INFO:
    #ifdef _DEBUG
                    SendFeedBack(MPCS_ACK, m_CmdLen +  3); //feed back the data we get from PC
    #else
                    MPUnitInfoFeedback(&m_pFeedBack->m_UnitInfoFeedback);
                    SendFeedBack(MPCS_ACK,sizeof(MP_UNIT_INFO_FEEDBACK));
    #endif
    
                    break;
    }
    
    /*
     * File:                main.c
     * Purpose:             sample program
     *
     */
    
    #include <stdio.h>
    #include "BasicDataType2468.h"  //#include "mcf5272.h"
    //#include "Sys_Init.h"
    
    #include "SF_Hwf.h"
    #include "Switch.h"
    #include "Ctrl_Arbus.h"
    #include "Ctrl_IvAdc.h"
    #include "Ctrl_BoardCfg.h"
    #include "Ctrl_Timer1ms.h"
    
    #include "Enet_Socket.h"
    
    #include "Ctrl_BoardCfg.h"
    
    #include "Ctrl_IvChan.h"
    #include "Ctrl_Pulse.h"
    #include "Ctrl_Ir.h"
    #include "Ctrl_Aci.h"
    #include "Ctrl_Ramp.h"
    #include "Ctrl_Dio.h"
    #include "Ctrl_AuxChan.h"
    
    #include "Cmd.h"
    #include "Uart_Serial.h"
    
    #include "main.h"
    
    //zl
    
    #include "VARIABLES_G.h"
    #include "target.h"
    #include "timers.h"
    
    #include "emac.h"        // Keil: Line added
    #define extern
    #include "tcpip.h"
    
    
    
    int main(void)
    {
    //zl
    #pragma arm section rwdata = "SRAM",zidata = "SRAM"              DRAM   0X80000000  0x00010000
    #pragma arm section
    //zl, end of off chip related codes
    
    
    
    Ctrl_BoardCfg::Init();
    
    
            Ctrl_BoardCfg::DetectSys();
            for(unsigned long uw32_i = 0;uw32_i < 6000000; uw32_i ++);   //              TargetResetInit();
        for(unsigned long uw32_i = 0;uw32_i < 6000000; uw32_i ++);       // µÈÂ'ýÆäËûÆ÷¼þ³õʼ»¯Ãê±Ã
    
             uw16_TimeStampNo = 0;
            uw32_TimeStamp = 0;
            Init_Device();   //2468
    
    
            Cmd::Init();
    
            for(;;)
            {
    
             if (!(SocketStatus & SOCK_ACTIVE)) TCPPassiveOpen();   // listen for incoming TCP-connection
    
                    DoNetworkStuff();       //2468
                    Cmd::CmdParse();
    
    
    
    //init device form 2468
            void Init_Device(void)
    {
    
    
    
            TCPLowLevelInit();
    
            *(unsigned char *)RemoteIP = 196; //EEP_RemoteIP[0];               // uncomment those lines to get the  Ã"¶³Ì¼ÆËã»úIP
            *((unsigned char *)RemoteIP + 1) = 168; //EEP_RemoteIP[1];          // quote of the day from a real
            *((unsigned char *)RemoteIP + 2) = 1;//EEP_RemoteIP[2];         // internet server! (gateway must be
            *((unsigned char *)RemoteIP + 3) = 100; //EEP_RemoteIP[3]  ;  //208 203; //       // set to your LAN-router)
    //
            *(unsigned char *)MyIP= 196; // EEP_RemoteIP[0];//192;                    // "MYIP1.MYIP2.MYIP3.MYIP4"    ±¾»úIP
            *((unsigned char *)MyIP + 1)= 168; //EEP_RemoteIP[1];//168;
            *((unsigned char *)MyIP + 2)= 1; //EEP_RemoteIP[2];// 1;
            *((unsigned char *)MyIP + 3)= 1; //dsp_id;
    //
           *((unsigned char *)MyMAC  + 5)= 1; //zl, //dsp_id;
    
            TCPRemotePort = 9030;//TCP_PORT_QOTD;Ã"¶³Ì¶Ë¿ÚºÅ
    
            UDPLocalPort = 2040;//2025;±¾µØ¶Ë¿ÚºÅ
            UDPRemotePort = 9040;//UDP_PORT_QOTD;Ã"¶³Ì¶Ë¿ÚºÅ
    
    
            TCPPassiveOpen();
            DELAY_SYS(6000*60); //delay 60ms
    //zl
            DoNetworkStuff();
    
    
            init_timer( 1,TIME_INTERVAL1ms);  //
            init_timer( 3,(TIME_INTERVAL1us+1)*100-1);
    
    
    }
    

  • pFeedBack->m_wFirmwareVersion)) = 51212;//zl,0xc80c
    

  • i askingh,

    pleese be showing the smallller code who be showing the error but compliles.

    you be using for us two much code who not show and comfusing me.