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

over 16 bit DPTR limit

I have 8051 with 2 DPTR, SFR register to switch data banks(32Kb/16Kb)... Both DPTRs used to increment read/write pointers. I need correct 32bit address increment over all accessible memory.
How to widen DPTR to work with 32 bit address?

Parents
  • Thanks, so at the end my solution is:

    typedef union U32
    {
            unsigned long dword;
            unsigned short word[2];
            unsigned char byte[4];
    } bdata U32;
    ...
    unsigned long Inc32bitDPTR (unsigned long addr)
    {
            U32 idata tmp_dptr;
    
            tmp_dptr.dword = addr;
            tmp_dptr.dword++;
            switch (DPS)
            {
                    case 0x00:
                            DPL0 = tmp_dptr.byte[3];
                            DPH0 = tmp_dptr.byte[2];
                            break;
                    case 0x01:
                            DPL1 = tmp_dptr.byte[3];
                            DPH1 = tmp_dptr.byte[2];
            }
    
            if (tmp_dptr.dword >= MAX_ADDR)
                    tmp_dptr.dword = 0;
    
            return tmp_dptr.dword;
    }
    ...
    tmp_dptr_dst.dword = addr;//long addr;
    WriteByte (tmp_dptr_dst.dword, byte);
    tmp_dptr_dst.dword = Inc32bitDPTR(tmp_dptr_dst.dword);
    ...
    


    May be anybody realized it better and faster?

Reply
  • Thanks, so at the end my solution is:

    typedef union U32
    {
            unsigned long dword;
            unsigned short word[2];
            unsigned char byte[4];
    } bdata U32;
    ...
    unsigned long Inc32bitDPTR (unsigned long addr)
    {
            U32 idata tmp_dptr;
    
            tmp_dptr.dword = addr;
            tmp_dptr.dword++;
            switch (DPS)
            {
                    case 0x00:
                            DPL0 = tmp_dptr.byte[3];
                            DPH0 = tmp_dptr.byte[2];
                            break;
                    case 0x01:
                            DPL1 = tmp_dptr.byte[3];
                            DPH1 = tmp_dptr.byte[2];
            }
    
            if (tmp_dptr.dword >= MAX_ADDR)
                    tmp_dptr.dword = 0;
    
            return tmp_dptr.dword;
    }
    ...
    tmp_dptr_dst.dword = addr;//long addr;
    WriteByte (tmp_dptr_dst.dword, byte);
    tmp_dptr_dst.dword = Inc32bitDPTR(tmp_dptr_dst.dword);
    ...
    


    May be anybody realized it better and faster?

Children