#include <12F629.h>
#fuses INTRC_IO,PUT,BROWNOUT,NOWDT,MCLR
#use delay(clock=4M)
#use rs232(baud=300, xmit=pin_a1, rcv=pin_a2, bits=8, parity=N)
#define TOUCH_PIN pin_a0//Defino el pin de entrada
#define on output_high
#define off output_low
#include <touch.c>
void enviar_temperatura(void);
void main()
{
char cmd;
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
while (TRUE)
{
cmd=0;
while(!kbhit());//Espero hasta que el dato de peticion este listo
if(cmd=='t')
enviar_temperatura();
else
cmd=0;
}
}
void enviar_temperatura(void)
{
int8 buffer[2];
if(touch_present())
{
touch_write_byte(0xCC);//Salto la ROM
touch_write_byte (0x44);//Inicio la conversion
output_high(TOUCH_PIN);
delay_ms(800);//Espero a que la conversion termine
touch_present();
touch_write_byte(0xCC);//Salto la ROM
touch_write_byte (0xBE);//Leo el dato
buffer[0] = touch_read_byte();
buffer[1] = touch_read_byte();
printf ("%u\r\n", buffer
[0]/2);//Envio el dato de la temperatura (formato int) }
else
{
printf("empty\r\n");//Si no hay sensor conectado envio el string }
}