$NOSYMBOLS ; ohne Symboltabelle im Listing $NOMOD51 ; 8051-Modus ausschalten $INCLUDE (REG509.INC) ; Einbinden der Registernamen des C509 MOV P5,#00 MOV R6,#06 ;--------------------------------------------------------------------------------------------------- start: CALL startc MOV A,#11010000b ;Slaveadresse DS1307 CALL send MOV A,#00H ;Registeradresse CALL send MOV A,#00000101b ;Daten CALL send CALL stop CALL startc MOV A,#11010000b CALL send MOV A,#07H CALL send MOV A,#10010000b CALL send CALL stop back_1: CALL startc ;Stackpointer wird auf Register 00h gesetzt MOV A,#11010000b CALL send MOV A,#00H CALL send CALL stop back_2: CALL startc MOV A,#11010001b CALL send CALL recv CALL stop MOV P5,A JMP back_1 ;Leseschlaufe des Registers 00h ;************************************************************************ ; I2C PROTOCOL LIBRARY ;************************************************************************ ;************************************************************************ ; Ports Used for I2C Communication ;************************************************************************ sda equ P1.7 scl equ P1.6 ;************************************************************************ ; Start Condition for I2C Communication ;************************************************************************ startc: clr scl setb sda nop nop setb scl nop nop clr sda ret ;************************************************************************ ; Stop Condition For I2C Bus ;************************************************************************ stop: nop nop clr sda setb scl nop nop setb sda nop nop clr scl ret ;************************************************************************ ; Sending Data to slave on I2C bus ; with Acknowledgement ;************************************************************************ send: mov r7,#8 back: clr scl nop nop nop rlc a mov sda,c setb scl nop nop nop clr scl nop nop nop djnz r7,back clr sda setb scl nop nop nop nop clr scl nop nop nop ret ;************************************************************************ ; Receiving Data from slave on I2C bus ; with Acknowledgement ;************************************************************************ recv: mov r7,#08 back2: setb sda setb scl nop nop nop mov c,sda rlc a clr scl nop nop nop djnz r7,back2 SETB SDA SETB SCL END