interacting with a k6x8008 ram chip

hello everyone, I am reading some code on a system that connect the 8051 with an external ram chip but I have no idea what is going on with the code, I have been struggling on this for quite some time now, just want to see if anyone can point me to the right direction.

the first part i dun understand is how the ram is use

void k6x8008_writebyte (unsigned char hadd,unsigned char madd,unsigned char ladd,unsigned char indat)
{ RD = 1; WR = 1; k6x8008_laddress(ladd); k6x8008_maddress(madd); k6x8008_din(indat); k6x8008_din(indat); k6x8008_haddress(hadd); WR = 0; WR = 0; WR = 1; k6x8008_haddress(0x00); P0 = 0; WR = 1;
}

i don't understand what those ladd, madd or hadd means at all

on the main code this is the part that requires writing data to the ram...

iphadd=((subaddress&HADDBITS)/0x00010000);
ipmadd=((subaddress&MADDBITS)/0x00000100);
ipladd=((subaddress&LADDBITS)/0x00000001); k6x8008_writebyte(iphadd,ipmadd,ipladd+0x00,0xff);
k6x8008_writebyte(iphadd,ipmadd,ipladd+0x01,0xff);
k6x8008_writebyte(iphadd,ipmadd,ipladd+0x02,0xff);

why does the coder uses binary division?? and this might be abstract but im also not sure why he is writing 0xff to the ram in the part above

Parents
  • void k6x8008_writebyte (
            unsigned char hadd,
            unsigned char madd,
            unsigned char ladd,
            unsigned char indat)
    {
            RD = 1;
            WR = 1;
            k6x8008_laddress(ladd);
            k6x8008_maddress(madd);
            k6x8008_din(indat);
            k6x8008_din(indat);
            k6x8008_haddress(hadd);
            WR = 0;
            WR = 0;
            WR = 1;
            k6x8008_haddress(0x00);
            P0 = 0;
            WR = 1;
    }
    

    phadd=((subaddress&HADDBITS)/0x00010000);
    ipmadd=((subaddress&MADDBITS)/0x00000100);
    ipladd=((subaddress&LADDBITS)/0x00000001);
    k6x8008_writebyte(iphadd,ipmadd,ipladd+0x00,0xff);
    k6x8008_writebyte(iphadd,ipmadd,ipladd+0x01,0xff);
    k6x8008_writebyte(iphadd,ipmadd,ipladd+0x02,0xff);
    

    Do you have documentation on the hardware this person is accessing? I believe the answers would be more obvious if you had the hardware documentation and started commenting the could. It might be good to change the code to be less abstract. For example ipladd is probably ip_low_address which is also wrong it should be ip_LSB <standard for least significant byte> or ip_least_significant_byte. It doesn't seem space efficient but it's big and obvious.

    k6x8008_writebyte is nasty naming, it at least gives you an idea what it does however, you may wish to give it a new and more descriptive function name. Refactoring of the original code might be a good idea before you get into it. One of the most important aspects of embedded code is it MUST be maintainable.

    You should document the method and reason for each function too, that way if someone else has to deal with the code they can extol your wisdom and make changes much more easily.

    According to the internet the k6x8008 is "1Mx8 bit Low Power full CMOS Static RAM". I suggest you get the documentation on the hardware interface to make better sense of that. In fact you probably should have notes on what version of your hardware that code is for, if it is not in there that is yet another major faux pas in programming. Always keep in the comments for IO interfacing what version of the hardware that code is for. That way people can look at the correct schematic to see what is going on (and hope the schematics are kept in proper revisions). Also if the hardware changes you know what part of the code needs changed.

    Stephen

Reply
  • void k6x8008_writebyte (
            unsigned char hadd,
            unsigned char madd,
            unsigned char ladd,
            unsigned char indat)
    {
            RD = 1;
            WR = 1;
            k6x8008_laddress(ladd);
            k6x8008_maddress(madd);
            k6x8008_din(indat);
            k6x8008_din(indat);
            k6x8008_haddress(hadd);
            WR = 0;
            WR = 0;
            WR = 1;
            k6x8008_haddress(0x00);
            P0 = 0;
            WR = 1;
    }
    

    phadd=((subaddress&HADDBITS)/0x00010000);
    ipmadd=((subaddress&MADDBITS)/0x00000100);
    ipladd=((subaddress&LADDBITS)/0x00000001);
    k6x8008_writebyte(iphadd,ipmadd,ipladd+0x00,0xff);
    k6x8008_writebyte(iphadd,ipmadd,ipladd+0x01,0xff);
    k6x8008_writebyte(iphadd,ipmadd,ipladd+0x02,0xff);
    

    Do you have documentation on the hardware this person is accessing? I believe the answers would be more obvious if you had the hardware documentation and started commenting the could. It might be good to change the code to be less abstract. For example ipladd is probably ip_low_address which is also wrong it should be ip_LSB <standard for least significant byte> or ip_least_significant_byte. It doesn't seem space efficient but it's big and obvious.

    k6x8008_writebyte is nasty naming, it at least gives you an idea what it does however, you may wish to give it a new and more descriptive function name. Refactoring of the original code might be a good idea before you get into it. One of the most important aspects of embedded code is it MUST be maintainable.

    You should document the method and reason for each function too, that way if someone else has to deal with the code they can extol your wisdom and make changes much more easily.

    According to the internet the k6x8008 is "1Mx8 bit Low Power full CMOS Static RAM". I suggest you get the documentation on the hardware interface to make better sense of that. In fact you probably should have notes on what version of your hardware that code is for, if it is not in there that is yet another major faux pas in programming. Always keep in the comments for IO interfacing what version of the hardware that code is for. That way people can look at the correct schematic to see what is going on (and hope the schematics are kept in proper revisions). Also if the hardware changes you know what part of the code needs changed.

    Stephen

Children
More questions in this forum