;*********************************** ;** SP1W88.inc ** ;** SP de gestion du bus 1 Wire ** ;** 16F88 à 8 MHz bus sur PB7 ** ;*********************************** CPT EQU h'3E' SAUV EQU h'3F' RAM1 EQU h'40' RAM2 EQU h'41' RAM3 EQU h'42' #DEFINE SENS TRISB,7 #DEFINE BUS PORTB,7 ;********************************************* ;** SP de reset et détection esclave ** ;** En retour: ** ;** - bit 0 de W à "1" si esclave présent ** ;** - bit 0 de W à "0" si pas d'esclave ** ;********************************************* DETECT PAGE1 BCF SENS ; Port en sortie PAGE0 BCF BUS ; Bus à "0" CALL DEL480 ; attente 480 us PAGE1 BSF SENS ; Port en entrée PAGE0 CALL DEL60 ; attente 60 us MOVLW d'01' ; b0 de W à "1" BTFSC BUS ; teste si Bus est à "0" MOVLW d'00' ; non donc b0 de W à "0" MOVWF SAUV ; sauve valeur dans W CALL DEL480 ; attente 480 us MOVFW SAUV ; restitue valeur de W RETURN ;******************************************** ;** SP attente 15 us ** ;******************************************** DEL15 MOVLW d'9' MOVWF RAM1 DEC1 DECFSZ RAM1 GOTO DEC1 RETURN ;******************************************** ;** SP attente 60 us ** ;******************************************** DEL60 MOVLW d'39' MOVWF RAM2 DEC2 DECFSZ RAM2 GOTO DEC2 RETURN ;******************************************** ;** SP attente 480 us ** ;******************************************** DEL480 MOVLW d'09' MOVWF RAM3 DEC3 DECFSZ RAM3 GOTO SUIT RETURN SUIT CALL DEL60 GOTO DEC3 ;******************************************** ;** SP Emission d'un bit ** ;** bit émis est le bit 0 de W ** ;******************************************** ENVBIT PAGE1 BCF SENS ; Port en sortie PAGE0 BCF BUS ; Bus à "0" NOP ; attente 1 us NOP MOVWF SAUV BTFSC SAUV,0 ; teste si bit 0 de W est à "0" BSF BUS ; non donc BUS à "1" tout de suite CALL DEL60 ; attente 60 us BSF BUS ; oui donc Bus à "1" aprés 60 us CALL DEL60 ; attente 60 us MOVFW SAUV PAGE1 BSF SENS ; Port en entrée PAGE0 ; donc tiré à "1" RETURN ; émission a duré 120 us ;******************************************** ;** SP réception d'un bit ** ;** Le bit lu est mis en bo de W ** ;******************************************** RECBIT PAGE1 BCF SENS ; Port en sortie PAGE0 BCF BUS ; Bus à "0" NOP NOP ; attente 1 us PAGE1 BSF SENS ; Port en entrée PAGE0 ANDLW h'FE' ; b0 à "0" les autres bits inchangés ADDLW h'01' ; bo de W mis à "1" BTFSS BUS ; teste si Bus est à "1" ANDLW h'FE' ; non donc b0 de W mis à "0" MOVWF SAUV ; sauve valeur de W CALL DEL60 CALL DEL60 ; attend 120 us MOVFW SAUV ; restitue valeur de W RETURN ; la reception a duré 120 us ;******************************************** ;** SP Emission d'un octet ** ;** Octet dans W est envoyé ** ;******************************************** ENVBYT MOVWF SAUV MOVLW d'08' MOVWF CPT ; CPT=8 MOVFW SAUV ENV CALL ENVBIT ; envoi le bit en b0 de W MOVWF SAUV RRF SAUV MOVFW SAUV ANDLW h'7F' BTFSC C ADDLW h'80' DECFSZ CPT GOTO ENV RETURN ;******************************************** ;** SP Réception d'un octet ** ;** Octet reçu mis dans W ** ;******************************************** RECBYT MOVWF SAUV MOVLW d'08' MOVWF CPT ; CPT=8 MOVFW SAUV REC CALL RECBIT MOVWF SAUV RRF SAUV MOVFW SAUV ANDLW h'7F' BTFSC C ADDLW h'80' DECFSZ CPT GOTO REC RETURN