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

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
  • If you have a 24-bit number and wants to split it into three individual bytes, you can do that in a number of ways.

    To extract an 8-bit group of bits from the larger integer, you may use either % or & (modulo or bit-and).

    To move bits down to the least significant part of the integer, before extracting them, you may use >> or / (right-shift or division).

    There is nothing magic about your RAM chip - it just needs an address of the required width, and the hardware interface of your processor don't have any magic function that can directly accept a 24-bit wide address.

    We don't know the contents of the helper functions (or macros) used, so maybe the code is using three 8-bit ports to send out the address. Or maybe it is using one 8-bit port and a couple of signals on another 8-bit port, and then sending out the three bytes of the address to three external 8-bit latches.

    The duplication of some of the source lines, is - as Andy notes - a way to slow down your processor, to make sure that the written data has enough time to settle before the RAM latches it, and to make sure that the write pulse is long enough. You should make yourself familiar with the settle and hold times specified in the RAM datasheet. When writing this kind of code, it is also required to verify the timing by using an oscilloscope and measure on the actual signals.

    Of course, all code like this should be properly documented. There should be information about the maximum speed you may run the processor in, to still fulfill the timing. Note that both clock frequency and the processors required clock count/instruction will affect the timing. And in some situations, a change of compiler or change of compiler settings may change the timing. C can't guarantee exact timing, but in this case you don't need exact timing. It doesn't matter if the timing is a bit too slow, but it may not be too fast.

Reply
  • If you have a 24-bit number and wants to split it into three individual bytes, you can do that in a number of ways.

    To extract an 8-bit group of bits from the larger integer, you may use either % or & (modulo or bit-and).

    To move bits down to the least significant part of the integer, before extracting them, you may use >> or / (right-shift or division).

    There is nothing magic about your RAM chip - it just needs an address of the required width, and the hardware interface of your processor don't have any magic function that can directly accept a 24-bit wide address.

    We don't know the contents of the helper functions (or macros) used, so maybe the code is using three 8-bit ports to send out the address. Or maybe it is using one 8-bit port and a couple of signals on another 8-bit port, and then sending out the three bytes of the address to three external 8-bit latches.

    The duplication of some of the source lines, is - as Andy notes - a way to slow down your processor, to make sure that the written data has enough time to settle before the RAM latches it, and to make sure that the write pulse is long enough. You should make yourself familiar with the settle and hold times specified in the RAM datasheet. When writing this kind of code, it is also required to verify the timing by using an oscilloscope and measure on the actual signals.

    Of course, all code like this should be properly documented. There should be information about the maximum speed you may run the processor in, to still fulfill the timing. Note that both clock frequency and the processors required clock count/instruction will affect the timing. And in some situations, a change of compiler or change of compiler settings may change the timing. C can't guarantee exact timing, but in this case you don't need exact timing. It doesn't matter if the timing is a bit too slow, but it may not be too fast.

Children
No data