Interface Code for Communicating to the MCP-1200

The MCP-1200 has three different timing options for reading and writing to the chip.

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

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

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