td1
Dependencies: lib_LCD_i2c_SPTLYI mbed
Revision 0:dca3b291558e, committed 2014-10-23
- Comitter:
- mbedo
- Date:
- Thu Oct 23 09:42:24 2014 +0000
- Commit message:
- tp1_exo1
Changed in this revision
diff -r 000000000000 -r dca3b291558e lib_LCD_i2c_SPTLYI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_LCD_i2c_SPTLYI.lib Thu Oct 23 09:42:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/YSI/code/lib_LCD_i2c_SPTLYI/#a805daa83dd0
diff -r 000000000000 -r dca3b291558e lib_SHT/lib_SHT11.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_SHT/lib_SHT11.cpp Thu Oct 23 09:42:24 2014 +0000 @@ -0,0 +1,262 @@ +#include "lib_SHT11.h" + + +SHT11::SHT11(PinName pin_DATA, PinName pin_SCK, float T_C_mesure) : DATA_HT(pin_DATA), SCK_HT(pin_SCK), Temps_cycle_mesure(T_C_mesure) +{ + if(Temps_cycle_mesure < 2) Temps_cycle_mesure = 2; + init(); +} + +void SHT11::start(void) +{ + DATA_HT.output(); + DATA_HT=1; + SCK_HT=0; +// wait_us(1); + SCK_HT=1; +// wait_us(1); + DATA_HT=0; +// wait_us(1); + SCK_HT=0; +// wait_us(1); + SCK_HT=1; +// wait_us(1); + DATA_HT=1; +// wait_us(1); + SCK_HT=0; +// wait_us(1); + DATA_HT=0; +} + +void SHT11::changer_timer_cycle(float new_Temps_cycle_mesure) +{ + if(new_Temps_cycle_mesure < 2) Temps_cycle_mesure = 2; + else Temps_cycle_mesure = new_Temps_cycle_mesure; + if(etat_cycle) desactiver(); init(); +} + +void SHT11::init(void) +{ +// ____________________________________________ +// DATA |__ +// __ __ __ __ __ __ __ __ __ +// SCK_HT _| |_| |_| |_| |_| |_| |_| |_| |_| |_ + unsigned char i; + DATA_HT.output(); + DATA_HT=1; + SCK_HT=0; + for (i=0;i<9;i++) + { + SCK_HT=1; +// wait_us(1); + SCK_HT=0; +// wait_us(1); + } + etat_sht11=0; + etat_cycle=1; + Timer_cycle_mesure.attach(this, &SHT11::gestion_HT, Temps_cycle_mesure); +} + +void SHT11::desactiver(void) +{ + etat_cycle=0; + Timer_cycle_mesure.detach(); +} + +void SHT11::demande_mesure(short octet_de_commande) +{ + unsigned int i; + + DATA_HT.output(); + for(i=0;i<8;i++) + { + if ((octet_de_commande)&(0x80)) DATA_HT=1; + else DATA_HT=0; +// wait_us(1); + SCK_HT=1; +// wait_us(1); + SCK_HT=0; + octet_de_commande=octet_de_commande*2; + } + DATA_HT.input(); +// wait_us(1); + SCK_HT=1; +// wait_us(1); + SCK_HT=0; +// wait_us(1); + DATA_HT.output(); + DATA_HT=1; + DATA_HT.input(); +} + +void SHT11::mesure_T(void) +{ + start(); + demande_mesure(3); +} + +void SHT11::mesure_H(void) +{ + start(); + demande_mesure(5); +} + +void SHT11::calcul_Temperature_Humidite(void) +{ + Temperature_mesuree=(Temperature*0.01-40); + Humidite_mesuree=((float)Temperature_mesuree-25.0)*(0.01+(0.00008*Humidite))-4+0.0405*Humidite-0.0000028*Humidite*Humidite; +} + +void SHT11::reception_mesure_T(void) +{ + unsigned int i; + Temperature=0; + + DATA_HT.input(); + for (i=0;i<8;i++) + { + SCK_HT=1; +// wait_us(1); + Temperature *=2; + if (DATA_HT==1) Temperature++; + SCK_HT=0; +// wait_us(1); + } + DATA_HT.output(); + DATA_HT=0; + SCK_HT=1; +// wait_us(1); + SCK_HT=0; +// wait_us(1); + DATA_HT.input(); + for (i=0;i<8;i++) + { + SCK_HT=1; +// wait_us(1); + Temperature *=2; + if (DATA_HT==1) Temperature++; + SCK_HT=0; +// wait_us(1); + } + DATA_HT.output(); + DATA_HT=1; + SCK_HT=1; +// wait_us(1); + SCK_HT=0; +// wait_us(1); +} + +void SHT11::reception_mesure_H(void) +{ + unsigned int i; + Humidite=0; + + DATA_HT.input(); + for (i=0;i<8;i++) + { + SCK_HT=1; +// wait_us(1); + Humidite *=2; + if (DATA_HT==1) Humidite++; + SCK_HT=0; +// wait_us(1); + } + DATA_HT.output(); + DATA_HT=0; + SCK_HT=1; +// wait_us(1); + SCK_HT=0; +// wait_us(1); + DATA_HT.input(); + for (i=0;i<8;i++) + { + SCK_HT=1; +// wait_us(1); + Humidite *=2; + if (DATA_HT==1) Humidite++; + SCK_HT=0; +// wait_us(1); + } + DATA_HT.output(); + DATA_HT=1; + SCK_HT=1; +// wait_us(1); + SCK_HT=0; +// wait_us(1); +} + +void SHT11::gestion_HT(void) +{ + switch (etat_sht11) + { + case 0: + Timer_cycle_mesure.detach(); + mesure_T(); + etat_sht11=1; + Timer_cycle_mesure.attach_us(this, &SHT11::gestion_HT, 10000); + break; + + case 1: + DATA_HT.input(); + if (DATA_HT==0) + { + Timer_cycle_mesure.detach(); + etat_sht11=2; + Timer_cycle_mesure.attach_us(this, &SHT11::gestion_HT, 1); + } + break; + + case 2: + Timer_cycle_mesure.detach(); + reception_mesure_T(); + etat_sht11=3; + Timer_cycle_mesure.attach_us(this, &SHT11::gestion_HT, 1); + break; + + case 3: + Timer_cycle_mesure.detach(); + mesure_H(); + etat_sht11=4; + Timer_cycle_mesure.attach_us(this, &SHT11::gestion_HT, 10000); + break; + + case 4: + DATA_HT.input(); + if (DATA_HT==0) + { + Timer_cycle_mesure.detach(); + etat_sht11=5; + Timer_cycle_mesure.attach_us(this, &SHT11::gestion_HT, 1); + } + break; + + case 5: + Timer_cycle_mesure.detach(); + reception_mesure_H(); + calcul_Temperature_Humidite(); + etat_sht11=0; + Timer_cycle_mesure.attach(this, &SHT11::gestion_HT, Temps_cycle_mesure); + break; + + default: + etat_sht11=0; + break; + } +} + +float SHT11::lire_T(void) +{ + return Temperature_mesuree; +} + +float SHT11::lire_H(void) +{ + return Humidite_mesuree; +} + +void SHT11::lire_T_H(float *pointeur_Temperature, float *pointeur_Humidite) +{ + *pointeur_Temperature = Temperature_mesuree; + *pointeur_Humidite = Humidite_mesuree; +} +
diff -r 000000000000 -r dca3b291558e lib_SHT/lib_SHT11.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib_SHT/lib_SHT11.h Thu Oct 23 09:42:24 2014 +0000 @@ -0,0 +1,45 @@ +#ifndef DEF_lib_SHT11_H +#define DEF_lib_SHT11_H + +#include "mbed.h" + + +class SHT11 : public Ticker +{ +public: + SHT11(PinName pin_DATA, PinName pin_SCK, float T_C_mesure); + + float lire_T(void); + float lire_H(void); + void lire_T_H(float *, float *); + void changer_timer_cycle(float new_Temps_cycle_mesure); + void init(void); + void desactiver(void); + +private: + + void start(void); + void gestion_HT(void); + void demande_mesure(short octet_de_commande); + void mesure_T(void); + void mesure_H(void); + void mesure_T_H(void); + void reception_mesure_T(void); + void reception_mesure_H(void); + void calcul_Temperature_Humidite(void); + + DigitalInOut DATA_HT; + DigitalOut SCK_HT; + Ticker Timer_cycle_mesure; + + unsigned int Temperature; + unsigned int Humidite; + unsigned etat_sht11; + unsigned etat_cycle; + float Temperature_mesuree; + float Humidite_mesuree; + float Temps_cycle_mesure; +}; + +#endif +
diff -r 000000000000 -r dca3b291558e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 23 09:42:24 2014 +0000 @@ -0,0 +1,35 @@ +#include "mbed.h" +#include "lib_LCD_i2c_SPTLYI.h" +LCD_I2C LCD(p28,p27,p26,0x7C); + +int main() +{ + + + float i=0; + float j=0; + + LCD.set_position_cursor(0,0); + LCD.print("compteur:"); + LCD.set_position_cursor(0,1); + LCD.print("compteur2:"); + while(1) { + + + LCD.set_position_cursor(9,0); + + LCD.print(i++); + if(i>99) i=0.0 ; + wait(0.25); + + + LCD.set_position_cursor(10,1); + + LCD.print(j=i/2); + if(j>99) j=0.0 ; + wait(0.25); + + } +} + +
diff -r 000000000000 -r dca3b291558e mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Oct 23 09:42:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file