Is it possible to make some changes so this thermometer will work on WL-500g?
beware, there's probably mistake in this wiring - PIN 1 and PIN 14 shouldn't be connected together as there's no need - should be enough to connect only PIN1 or PIN14 (read in forum under article)
"teplomer.c"
PHP Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/io.h>
#define DATA 0x378
#define STATUS DATA+1
#define CONTROL DATA+2
float ZmerTo (unsigned short naportu, unsigned char odkud, int stav)
// return temperature in °C
// parametert
// naportu - port where is thermometer connected tomereni
// odkud - bit where is thermometer connected tomereni
// stav - set if is bit "odkud" negated or not
#define DelkaCyklu 0xffff //length of cycle
{
int t0, t1, t2;
int mask = (1 << odkud);
t1=0;
t2=0;
for (t0 = 0; t0 < DelkaCyklu; t0++)
// measurement
if ((inb (naportu) & mask) == 0) t1++ ;
// negation of measurement in case the bit/port is also negated
t2=DelkaCyklu-t1;
if (stav!=0){
t1=t2;
t2=DelkaCyklu-t1;
};
// temperature calculation
return ((((double)t2 / ((double)DelkaCyklu)) - 0.32) / 0.0047);
}
int main (void)
{
if (setuid (0) < 0)
{
printf ("Program must be run under root privileges\n");
exit (1);
}
if (ioperm (STATUS, 3, 1))
{
printf ("Program must be run under root privileges\n");
exit (1);
}
if (ioperm (CONTROL, 3, 1))
{
printf ("No access to port\n");
exit (1);
}
// set control port to 1 so there is +5V for supply
outb (52, CONTROL);
// temp measurement
//for LPT port and thermometer connected to LPT PIN 15
printf ("Temperature is %4.1f \n", ZmerTo (STATUS, 3, 0));
// set control port to 0 so there is NOT +5V for supply
outb (55, CONTROL);
return (0);
}
translated form article:
http://www.root.cz/clanky/nejjednodu...line-teplomer/