*/
If you have a PH account, you can customize your PH profile.
*/

View \ROUTINE.SRC

Code from app note AN425 using the 8584

Submitted By: WEBMASTER
Rating: (Not rated) (Rate It)


$TITLE (Routines for PCD8584)
;Program written for PCD8584 as master
;
        PUBLIC READBYTE,READCONTR,SENDBYTE,SENDCONTR,START,STOP
        PUBLIC I2C_INIT
        EXTRN  BIT(I2C_END,DIR)
        EXTRN  DATA(SLAVE,IIC_CNT,NR_BYTES)
        EXTRN  NUMBER(SLAVE_ADR,I2C_CLOCK,PCD8584)
;
;Define code segment
ROUTINE   SEGMENT CODE
          RSEG    ROUTINE
;
;SENDBYTE sends a byte to PCD8584 with A0=0
;Byte to be send must be in accu
SENDBYTE:
        MOV DPTR,#PCD8584 ;Register address
SEND:   MOVX @DPTR,A    ;Send byte
        RET
;
;SENDCONTR sends a byte to PCD8584 with A0=1
;Byte to be send must be in accu
SENDCONTR:
        MOV DPTR,#PCD8584+01H ;Register address
        JMP SEND
;
;READBYTE reads a byte from PCD8584 with A0=0
;Received byte is stored in accu
READBYTE:
        MOV DPTR,#PCD8584 ;Register address
REC:    MOVX A,@DPTR    ;Receive byte
        RET
;
;READCONTR reads a byte from PCD8584 with A0=1
;Received byte is stored in accu
READCONTR:
        MOV DPTR,#PCD8584+01H ;Register address
        JMP REC
;
;START tests if the I2C bus is ready. If ready a START-condition
;will be sent, interrupt generation and acknowledge will be
;enabled.
START:  MOV IIC_CNT,#00 ;Clear  I2C byte counter
        JB DIR,PROCEED  ;If DIR is 'receive' then
        INC NR_BYTES    ;increment NR_BYTES
PROCEED:MOV A,#40H      ; Read STATUS register of 8584
        CALL SENDCONTR
TESTBB: CALL READCONTR
        JNB ACC.0,TESTBB; Test BB/ bit
        MOV A,SLAVE
        CLR I2C_END     ;Reset I2C ready bit
        CALL SENDBYTE   ;Send slave address
        MOV A,#01001101B;Generate START, set ENI, set ACK
        CALL SENDCONTR
        RET
;
;STOP will generate a STOP condition and set the I2C_END bit
STOP:   MOV A,#11000011B
        CALL SENDCONTR  ;Send STOP condition
        SETB I2C_END    ;Set I2C_END bit
        RET
;
;I2C_init does the initialisation of the PCD8584
I2C_INIT:
;Write own slave address
        CLR A
        CALL SENDCONTR  ;Write to control register
        MOV A,#SLAVE_ADR
        CALL SENDBYTE    ;Write to own slave register
;Write clock register
        MOV A,#20H     
        CALL SENDCONTR  ;Write to control register
        MOV A,#I2C_CLOCK
        CALL SENDBYTE   ;Write to clock register
        RET
;
        END

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.