??? 04/23/07 06:27 Modified: 04/23/07 06:32 Read: times |
#137783 - Oh dear! Responding to: ???'s previous message |
Mike Stegmaier said:
I will explain the "standard" memory addressing scheme that he talks about. When you send or receive data to a certain memory location "Sending" data from the processor to memory is commonly known as "Writing"; "Receiving" data from memory to the processor is commonly known as "Reading". a processor loads the address and data. The address is always an output from the processor - on the address bus; The data may be an output from the processor (for a Write operation), or an input to the processor (for a Read). Note that the 8051 has a 16-bit address bus, and the 8-bit data bus shares the lower 16-pins also used by the address bus (they are "multiplexed"") The address consists of two parts. The segment (or selector if you want to call it that), and the offset. No, this is wrong! The 8051 does not use a segmented mempry system like this! This applies to the x86 family - not to the 8051. Think of a segment as a "group" and think of the offset as members of the group. No, don't think like that at all for an 8051. On an 8051, there are 3 SFRs (special function registers), that define external memory. DPH, DPL, and DPTR. It's really only a single 16-bit SFR but, because the 8051 is an 8-bit processor, it has to be accessible as 2 bytes. To be precise, it defines the external memory address With MOVC, you can also use the Program Counter (PC). DPH refers to the segment, DPL refers to the offset, Not true - see above. They are simple the high and low bytes of the 16-bit address. MOVX is designed to deal with external RAM. No, it is not. The type of memory is entirely irrelevant - it could be RAM, ROM or, of course, memory-mapped IO. When data is written with MOVX the WR line is lowered for a short period of time, long enough to trigger your external ram that data is coming in. then it is raised again to avoid accidental writes. When data is read, the RD line is lowered instead for a short time. The "short period of time" is precisely defined in the so-called "bible" - in terms of the processor clock. See http://www.8052.com/forum/read.phtml?id=137654 for chapter & verse With MOVC, psen acts just like RD. So basically, MOVC is able to read your code Thus MOVC is read-only MOVC reads wnatever is in the memory that it addresses; usually you would use it to read data from CODE space, rather than to read your actual code - but you can, of course, also read the code provided that the address is low enough (less than or equal to your code rom size). Exactly what happens depends on your external memory decoding - quite often, the address space simple "wraps around". The same applies to both MOVX and MOVC. If you like to read data without worrying about (or using any) external ram, then you can use MOVC. Again, it has nothing to do with RAM. MOVC is read-only - that's the key thing. [true]with MOVC, you cannot write data[/true] (unless PSEN is connected to the write enable on your external chip). That would be bizarre, but then it would become write-only! MOVX is the only command suitable for writing data. True. The first three lines of code sends the byte representing hex code 40 to address 1234h. The segment is 12 hex and the offset is 34 hex. No it's just a 16-bit number - not Segment and Offset And its XDATA address - not CCODE address The 4th and 5th lines read the value stored at external ram address 1234h. Not necessarily RAM: say "XDATA" - it could be RAM, ROM, MMIO, etc... The last 3 lines of code read data from address 1234h in code rom Not necessarily ROM: just say "CODE" space - again, it could be RAM, ROM, MMIO, etc... the accumulator should be cleared before reading the byte. The accumulator forms part of the address - therefore it must be set to the approproiate value before reading the byte - which may or may not be zero! In all cases, when performing MMIO with an external source, it is the accumulator that handles the data. To be precise, MOVX and MOVC always use the accumulator. |