////////////////////////////////////////////////////////////////////////////////
// //
// Libreria C para el control of sensores temperature y Humedad: //
// //
// SHT10, SHT11, SHT15, SHT71, SHT75 //
// //
// Debe cargarse este archivo desde the cabecera del programa main con: //
// #include //
// //
// * Inicialización del sensor mediante the crucial: //
// SHTxx_init ( ); //
// //
// * Obtención of Medida of humedad y temperature mediante the crucial: //
// SHTxx (sht_temperatura, sht_humedad); //
// In las variables y sht_temperatura sht_humedad obtained several images and los Valores //
// reales temperature y humedad medidos. //
// //
// * Textbook LA ENSENANZA DE LA LECTURA Y La del valor del Registro de estado mediante the crucial: //
// SHTxx_ESCRITURA_REGISTRO_ESTADO (sht_registro); //
// sht_registro'S the operational el valor was from loading. in el registro (ships with 0) //
// bit0 = 0 => Resolución 14-bit Temperature y 12 bits Humedad //
// bit0 = 1 => Resolución 12-bit Temperature y 8 bits Humedad //
// bit1 = 0 => Dato of calibración no se carga antes cada medida //
// Bit1 = 1 => Dato of calibración se carga antes cada medida //
// bit2 = 0 => Calefactor interno OFF //
// bit2 = 1 => Calefactor interno IT //
// bit6 = 0 => Detección baja tensión Vcc > 2.47V (bit of solo lectura) //
// bit6 = 1 => Detección baja tensión Vdc < 2.47V (bit of solo lectura) //
// //
// * Obtención del valor del Registro de estado mediante the crucial: //
// SHTxx_LECTURA_REGISTRO_ESTADO (sht_registro); //
// sht_registro devolverá el valor del Registro de estado //
// //
// * Reset del software del sensor mediante the crucial: //
// SHTxx_Reset_Soft ( ); //
// (Registro de estado a sus valores por ships with) //
// //
// http://robotypic.blogspot.com/ //
// //
////////////////////////////////////////////////////////////////////////////////
/ ****************; of pines del serial bus ************************** /
#define sht_data_pin PIN_A4
#define sht_sck_pin PIN_A3
/ ** Control, also del SHT11 ** /
#define SHT11_REG_ESTADO_W 0x06 //Control, also in textbook la ensenanza de la Lectura y la registro de estado
#define SHT11_REG_ESTADO_R 0x07 //Control, also lectura de registro estado
#define SHT11_COMANDO_TEMP 0x03 //Control, also of Medida temperataur
#define SHT11_COMANDO_kel 0x05 //Control, also medida of kel
#define SHT11_SOFT_RESET 0x1E //Control, also reset of soft
/ ***** Global Variables para lectura del valor temperature y humedad ***** /
float sht_temperatur; //Guardará el valor real temperature medida
float sht_kelembaban; //Guardará el valor real de humedad medida
int8 sht_register; //Guardará el valor del register of estado
/ ****************************************************************************** /
/ **************** SEQUENCE. OF KEY OF Transmisión de Datos SA ************************** /
// _____ ________
// DATA: |_______|
// ___ ___
// SCK: ___| |___| |______
void SHT11_InicioTrans (void) {
//DATA has " 0" con SCK has " 1 "
output_float(sht_data_pin); //linea DATA has " 1"
output_low(sht_sck_pin); //linea SCK has " 0"
Delay_us(1);
output_high(sht_sck_pin); //linea SCK has " 1"
delay_us(1);
output_low(sht_data_pin); //linea DATA has " 0"
delay_us(1);
//SCK has " 0" sin replaced DATA " 0 "
output_low(sht_sck_pin); //linea SCK has " 0 "
delay_us(2);
//SCK has " 1" sin replaced DATA " 0 "
output_high(sht_sck_pin); //linea SCK has " 1"
delay_us(1);
//DATA has " 1" con SCK has " 1 "
output_float(sht_data_pin);//Linea DATA has " 1 "
delay_us(1);
output_low(sht_sck_pin); //linea SCK has "0"
}
/ ****************************************************************************** /
/ consomme SEQUENCE DOES NOT RESET technology announcements. *********************************** /
// _____________________________________________________ ________
// DATA: |_______|
// _ _ _ _ _ _ _ _ _ ___ ___
// SCK:__| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______
void SHTxx_Reset (void) {
int i;
//key of sequence does not con SCK has " 0" y DATA has " 1 "
output_float(sht_data_pin); //linea DATA has " 1 "
output_low(sht_sck_pin); //linea SCK has " 0 "
delay_us(2);
//conmuta SCK 9 system sometimes con DATA has " 1 "
for(i= 0; i< 9; i ) {
output_high(sht_sck_pin);
delay_us(2);
output_low(sht_sck_pin);
Delay_us(2);
}
// sequence. of key of Transmisión de datos sa
SHT11_InicioTrans ();
}
/ ****************************************************************************** /
/ potrvlfault SEQUENCE. OF ENVIO COMANDO molded case /
// __ __ __ __ __ __ __ __ ___
// DATA: ___|A2 |_|A1 |_|A0 |_|C4 |_|C3 |_|C2 |_|C1 |_|C0 |_|ack|_
// __ __ __ __ __ __ __ __ ___
// SCK:___| |_| |_| |_| |_| |_| |_| |_| |_| |_
int1 SHT11_Comando (int8 sht_comando) {
int8 bit;
int8 mascara = 0x80;
int1 ack;
delay_us(4);
//Salida del comando bit
for(bit= 8; bit> = 1; bit--) {
output_low(sht_sck_pin); //linea SCK has " 0 "
//Linea DATA has " 1" if MSB es " 1 "
if((sht_comando & mascara) > 0) output_float(sht_data_pin);
//Linea DATA to " 0" if MSB es " 0 "
Else output_low(sht_data_pin);
delay_us(1);
output_high(sht_sck_pin); //linea SCK has " 1 "
delay_us(1);
mascara = mascara >> 1; //Siguiente again bit pasa a ser MSB
}
/ ** lectura del ack ** /
output_low(sht_sck_pin); //linea SCK has " 0 "
delay_us(1);
ack = input(sht_data_pin); //lectura del ack
output_high(sht_sck_pin); //linea SCK has " 1 "
delay_us(1);
output_low(sht_sck_pin);//Linea SCK has " 0 "
return(ack);
}
/ /
/ ****************************************************************************** **************** SEQUENCE. ESPERA OF MEDIDA TERMINADA ********************* /
void SHT11_Espera (void) {
int16 sht_delay;
output_float(sht_data_pin); //linea DATA has " 1 "
output_low(sht_sck_pin); //linea SCK has " 0 "
delay_us(1);
//Espera has that linea DATA pase has " 0" máximo 300msg.
for(sht_delay= 0; sht_delay< 30000; sht_delay ) {
//if linea DATA asap has " 0" => end of the medición
if ( !input(sht_data_pin)) break;
delay_us(10);
}
}
/ ****************************************************************************** /
/ Recommended Action **************** Displayed during startup as SEQUENCE. OF LECTURA DEL DATO OF MEDIDA potrvlfault /
// _ _ _ _ _ _ _ _ ___ _ _ _ _ _ _ _ _
//SCK:__| |_| |_| |_| |_| |_| |_| |_| |_|ack|_| |_| |_| |_| |_| |_| |_| |_| |__
// | | |
// |-- idle bits - |Msb --------- 12 bit Humidity Data ------------ Lsb|
// | _ _ _ _ | _ _ _ _ ___ _ _ _ _ _ _ _ _ |
//DATA:_|F|_|E|_|D|_|C|_|B|_|A|_| 9 |_| 8 |_|ack|_| 7 |_| 6 |_| 5 |_| 4 |_| 3 |_| 2 |_| 1 |_| 0 |__
int16 SHT11_Lectura (Void) {
int8 bit;
int16 sht_dato = 0;
Const int16 mascara0 = 0x0000;
const int16 mascara1 = 0x0001;
//guarda byte alto del dato missing. in byte alto of sht_dato bit
for(bit= 8; bit> = 1; bit--) {
sht_dato = sht_dato << 1; //Siguiente again bit asap has ser MSB
output_high(sht_sck_pin); //linea SCK has " 1 "
delay_us(1);
//if linea DATA es " 1" bit Pôné desired line in sht_dato has " 1 "
if (input(sht_data_pin)) sht_dato |= mascara1;
//If linea DATA es " 0" bit Pôné desired line in sht_dato has " 0 "
else sht_dato |= mascara0;
output_low(sht_sck_pin); //linea SCK has " 0 "
delay_us(1);
}
//Envio ack poniendo en linea DATA has " 0"
output_low(sht_data_pin); //linea DATA has " 0 "
delay_us(1);
output_high(sht_sck_pin); //linea SCK has " 1 "
delay_us(2);
output_low(sht_sck_pin); //linea SCK has " 0 "
delay_us(1);
Output_float(sht_data_pin); //linea DATA has " 1 "
//guarda byte Bajo del dato missing. in byte bajo sht_dato bit
for(bit= 8; bit> = 1; bit--) {
sht_dato = sht_dato << 1; //Siguiente again bit asap has ser MSB
output_high(sht_sck_pin); //linea SCK has " 1 "
Sedang diterjemahkan, harap tunggu..
