Interface Code for Communicating to the MCP-1200
The MCP-1200 has three different timing options for reading and writing to the chip.
- /ALE, /CS Non-overlapped
- /ALE, /CS Overlapped
- /ALE within /CS
The code given below is an example of how the firmware on a microcontroller can easily communicate to the MCP-1200 using an 8-bit port.
Routine MREAD
- Reads a MCP-1200 register (uses ALE/CS Overlapped Mode)
- Address latched according to value of Overlapped Mode
- On entry: Acc holds the register address
- On exit: Acc holds register value
MREAD: | mov | P1MDOUT,#0FFh | ; Port 1, Push-Pull Drivers |
setb | R_W | ; Set high for Read | |
move | P1,A | ; Place address on port | |
clr | ALEn | ; Set ALE low | |
clr | CSn | ; Latch Address, Overlapped Mode | |
setb | ALEn | ||
setb | CSn | ||
mov | P1MDOUT, #00h | ; set port to open collector | |
mov | P1, #0FFh | ; and high to enable inputs | |
clr | OEn | ; set OE low | |
nop | |||
mov | A,P1 | ; read data byte | |
setb | OEn | ; reset OE | |
mov | P1MDOUT, #0FFh | ; restore Port 1 to push-pull | |
ret | |||
Routine MWRITE
- Writes a value to a MCP-1200 register (uses ALE/CS Overlapped Mode)
- On entry: R2 holds the register address
- On entry: Acc holds data value
MWRITE: | mov | P1MDOUT,#0FFh | ; Port 1, Push-Pull Drivers |
clr | R_W | ; Set low for Write | |
mov | P1,P2 | ; Place address on port | |
clr | ALEn | ||
clr | CSn | ; Latch address, Overlapped Mode | |
setb | ALEn | ||
mov | P1,A | ; Place data on port | |
nop | |||
setb | CSn | ; Latch Data | |
setb | R_W | ||
ret | |||