begin process at 2010 03 19 16:37:53
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Les PIC

 > BUS I2C POUR PIC16XXX

BUS I2C POUR PIC16XXX


 Information sur la source

Note :
8 / 10 - par 1 personne
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Les PIC Niveau :Débutant Date de création :08/06/2003 Date de mise à jour :08/06/2003 22:14:15 Vu / téléchargé :11 523 / 745

Auteur : tranquilos

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Que dire de plus, que vous trouverez ici les principales commandes I2C.
Il vous suffit ensuite en fonction du composant avec lequel vous communiquez, de les assember dans le bon ordre.

Source

  • ;
  • ; Routines I2C V1.0
  • ;
  • ; O.R 04/2003
  • ;-----------------------------------------------------------------------------------------
  • ;
  • ;
  • ; Cette routine nécessite :
  • ; - Les deux macros : SDA_IN et SDA_OUT
  • ; - Les variables : I2C_flag, I2C_DATA, I
  • ; - Le fichier : Q4mhz.asm
  • ;
  • ;
  • I2C_INIT:
  • SDA_OUT ;SDA en sortie
  • bsf SDA ;SDA a 1
  • bsf SCL ;SCL a 1
  • return
  • I2C_START: ;SDA_OUT
  • ;SDA=1 SCL=1
  • bsf SCL ;SCL a 1
  • bsf SDA ;SDA a 1
  • bcf SDA ;SDA a 0
  • return
  • I2C_STOP: ;SDA_OUT
  • ;SDA=X SCL=0
  • bcf SDA ;SDA a 0
  • bsf SCL ;SCL a 1
  • bsf SDA ;SDA a 1
  • return
  • I2C_SLAVE_ACK: ;SDA_OUT
  • ;SDA=X SCL=0
  • bcf SCL ;SCL a 0
  • SDA_IN ;SDA en entrée
  • CALL Tempo_11us
  • bsf SCL ;SCL a 1
  • CALL Tempo_11us
  • btfsc SDA ;Si 1 ecriture d'un flag d'erreur
  • call NO_ACK
  • bcf SCL ;SCL a 0
  • CALL Tempo_11us
  • SDA_OUT ;SDA en sortie
  • return
  • I2C_MASTER_ACK: ;SDA_IN
  • ;SDA=X SCL=0
  • bcf SCL ;SCL a 0
  • SDA_OUT ;SDA en sortie
  • bcf SDA ;SDA a 0
  • bsf SCL ;SCL a 1
  • CALL Tempo_11us
  • bcf SCL ;SCL a 0
  • CALL Tempo_11us
  • bsf SDA ;SDA a 1
  • return
  • I2C_MASTER_NACK: ;SDA_IN
  • ;SDA=X SCL=0
  • bcf SCL ;SCL a 0
  • SDA_OUT ;SDA en sortie
  • bsf SDA ;SDA a 1
  • bsf SCL ;SCL a 1
  • CALL Tempo_11us
  • bcf SCL ;SCL a 0
  • CALL Tempo_11us
  • bcf SDA ;SDA a 0
  • return
  • I2C_SEND_BYTE:
  • movwf I2C_DATA ;w contient les data a envoyer
  • movlw d'8'
  • movwf I
  • Next_data_s:
  • decf I,f
  • bcf SCL ;SCL a 0
  • CALL Tempo_11us
  • rlf I2C_DATA,f ;Rotation a gauche bit(I) dans la carry
  • btfsc carry ;Si I=1
  • bsf SDA ;SDA a 1
  • btfss carry ;Si I=0
  • bcf SDA ;SDA a 0
  • bsf SCL ;SCL a 1
  • CALL Tempo_11us
  • incf I,f
  • decfsz I,f ;Si I!=0
  • goto Next_data_s
  • bcf SCL ;SCL a 0
  • CALL Tempo_11us
  • call I2C_SLAVE_ACK
  • return
  • I2C_RECEIVE_BYTE:
  • movlw d'8'
  • movwf I
  • clrf I2C_DATA
  • SDA_IN ;SDA en entrée
  • Next_data_r:
  • decf I,f
  • bcf SCL ;SCL a 0
  • CALL Tempo_11us
  • bsf SCL ;SCL a 1
  • CALL Tempo_11us
  • btfsc SDA ;Si SDA=1
  • bsf carry
  • btfss SDA ;Si SDA=0
  • bcf carry
  • rlf I2C_DATA,f ;décallage à gauche et met la carry dans le LSB
  • incf I,f
  • decfsz I,f ;Si I!=0
  • goto Next_data_r
  • bcf SCL ;SCL a 0
  • CALL Tempo_11us
  • call I2C_MASTER_ACK
  • return
  • I2C_RECEIVE_BYTE_LAST:
  • movlw d'8'
  • movwf I
  • SDA_IN ;SDA en entrée
  • Next_data_rl:
  • decf I,f
  • bcf SCL ;SCL a 0
  • CALL Tempo_11us
  • bsf SCL ;SCL a 1
  • CALL Tempo_11us
  • btfsc SDA ;Si SDA=1
  • bsf carry
  • btfss SDA ;Si SDA=0
  • bcf carry
  • rlf I2C_DATA,f ;décallage à gauche et met la carry dans le LSB
  • incf I,f
  • decfsz I,f ;Si I!=0
  • goto Next_data_rl
  • bcf SCL ;SCL a 0
  • CALL Tempo_11us
  • call I2C_MASTER_NACK
  • return
  • ;-----------------------------------------------------------------------------------------
  • ; I2C_flag
  • ; 0: NO_ACK
  • ; 1:
  • ; 2:
  • ; 3:
  • ; 4:
  • ; 5:
  • ; 6:
  • ; 7:
  • ;
  • NO_ACK:
  • bsf I2C_flag,0 ;Pas d'ack de l'esclave -> problème de comm
  • return
;
;			Routines I2C                            	V1.0
;
;									O.R	04/2003
;-----------------------------------------------------------------------------------------
;
;
;	Cette routine nécessite :
;		- Les deux macros 	: SDA_IN et SDA_OUT
;		- Les variables   	: I2C_flag, I2C_DATA, I
;		- Le fichier	  	: Q4mhz.asm
;
;


I2C_INIT:
	SDA_OUT			;SDA en sortie
	bsf	SDA		;SDA a 1
	bsf	SCL		;SCL a 1

	return

I2C_START:			;SDA_OUT
				;SDA=1 SCL=1
	bsf	SCL		;SCL a 1
	bsf	SDA		;SDA a 1
	bcf	SDA		;SDA a 0		

	return

I2C_STOP:			;SDA_OUT
				;SDA=X SCL=0
	bcf	SDA		;SDA a 0
	bsf	SCL		;SCL a 1
	bsf	SDA		;SDA a 1		

	return

I2C_SLAVE_ACK:			;SDA_OUT
				;SDA=X SCL=0
	bcf	SCL		;SCL a 0
	SDA_IN			;SDA en entrée
	CALL	Tempo_11us
	bsf	SCL		;SCL a 1
	CALL	Tempo_11us
	btfsc	SDA		;Si 1 ecriture d'un flag d'erreur
	call	NO_ACK
	bcf	SCL		;SCL a 0
	CALL	Tempo_11us

	SDA_OUT			;SDA en sortie

	return

I2C_MASTER_ACK:			;SDA_IN 
				;SDA=X SCL=0
	bcf	SCL		;SCL a 0
	SDA_OUT			;SDA en sortie
	bcf	SDA		;SDA a 0 
	bsf	SCL		;SCL a 1
	CALL	Tempo_11us
	bcf	SCL		;SCL a 0
	CALL	Tempo_11us
	bsf	SDA		;SDA a 1

	return

I2C_MASTER_NACK:		;SDA_IN 
				;SDA=X SCL=0
	bcf	SCL		;SCL a 0
	SDA_OUT			;SDA en sortie
	bsf	SDA		;SDA a 1 
	bsf	SCL		;SCL a 1
	CALL	Tempo_11us
	bcf	SCL		;SCL a 0
	CALL	Tempo_11us
	bcf	SDA		;SDA a 0 
	
	return

I2C_SEND_BYTE:
	movwf	I2C_DATA	;w contient les data a envoyer
	movlw	d'8'
	movwf	I
Next_data_s:
	decf	I,f
	bcf	SCL		;SCL a 0
	CALL	Tempo_11us
	rlf	I2C_DATA,f	;Rotation a gauche bit(I) dans la carry
	btfsc	carry		;Si I=1
	bsf	SDA		;SDA a 1
	btfss	carry		;Si I=0
	bcf	SDA		;SDA a 0
	bsf	SCL		;SCL a 1 
	CALL	Tempo_11us
	incf	I,f
	decfsz	I,f		;Si I!=0
	goto	Next_data_s

	bcf	SCL	;SCL a 0
	CALL	Tempo_11us

	call	I2C_SLAVE_ACK

	return

I2C_RECEIVE_BYTE:
	movlw	d'8'
	movwf	I
	clrf	I2C_DATA
	SDA_IN			;SDA en entrée
Next_data_r:
	decf	I,f
	bcf	SCL		;SCL a 0
	CALL	Tempo_11us
	bsf	SCL		;SCL a 1
	CALL	Tempo_11us
	btfsc	SDA		;Si SDA=1
 	bsf	carry     
	btfss	SDA		;Si SDA=0
	bcf	carry      

	rlf	I2C_DATA,f	;décallage à gauche et met la carry dans le LSB 

	incf	I,f
	decfsz	I,f		;Si I!=0
	goto	Next_data_r

	bcf	SCL	;SCL a 0
	CALL	Tempo_11us

	call	I2C_MASTER_ACK

	return

I2C_RECEIVE_BYTE_LAST:
	movlw	d'8'
	movwf	I
	SDA_IN			;SDA en entrée
Next_data_rl:
	decf	I,f
	bcf	SCL		;SCL a 0
	CALL	Tempo_11us
	bsf	SCL		;SCL a 1
	CALL	Tempo_11us
	btfsc	SDA		;Si SDA=1
 	bsf	carry     
	btfss	SDA		;Si SDA=0
	bcf	carry      

	rlf	I2C_DATA,f	;décallage à gauche et met la carry dans le LSB 

	incf	I,f
	decfsz	I,f		;Si I!=0
	goto	Next_data_rl

	bcf	SCL	;SCL a 0
	CALL	Tempo_11us

	call	I2C_MASTER_NACK

	return


;-----------------------------------------------------------------------------------------
;	I2C_flag
;		0: NO_ACK
;		1:	
;		2:
;		3:
;		4:
;		5:
;		6:
;		7:
;


NO_ACK:
	bsf	I2C_flag,0	;Pas d'ack de l'esclave -> problème de comm

	return



 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip AFFICHEUR LCD 2X16 EN MODE 4BIT POUR PIC 16XXX
Source avec Zip Source avec une capture AFFICHEUR LCD 2X16 EN MODE 8BIT POUR PIC 16XXX

 Sources de la même categorie

Source avec Zip SAUT AVEC TROIS IMPULSIONS par ariane2005
Source avec Zip LED ROTATE par ariane2005
Source avec Zip LED EN COULEUR par ariane2005
Source avec Zip JEUX DE LUMIÈRE par ariane2005
PIC : OBTENIR UN NOMBRE ALÉATOIRE AVEC LA FORMULE XN+1=(137... par warezpsx

Commentaires et avis

Commentaire de Bigonoff le 08/10/2003 22:07:11

Salut
------

Petite remarque : en I²C, on ne peut JAMAIS imposer un niveau haut sur SCL ou sur SDA.
Ce programme ne respecte donc pas la norme, sauf si électronique externe (mais ce n'est pas précisé).
Tu devrais revoir tes routines ;)

A+
Bigonoff

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,718 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales