TODOPIC
Microcontroladores PIC => Todo en microcontroladores PIC => Mensaje iniciado por: javiergggg en 25 de Agosto de 2021, 15:38:09
-
estoy tratando de tomar el dato de presión del bmp180, y del dht22; con el dht22 no tengo problemas...leo perfecto temp y humedad..., pero se me cuelga con bmp085Calibration();
alguien tuvo el mismo problema...????
#include <16F876A.h>
#fuses HS,NOWDT,PUT
#use delay(clock=20Mhz)
#use i2c(master, sda=PIN_C4, scl=PIN_C3, FAST=100000, FORCE_SW)
#include <i2c_Flex_LCD.c>
#include "BMP180.c"//*-------------------------------------------------------------------------------------------------------------------------------------
#use fast_io(B)
#use fast_io(C)
#BIT Data_Pin = 0x06.7 // Pin mapped to PORTB.7
#BIT Data_Pin_Direction = 0x86.7 // Pin direction mapped to TRISB.7
float P_mBar,T_Cent;
char message1[] = "Temp = 00.0 C";
char message2[] = "RH = 00.0 %";
short Time_out ;
unsigned int8 T_byte1, T_byte2, RH_byte1, RH_byte2, CheckSum ;
unsigned int16 Temp, RH;
void start_signal(){
Data_Pin_Direction = 0; // Configure connection pin as output
Data_Pin = 0; // Connection pin output low
delay_ms(25);
Data_Pin = 1; // Connection pin output high
delay_us(30);
Data_Pin_Direction = 1; // Configure connection pin as input
}
short check_response(){
delay_us(40);
if(!Data_Pin){ // Read and test if connection pin is low
delay_us(80);
if(Data_Pin){ // Read and test if connection pin is high
delay_us(50);
return 1;}
}
}
unsigned int8 Read_Data(){
unsigned int8 i, k, _data = 0; // k is used to count 1 bit reading duration
if(Time_out)
break;
for(i = 0; i < 8; i++){ k = 0; while(!Data_Pin){ // Wait until pin goes high k++; if (k > 100) {Time_out = 1; break;}
delay_us(1);}
delay_us(30);
if(!Data_Pin)
bit_clear(_data, (7 - i)); // Clear bit (7 - i)
else{
bit_set(_data, (7 - i)); // Set bit (7 - i)
while(Data_Pin){ // Wait until pin goes low
k++;
if (k > 100) {Time_out = 1; break;}
delay_us(1);}
}
}
return _data;
}
void main()
{
lcd_init(0x4E,16,4);
delay_ms(50);
lcd_gotoxy(5,1);
lcd_putc("-PTU-AR-");
//*bmp085Calibration();
while(1)
{
delay_ms(1000);
Time_out = 0;
Start_signal();
if(check_response()){ // If there is response from sensor
RH_byte1 = Read_Data(); // read RH byte1
RH_byte2 = Read_Data(); // read RH byte2
T_byte1 = Read_Data(); // read T byte1
T_byte2 = Read_Data(); // read T byte2
Checksum = Read_Data(); // read checksum
if(Time_out){ // If reading takes long time
lcd_putc('f'); // LCD clear
lcd_gotoxy(5, 1); // Go to column 5 row 1
lcd_putc("Time out!");
}
else{
if(CheckSum == ((RH_Byte1 + RH_Byte2 + T_Byte1 + T_Byte2) & 0xFF))
{
RH = RH_byte1;
RH = (RH << 8) | RH_byte2;
Temp = T_byte1;
Temp = (Temp << 8) | T_byte2;
if (Temp > 0x8000){
message1[6] = '-';
Temp = Temp & 0x7FFF;
}
else
message1[6] = ' ';
message1[7] = (Temp / 100) % 10 + 48;
message1[8] = (Temp / 10) % 10 + 48;
message1[10] = Temp % 10 + 48;
message2[7] = (RH / 100) % 10 + 48;
message2[8] = (RH / 10) % 10 + 48;
message2[10] = RH % 10 + 48;
message1[11] = 223; // Degree symbol
//*lcd_putc('f'); // LCD clear
lcd_gotoxy(1,2); // Go to column 1 row 1
printf(lcd_putc, message1); // Display message1
lcd_gotoxy(1,3); // Go to column 1 row 2
printf(lcd_putc, message2); // Display message2
}
else {
lcd_putc('f'); // LCD clear
lcd_gotoxy(1, 1); // Go to column 1 row 1
lcd_putc("Checksum Error!");
}
}
}
else {
lcd_putc('f'); // LCD clear
lcd_gotoxy(3, 1); // Go to column 3 row 1
lcd_putc("No response");
lcd_gotoxy(1, 2); // Go to column 1 row 2
lcd_putc("from the sensor");
}
delay_ms(100);
//*P_mBar = BMP085Pressure(false);//*----------------------------------------------------------------------------------------------------------------------------
//*T_Cent = BMP085Temperature();
lcd_gotoxy(1,4);
printf(lcd_putc "Pres = %0.1f hPa",P_mBar);//*-
}
}