Advertisement
smartel99

fonctions I2C TSO-S4-Projet

May 8th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.62 KB | None | 0 0
  1. //***********************uiLectureChanel1236************************************
  2. //    Nom de la fonction : uiLectureChanel1236(ucChanel)
  3. //    Auteur : Alain Champagne
  4. //    Date de création : 04 avril 2006
  5. //    Modifiée : 10-10-2016
  6. //    Prototype: uiLecture = uiLectureChanel1236(ucChanel);
  7. //    Description : Routine de lecture de la donnee du convertisseur MAX1236.
  8. //                  On passe comme parametre le no du chanel du convertisseur
  9. //                  en code ascii.
  10. //
  11. //    Appel : i1236ReadChanel('0');
  12. //            Lire la valeur de l'entrée 0 du convertisseur MAX1236.
  13. //    Fonctions appelées :   vI2CStartBit(), vI2CByteOut(), ucI2CByteIn(),
  14. //                           vI2CStopBit().
  15. //    Paramètres d'entrées : unsigned char ucChanel
  16. //    Paramètres de sortie : unsigned int.
  17. //    Variables utilisées : iAnalog, ucHaut, ucBas, ucLecture.
  18. //    Variables Globales : Aucune.
  19. //    #Define : ECRIREI2CMAX1236, CONFIGURE0MAX1236, SETUP0MAX1236),
  20. //              LIREI2CMAX1236.
  21. //
  22. //******************************************************************************
  23. int iLectureChanel1236(unsigned char ucChanel)
  24. {
  25.   int iAnalog;
  26.   unsigned char ucHaut, ucBas, ucLecture;
  27.   ucLecture = 0xFF;
  28.   while (ucLecture != 0x00)
  29.    ucLecture = uiI2CCheckDevice (ECRIREI2CMAX1236, 200);
  30.   vI2CStartBit();
  31.   vI2CByteOut(ECRIREI2CMAX1236);
  32.   if (ucChanel == '0')
  33.     vI2CByteOut(CONFIGURE0MAX1236);      //Modifier CONFIGURE0 pour une autre entree.
  34.   if (ucChanel == '1')
  35.     vI2CByteOut(CONFIGURE1MAX1236);      //Modifier CONFIGURE0 pour une autre entree.
  36.   if (ucChanel == '2')
  37.     vI2CByteOut(CONFIGURE2MAX1236);      //Modifier CONFIGURE0 pour une autre entree.
  38.   if (ucChanel == '3')
  39.     vI2CByteOut(CONFIGURE3MAX1236);      //Modifier CONFIGURE0 pour une autre entree.
  40.  
  41.   vI2CByteOut(SETUP0MAX1236);
  42.   vI2CStopBit();
  43.   vI2CStartBit();
  44.   vI2CByteOut(LIREI2CMAX1236);           //Demande de conversion.
  45. //Partie haute de la conversion.
  46.   ucHaut = ucI2CByteIn();                //Lecture de la valeur convertie.
  47.   vI2CBitOut(0x00);         //ACK
  48. //Partie basse de la conversion.
  49.   ucBas = ucI2CByteIn();
  50.   vI2CBitOut(0xFF);         //NO ACK
  51.   iAnalog = ucHaut;
  52.   iAnalog = (iAnalog << 8);
  53.   iAnalog = iAnalog | ucBas;
  54.   iAnalog = iAnalog & 0x0FFF;
  55.   vI2CStopBit();
  56.   return (iAnalog);
  57. }
  58.  
  59. //****************************vI2CEcrireInt6574*********************************
  60. //  Nom de la fonction : vI2CEcrireInt6574         
  61. //  Auteur : Alain Champagne       
  62. //       Date de création : 19-11-2009                  
  63. //  Description :   Routine de transmission d'un INT de donnée
  64. //                  sur le canal d'un convertisseur DA.
  65. //                         
  66. //  Fonctions appelées :    vI2CStartBit, vI2CStopBit, vI2CByteOut.       
  67. //  Paramètres d'entrée :   unsigned char ucChanel, unsigned int uiData.     
  68. //  Paramètres de sortie :  Aucun     
  69. //  Variables utilisées :   ucDataH, ucDataL, ucLecture.
  70. //  Equate :                Aucun  
  71. //  #Define :               ECRIREI2CDAC6574, CONFIGURE0DAC6574
  72. //                     
  73. //******************************************************************************
  74. void vI2CEcrireInt6574(unsigned char ucChannel, unsigned int uiData)
  75. {
  76.   unsigned char ucDataH, ucDataL, ucLecture;
  77.   ucLecture = 0xFF;
  78.   while (ucLecture != 0x00)
  79.    ucLecture = uiI2CCheckDevice (ECRIREI2CDAC6574, 200);
  80.   vI2CStartBit();            //Debut d'une communication I2C.
  81.   vI2CByteOut(ECRIREI2CDAC6574);         //Commande d'ecriture.
  82.   vI2CByteOut(ucChannel);
  83.   ucDataH = uiData >> 8;
  84.   ucDataL = uiData;
  85.   vI2CByteOut(ucDataH);                  //Ecrire la donnee.
  86.   vI2CByteOut(ucDataL);                  //Ecrire la donnee.
  87.   vI2CStopBit();                         //Fin d'une communication I2C.
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement