pic 16f877A et capteur sht75
Répondre à la discussion
Affichage des résultats 1 à 5 sur 5

pic 16f877A et capteur sht75



  1. #1
    invite78234403

    pic 16f877A et capteur sht75


    ------

    j'ecris ce code et je simule avec proteus isis mais rien se passe
    #include "16F877A.h"
    #use delay(clock=1M)
    #byte PORTB=0x06
    #byte PORTC=0x07
    #byte TRISB=0x86
    #byte TRISC=0x87
    /*SHT75 Sensor Macros*/
    #bit SCL=PORTB.0 // Serial Clock pin
    #bit SDA=PORTB.1// Serial Data pin
    #bit SCL_DIRECTION=TRISB.0
    #bit SDA_Direction=TRISB.1
    #int_timer0
    INT i;

    #define MEASURE_TEMPERATURE 0x03
    #define MEASURE_RELATIVE_HUMIDITY 0x05
    /*SHT75 Temperature and Humidity Sensor Functions*/
    void SHT75_Reset(void);
    void SHT75_Transmission_Start(void) ;
    void SHT75_MCU_ACK(void);
    unsigned long Measure_SHT75(unsigned char command);
    unsigned long Measure_SHT75_Temperature(void );
    unsigned long Measure_SHT75_Relative_Humidit y(void);
    unsigned long Measure_True_Humidity(unsigned long SHT75_temperature,unsigned long SHT75_Relative_Humidity);

    /*************SHT75 Constants For Calculation************/
    const unsigned int C1 = 205;
    const unsigned int C2 = 367;
    const unsigned int C3 = 16;
    const unsigned int D1 = 4010;
    const unsigned int D2 = 1;
    const unsigned int T1 = 1000;
    const unsigned int T2 = 8;
    /*
    SHT75 Global variables
    */
    unsigned long SORH; //This is used to Calculate the True_Humidity
    /****************************** **************************/
    void main()
    {


    //setup_timer_0 (RTCC_DIV_4|RTCC_INTERNAL);//fe=4096000/4/4/256=1kHz
    //enable_interrupts(INT_TIMER0);

    // enable_interrupts(GLOBAL);
    void SHT75_Reset()
    {
    unsigned char i;
    SCL = 0;
    SDA_Direction = 1;// Define SDA as input to pull the DATA line high
    for (i = 1; i <= 20; i++)// repeat 18 times
    {
    SCL = ~SCL;// invert SCL
    }
    }

    void SHT75_Transmission_Start()
    {
    SDA_Direction = 1; //data Line High Pulled Up Resistor
    SCL = 0;
    Delay_us(1);
    SCL = 1;
    SDA_Direction = 0; //Make Data line as Output pin
    SDA = 0;
    Delay_us(1);
    SCL = 0; //SCL Low
    Delay_us(1);
    SDA = 0; //SDA Still Low
    Delay_us(1);
    SCL = 1;
    Delay_us(1);
    SDA_Direction = 1; //Pull High the Line
    SDA = 1; //Not Required
    Delay_us(1);
    SCL = 0;
    }

    void SHT75_MCU_ACK()
    {
    SDA_Direction = 0;
    SDA = 0;
    SCL = 1;
    Delay_us(1);
    SCL = 0;
    Delay_us(1);
    SDA_Direction = 1;
    }

    unsigned long Measure_SHT75(unsigned char command)
    {
    unsigned char i,j;
    unsigned long k;
    j = command;

    SCL_Direction = 0;
    SHT75_Reset();
    SHT75_Transmission_Start();
    k = 0;
    SDA_Direction = 0;
    SCL = 0;
    for(i = 1; i <= 8; i++)
    {
    if ((j & 0x80) == 0x80)
    {
    SDA_Direction = 1;
    }
    else
    {
    SDA_Direction = 0;
    SDA = 0;
    }
    Delay_us(1);
    SCL = 1;
    Delay_us(1);
    SCL = 0;
    j <<= 1;
    }

    SDA_Direction = 1;
    SCL = 1;
    Delay_us(1);
    SCL = 0;
    Delay_us(1);
    while (SDA == 1);

    //Time to Read 2-Bytes from the Sensor
    for (i = 1; i <=16; i++)
    {
    k <<= 1;
    SCL = 1;
    if (SDA == 1)
    {
    k = k | 0x0001;
    }
    SCL = 0;
    if (i == 8 )
    {
    SHT75_MCU_ACK(); //Send Ack from Micro to Sensor
    }
    }
    return k; //Return value For calculations
    }

    unsigned long Measure_SHT75_Temperature(void )
    {
    unsigned long SHT75_Temperature;
    SHT75_Temperature = Measure_SHT75(MEASURE_TEMPERAT URE);
    if(SHT75_Temperature>D1)
    {
    SHT75_Temperature = D2*(SHT75_Temperature) - D1 ;
    }
    else
    {
    SHT75_Temperature = D1 - D2*(SHT75_Temperature);
    }

    return (SHT75_Temperature);
    }
    unsigned long Measure_SHT75_Relative_Humidit y(void)
    {
    unsigned long SHT75_Relative_Humidity;
    long temp;

    /*
    This will Return SOt see Section 4.3 of SHT75 Datasheet
    */
    SHT75_Relative_Humidity = Measure_SHT75(MEASURE_RELATIVE _HUMIDITY);

    SORH = SHT75_Relative_Humidity; //Used to Calculate the True Humidity
    //Thats why the above variable is declared as Global Variable

    temp = SHT75_Relative_Humidity*SHT75_ Relative_Humidity;
    temp = temp/100000;
    temp = temp*C3;
    SHT75_Relative_Humidity = C2*SHT75_Relative_Humidity/100;
    SHT75_Relative_Humidity = SHT75_Relative_Humidity - temp;
    SHT75_Relative_Humidity = SHT75_Relative_Humidity - C1;

    /*
    This Code is Highly Accurate and Efficient
    */
    return SHT75_Relative_Humidity;
    }
    unsigned long Measure_True_Humidity(unsigned long SHT75_Temperature,unsigned long SHT75_Relative_Humidity)
    {
    long SHT75_True_Humidity;
    long temp;
    SHT75_True_Humidity = (long)SHT75_Temperature - 2500;

    temp = T1 + T2 * SORH;
    temp = temp/100000;

    SHT75_True_Humidity = SHT75_True_Humidity + temp + SHT75_Relative_Humidity;

    return SHT75_True_Humidity;
    }
    }
    pouvez vous m'aider S.V.P

    -----

  2. #2
    invitee05a3fcc

    Re : pic 16f877A et capteur sht75

    Tu as les lettres J i c u e o b m n et r sur ton clavier ?

  3. #3
    invite78234403

    Re : pic 16f877A et capteur sht75

    j'ai pas compris

  4. #4
    invitee05a3fcc

    Re : pic 16f877A et capteur sht75

    Citation Envoyé par puzzlou Voir le message
    j'ai pas compris
    C'est bien dommage .....

  5. A voir en vidéo sur Futura
  6. #5
    invite78234403

    Re : pic 16f877A et capteur sht75

    ok pas de problème et désolé si ma question n'est pas à la hauteur

Discussions similaires

  1. SHT75 envoie un signal inutilisable
    Par invite5820f017 dans le forum Électronique
    Réponses: 1
    Dernier message: 25/05/2011, 15h47
  2. Code en C pour PIC avec Sensirion SHT75 / SHT71
    Par invitedd558ae9 dans le forum Électronique
    Réponses: 4
    Dernier message: 13/04/2010, 23h50
  3. Sht75 Pic16f876 récupérer les informations
    Par invitef9035af2 dans le forum Électronique
    Réponses: 3
    Dernier message: 20/01/2010, 23h48
  4. pic 16F877A
    Par invite636b8579 dans le forum Électronique
    Réponses: 22
    Dernier message: 01/04/2009, 16h00
  5. pic 16f877a
    Par invited2ae1532 dans le forum Électronique
    Réponses: 3
    Dernier message: 01/02/2008, 11h49
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...