Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***********************uiLectureChanel1236************************************
- // Nom de la fonction : uiLectureChanel1236(ucChanel)
- // Auteur : Alain Champagne
- // Date de création : 04 avril 2006
- // Modifiée : 10-10-2016
- // Prototype: uiLecture = uiLectureChanel1236(ucChanel);
- // Description : Routine de lecture de la donnee du convertisseur MAX1236.
- // On passe comme parametre le no du chanel du convertisseur
- // en code ascii.
- //
- // Appel : i1236ReadChanel('0');
- // Lire la valeur de l'entrée 0 du convertisseur MAX1236.
- // Fonctions appelées : vI2CStartBit(), vI2CByteOut(), ucI2CByteIn(),
- // vI2CStopBit().
- // Paramètres d'entrées : unsigned char ucChanel
- // Paramètres de sortie : unsigned int.
- // Variables utilisées : iAnalog, ucHaut, ucBas, ucLecture.
- // Variables Globales : Aucune.
- // #Define : ECRIREI2CMAX1236, CONFIGURE0MAX1236, SETUP0MAX1236),
- // LIREI2CMAX1236.
- //
- //******************************************************************************
- int iLectureChanel1236(unsigned char ucChanel)
- {
- int iAnalog;
- unsigned char ucHaut, ucBas, ucLecture;
- ucLecture = 0xFF;
- while (ucLecture != 0x00)
- ucLecture = uiI2CCheckDevice (ECRIREI2CMAX1236, 200);
- vI2CStartBit();
- vI2CByteOut(ECRIREI2CMAX1236);
- if (ucChanel == '0')
- vI2CByteOut(CONFIGURE0MAX1236); //Modifier CONFIGURE0 pour une autre entree.
- if (ucChanel == '1')
- vI2CByteOut(CONFIGURE1MAX1236); //Modifier CONFIGURE0 pour une autre entree.
- if (ucChanel == '2')
- vI2CByteOut(CONFIGURE2MAX1236); //Modifier CONFIGURE0 pour une autre entree.
- if (ucChanel == '3')
- vI2CByteOut(CONFIGURE3MAX1236); //Modifier CONFIGURE0 pour une autre entree.
- vI2CByteOut(SETUP0MAX1236);
- vI2CStopBit();
- vI2CStartBit();
- vI2CByteOut(LIREI2CMAX1236); //Demande de conversion.
- //Partie haute de la conversion.
- ucHaut = ucI2CByteIn(); //Lecture de la valeur convertie.
- vI2CBitOut(0x00); //ACK
- //Partie basse de la conversion.
- ucBas = ucI2CByteIn();
- vI2CBitOut(0xFF); //NO ACK
- iAnalog = ucHaut;
- iAnalog = (iAnalog << 8);
- iAnalog = iAnalog | ucBas;
- iAnalog = iAnalog & 0x0FFF;
- vI2CStopBit();
- return (iAnalog);
- }
- //****************************vI2CEcrireInt6574*********************************
- // Nom de la fonction : vI2CEcrireInt6574
- // Auteur : Alain Champagne
- // Date de création : 19-11-2009
- // Description : Routine de transmission d'un INT de donnée
- // sur le canal d'un convertisseur DA.
- //
- // Fonctions appelées : vI2CStartBit, vI2CStopBit, vI2CByteOut.
- // Paramètres d'entrée : unsigned char ucChanel, unsigned int uiData.
- // Paramètres de sortie : Aucun
- // Variables utilisées : ucDataH, ucDataL, ucLecture.
- // Equate : Aucun
- // #Define : ECRIREI2CDAC6574, CONFIGURE0DAC6574
- //
- //******************************************************************************
- void vI2CEcrireInt6574(unsigned char ucChannel, unsigned int uiData)
- {
- unsigned char ucDataH, ucDataL, ucLecture;
- ucLecture = 0xFF;
- while (ucLecture != 0x00)
- ucLecture = uiI2CCheckDevice (ECRIREI2CDAC6574, 200);
- vI2CStartBit(); //Debut d'une communication I2C.
- vI2CByteOut(ECRIREI2CDAC6574); //Commande d'ecriture.
- vI2CByteOut(ucChannel);
- ucDataH = uiData >> 8;
- ucDataL = uiData;
- vI2CByteOut(ucDataH); //Ecrire la donnee.
- vI2CByteOut(ucDataL); //Ecrire la donnee.
- vI2CStopBit(); //Fin d'une communication I2C.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement