Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; TXD P1.0 = CLOCK
- ; RXD P1.1 = DATA
- $NOMOD51 ; importes
- #include "reg932.h" ; for
- ; at
- prog SEGMENT CODE ; undgå
- RSEG prog ; fejl
- ;
- ?C_START: ;
- public ?C_START ;
- jmp 80H ;
- org 80H ; hvad gør disse "!!!!"
- mov divm,#9 ;(120KHz)
- mov p1m1,#0 ;
- mov p1m2,#0 ; sætter portene op
- ; mov p1,#0H ;
- ; mov scon, #0 ; SKAL BRUGES DA DER ARBEJDES MED MODE-0
- call i2cinit
- //******************************
- call startc
- mov a,#10010000b
- call send
- call ack
- mov a,#10101100b
- call send
- call ack
- mov a,#00000000b
- call send
- call ack
- call stop
- //******************************
- call DEELAY
- //******************************
- call startc
- mov a,#10010000b
- call send
- call ack
- mov a,#10100001b
- call send
- call ack
- mov a,#00111001b
- call send
- call ack
- mov a,#00000000b
- call send
- call ack
- call stop
- //******************************
- call DEELAY
- //******************************
- call startc
- mov a,#10010000b
- call send
- call ack
- mov a,#10100010b
- call send
- call ack
- mov a,#00001010b
- call send
- call ack
- mov a,#00000000b
- call send
- call ack
- call stop
- //******************************
- call DEELAY
- //******************************
- call startc
- mov a,#10010000b
- call send
- call ack
- mov a,#10101010b
- call send
- call ack
- call stop
- //******************************
- jmp $
- ;***************************************
- ;Ports Used for I2C Communication
- ;***************************************
- PDA equ P1.0
- PCL equ P1.1
- ;***************************************
- ;Initializing I2C Bus Communication
- ;***************************************
- i2cinit:
- setb PDA
- setb PCL
- ret
- ;****************************************
- ;ReStart Condition for I2C Communication
- ;****************************************
- rstart:
- clr PCL
- setb PDA
- setb PCL
- clr PDA
- ret
- ;****************************************
- ;Start Condition for I2C Communication
- ;****************************************
- startc:
- setb PCL
- clr PDA
- clr PCL
- ret
- ;*****************************************
- ;Stop Condition For I2C Bus
- ;*****************************************
- stop:
- clr PCL
- clr PDA
- setb PCL
- setb PDA
- ret
- ;*****************************************
- ;Sending Data to slave on I2C bus
- ;*****************************************
- send:
- mov r7,#08
- back:
- clr PCL
- rlc a
- mov PDA,c
- setb PCL
- djnz r7,back
- clr PCL
- setb PDA
- ret
- ;*****************************************
- ;ACK and NAK for I2C Bus
- ;*****************************************
- ack:
- clr PDA
- setb PCL
- nop
- nop
- clr PCL
- setb PDA
- ret
- nak:
- setb PDA
- setb PCL
- clr PCL
- setb PCL
- ret
- ;*****************************************
- ;Receiving Data from slave on I2C bus
- ;*****************************************
- recv:
- mov r7,#08
- back2:
- clr PCL
- setb PCL
- mov c,PDA
- rlc A
- djnz r7,back2
- clr PCL
- nop
- nop
- ;setb PDA
- ret
- DEELAY:
- mov r4,#50
- DELL:
- djnz r3,DELL
- djnz r4,DELL
- ret
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement