كيف اخوتي الكرام اريد مساعدة فيما يخص البروتوكول i2c
كيف يمكنني تخزين امعطيات في eeprom
بواسطة pic16f877 et 24cl256
بلغة asm
وهل هذا الكود صحيح
;############################################
; Ecrit des octets dans l'EEPROM
EEWrite
call I2CStart ; bit de start
MOVLW Wr_TIMER
call I2CSendByte
call I2CWaitAck1
MOVLW 0x00
call I2CSendByte
call I2CWaitAck1
F_BANK 1
MOVFF retard5,W
F_BANK 0
call I2CSendByte
call I2CWaitAck1
F_BANK 1
MOVFF retard4, W
F_BANK 0
call I2CSendByte
call I2CWaitAck1
F_BANK 1
MOVFF retard3, W
F_BANK 0
call I2CSendByte
call I2CWaitAck1
MOVLW 0x01
call I2CSendByte
call I2CWaitAck1
MOVLW 0x17
call I2CSendByte
call I2CWaitAck1
MOVLW 0x06
call I2CSendByte
call I2CWaitAck1
MOVLW 0x05
call I2CSendByte
call I2CWaitAck1
call I2CStop
call Tp_05 ; Tempo d'écriture (5ms)
return
;#############################################
;Temporisations
Tp_05
MOVLW 05 ; tempo 5ms
goto Tp_xx
Tp_125
MOVLW 07Dh
Tp_xx
MOVWF Var1
tp1
MOVLW 0F9h ; 3.2768Mhz/0CCh, 4Mhz/0F9h
MOVWF Var2
tp2
nop
decfsz Var2
goto tp2
decfsz Var1
goto tp1
return
;#####################################################
; Fonction envoyant un bit de START pour l'I2C interne
I2CStartLoad
bsf PORTC,SDA
call Wait_04
bsf PORTC,SCL ;préparation pour bit de start
call Wait_04
I2CStart
call Wait_06
bcf PORTC,SDA
call Wait_06
bcf PORTC,SCL
call Wait_04
return
;#######################################
; Fonction envoyant un bit de STOP
I2CStop
bcf PORTC,SDA ; préparation pour bit de stop
call Wait_06
bsf PORTC,SCL
call Wait_06
bsf PORTC,SDA
call Wait_04
return
;#######################################################
; Fonction qui envoie l'acquittement vers une EEPROM
I2CSendAck
bcf PORTC,SDA
call Wait_04
bsf PORTC,SCL ; impulsion d'horloge
call Wait_04
bcf PORTC,SCL
call Wait_04
return
;######################################################
; Fonction qui envoie l'acquittement vers une EEPROM
I2CSendNoAck
bsf PORTC,SDA
call Wait_04
bsf PORTC,SCL ; impulsion d'horloge
call Wait_04
bcf PORTC,SCL
call Wait_04
return
;##################################################
;Fonction qui reçoit un octet venant de l'EEPROM
I2CReceiveByte
F_BANK 1
MOVLW 10h
MOVWF TRISC ; mise de SDA en lecture
F_BANK 0
clrf I2C_Receive
MOVLW 8
MOVWF Var1 ; compteur de bits
bcl_rcp
call Wait_04
bsf PORTC,SCL ; impulsion d'horloge
call Wait_04
btfss PORTC,SDA
goto SD0_rcp ; si SDA=0
SD1_rcp
nop ; si SDA=1
bsf STATUS,C
goto st_rcp
SD0_rcp
bcf STATUS,C
goto st_rcp
st_rcp
bcf PORTC,SCL
rlf I2C_Receive
decfsz Var1
goto bcl_rcp
F_BANK 1
MOVLW 00h
MOVWF TRISC ; mise de SDA en écriture
F_BANK 0
call Wait_04
return
;################################
; tempo en µs
Wait_10
goto Wait_08
Wait_08
goto Wait_06
Wait_06
goto Wait_04
Wait_04
return
;##################################
I2CWaitAck1
BSF PORTC,SDA
F_BANK 1
MOVLW 10h
MOVWF TRISC ; mise de SDA en lecture
F_BANK 0
call Wait_04
bsf PORTC,SCL ; impulsion d'horloge
call Wait_04
bcl_ack1
btfsc PORTC,SDA
goto bcl_ack1 ; recommence si SDA=1
bcf PORTC,SCL ; impulsion d'horloge
call Wait_04
Fin_ack1
F_BANK 1
MOVLW 00h
MOVWF TRISC
F_BANK 0
return
;##############################################
; Fonction qui envoie un octet sur le bus I2C pour les EEPROM
; W doit contenir la données à envoyer
I2CSendByte
MOVWF I2C_Send
MOVLW 8
MOVWF Var1 ; compteur de bits
bcl_env
rlf I2C_Send
btfss STATUS,C
goto C0_env ; si Carry=0
C1_env
nop ; si Carry=1
bsf PORTC,SDA
goto st_env
C0_env
bcf PORTC,SDA
goto st_env
st_env
bsf PORTC,SCL ; impulsion d'horloge
call Wait_04
bcf PORTC,SCL
decfsz Var1
goto bcl_env
rlf I2C_Send ; repositionnement du buffer I2C
bsf PORTC,SDA ; préparation de l'ACKownledge
return
;############################################
شكرا

