*/
Do you receive the Programmer's Heaven newsletter? If not, why not subscribe?
*/

View \INTERR.SRC

Code from app note AN425 using the 8584

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


$TITLE (I2C INTERRUPT ROUTINE)
$PAGELENGTH(40)
;
        PUBLIC INT0_SRV
        PUBLIC DIR,I2C_END
        PUBLIC BASE,NR_BYTES,IIC_CNT,SLAVE
        EXTRN  CODE(SENDBYTE,SENDCONTR,STOP,READBYTE,READCONTR)
;
;Define variables in RAM
IIC_VAR SEGMENT DATA
        RSEG IIC_VAR
BASE:   DS 1            ;Pointer to I2C table (till 256)
NR_BYTES: DS 1          ;Number of bytes to rcv/trm
IIC_CNT:DS 1            ;I2C byte counter
SLAVE:  DS 1            ;Slave address after START
;
;Define variable segment
BIT_VAR SEGMENT DATA BITADDRESSABLE
        RSEG BIT_VAR               
STATUS: DS 1            ;Byte with flags
I2C_END BIT STATUS.0    ;Defines if a I2C transmission is finished
                        ;'1' is finished
                        ;'0' is not ready
DIR     BIT STATUS.3    ;Defines direction of I2C transmission
                        ;'1':Transmit    '0':Receive
;
;Define code segment for routine
IIC_INT SEGMENT CODE PAGE
        RSEG IIC_INT
;
;Program uses registers in RB1
        USING 1
;
INT0_SRV:
        PUSH ACC        ;Save acc. en psw on stack
        PUSH PSW
        MOV PSW,#08H    ;Select register bank 1
        JNB DIR,RECEIVE ;Test direction bit
                        ;8584 is MST/TRM

;Program part to transmit bytes to IIC bus
        MOV A,IIC_CNT   ;Compare IIC_CNT and NR_BYTES
        CJNE A,NR_BYTES,PROCEED
        CALL STOP       ;All bytes transmitted
        JMP EXIT
PROCEED:MOV R0,BASE     ;RAM pointer
        MOV A,@R0       ;Source is internal RAM
        INC BASE        ;Update pointer of table
        CALL SENDBYTE   ;Send byte to IIC bus
        INC IIC_CNT     ;Update byte counter
        JMP EXIT                             
;
;
;Program to receive byte from IIC bus
RECEIVE:
        MOV A,IIC_CNT   ;Test if last byte is to be received
        INC A
        INC A
        CJNE A,NR_BYTES,PROC_RD
        MOV A,#01001000B;Last byte to be received. Disable ACK
        CALL SENDCONTR  ;Write control word to PCD8584
PROC_RD:CALL READBYTE   ;Read I2C byte
        MOV R4,A        ;Save accu
;If RECEIVE is entered after the transmission of START+address
;then the result of READBYTE is not relevant. READBYTE is used to start
;the generation of the clock pulses for the next byte to read.
;This situation occurs when IIC_CNT is 0
        CLR A           ;Test IIC_CNT
        CJNE A,IIC_CNT,SAVE
        JMP END_TEST    ;START is send. No relevant data in data reg. of 8584
SAVE:   MOV R0,BASE
        MOV A,R4        ;Destination is internal RAM
        MOV @R0,A
        INC BASE
END_TEST:INC IIC_CNT   ;Test if all bytes are received
        MOV A,NR_BYTES
        CJNE A,IIC_CNT,EXIT
        CALL STOP       ;All bytes received
;       
EXIT:   POP PSW         ;Restore PSW and accu
        POP ACC
        RETI   
;
        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.