??? 04/23/07 03:57 Read: times Msg Score: -1 -1 Answer is Wrong |
#137776 - oh my Responding to: ???'s previous message |
Its quite amazing how much exposure one error has in a thread :)
Now I will try to provide useful information. Andy Neil said:
"Memory-Mapped IO" means that the IO is accessed by the processor's standard memory access scheme; ie, via the Data and Address busses - as opposed to directly accessing the ports, or using some serial scheme, etc.
On an 8051, this means using the MOVX instruction (or, for read-only, you could possibly use MOVC). I will explain the "standard" memory addressing scheme that he talks about. When you send or receive data to a certain memory location, a processor loads the address and data. The address consists of two parts. The segment (or selector if you want to call it that), and the offset. Think of a segment as a "group" and think of the offset as members of the group. On an 8051, there are 3 SFRs (special function registers), that define external memory. DPH, DPL, and DPTR. DPH refers to the segment, DPL refers to the offset, and DPTR is both DPH and DPL together to form the complete memory address. Do you understand how the 8051's external memory accessing works? ie, how it uses the data & address busses and the other control lines (ALE, /PSEN, /RD, /WR)? I will explain this too. MOVX is designed to deal with external RAM. 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. With MOVC, psen acts just like RD. So basically, MOVC is able to read your code provided that the address is low enough (less than or equal to your code rom size). If you like to read data without worrying about (or using any) external ram, then you can use MOVC. with MOVC, you cannot write data (unless PSEN is connected to the write enable on your external chip). MOVX is the only command suitable for writing data. I will show some code below and explain them. mov DPTR,#1234h mov A,#40h movx @DPTR,A mov DPTR,#1234h movx A,@DPTR mov DPTR,#1234h clr A movc A,@A+DPTR 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. The 4th and 5th lines read the value stored at external ram address 1234h. If the first 5 lines of code were executed in a program, then A will equal 40h, even if some code modified "A" between the 3rd and 5th line of code. The last 3 lines of code read data from address 1234h in code rom, not external ram. the accumulator should be cleared before reading the byte. In all cases, when performing MMIO with an external source, it is the accumulator that handles the data. |