Buenos días, estoy con un problema que me tiene intrigado, estoy utilizando el sensor digital de temperatura 18b20 de Dallas.
Busqué las librerías, y en un post de ccs encontré estas dos:
1wire.c
[spoiler]
/*-------1-wire definitions-------*/
#define ONE_WIRE_PIN PIN_A0
/*******************1-wire communication functions********************/
/************onewire_reset*************************************************/
/*This function initiates the 1wire bus */
/* */
/*PARAMETERS: */
/*RETURNS: */
/*********************************************************************/
void onewire_reset() // OK if just using a single permanently connected device
{
output_low(ONE_WIRE_PIN);
delay_us( 500 ); // pull 1-wire low for reset pulse
output_float(ONE_WIRE_PIN); // float 1-wire high
delay_us( 500 ); // wait-out remaining initialisation window.
output_float(ONE_WIRE_PIN);
}
/*********************** onewire_write() ********************************/
/*This function writes a byte to the sensor.*/
/* */
/*Parameters: byte - the byte to be written to the 1-wire */
/*Returns: */
/*********************************************************************/
void onewire_write(int data)
{
int count;
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 ); // pull 1-wire low to initiate write time-slot.
output_bit(ONE_WIRE_PIN, shift_right(&data,1,0)); // set output bit on 1-wire
delay_us( 60 ); // wait until end of write slot.
output_float(ONE_WIRE_PIN); // set 1-wire high again,
delay_us( 2 ); // for more than 1us minimum.
}
}
/*********************** read1wire() *********************************/
/*This function reads the 8 -bit data via the 1-wire sensor. */
/* */
/*Parameters: */
/*Returns: 8-bit (1-byte) data from sensor */
/*********************************************************************/
int onewire_read()
{
int count, data;
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 ); // pull 1-wire low to initiate read time-slot.
output_float(ONE_WIRE_PIN); // now let 1-wire float high,
delay_us( 8 ); // let device state stabilise,
shift_right(&data,1,input(ONE_WIRE_PIN)); // and load result.
delay_us( 120 ); // wait until end of read slot.
}
return( data );
} [/spoiler]
y ds1820.c
[spoiler]
float ds1820_read()
{
int8 busy=0, temp1, temp2;
signed int16 temp3;
float result;
onewire_reset();
onewire_write(0xCC);
onewire_write(0x44);
while (busy == 0)
busy = onewire_read();
onewire_reset();
onewire_write(0xCC);
onewire_write(0xBE);
temp1 = onewire_read();
temp2 = onewire_read();
temp3 = make16(temp2, temp1);
result = (float) temp3 / 16.0; //Calculation for DS18S20 with 0.5 deg C resolution
delay_ms(200);
return(result);
}
[/spoiler]
MI código es :
[spoiler]
#include <16f877.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOPUT,NOLVP,NOBROWNOUT,NOPROTECT
#define LCD_ENABLE_PIN PIN_D3
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_DATA4 PIN_D7
#define LCD_DATA5 PIN_D6
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D4
#include <1wire.c>
#include <lcd.c>
#include <ds1820.c>
void main()
{
float temperature;
set_tris_a (0b11111);
set_tris_d (0);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
port_b_pullups (false) ;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
lcd_init();
lcd_putc("\f");
while (1)
{
temperature = ds1820_read();
lcd_gotoxy(1,1);
printf(lcd_putc,"TEMP: %3.1f ", temperature);
lcd_putc(223);
lcd_putc("C ");
lcd_gotoxy(1,2);
if(temperature >= 29.0)
printf(lcd_putc,"Calor! ");
else if( temperature >= 20 && temperature < 29.0)
printf(lcd_putc,"Ambiente!");
else
printf(lcd_putc,"Frio! ");
}
}
[/spoiler]
Bueno, simulé esto en proteus, y anduvo perfecto, cuando pasé a la práctica, el lcd se prende, pero no hace nada, queda en \f o sea limpio....
Probé sacando en mi código la linea temperature = ds1820_read() y el lcd muestra la temperatura en valor 0 ( o sea que el problema no es del conexionado del lcd sino de esa función)
Agradecería mucho si me pusieran ayudar
Un saludos a todoss