Hardware Reference
In-Depth Information
83 static unsigned
84 rbyte(void) {
85 unsigned x, u = 0;
86
87 for ( x=0; x<8; ++x )
88 u = (u << 1) | rbit();
89 return u;
90 }
91
92 /
93
Read 32 bits of data + 8 bit checksum from the
94
DHT sensor. Returns relative humidity and
95
temperature in Celsius when successful. The
96
function returns zero if there was a checksum
97
error.
98
/
99 static int
100 rsensor(int
celsius) {
101 unsigned char u[5], cs = 0, x;
102 for ( x=0; x<5; ++x ) {
103 u[x] = rbyte();
104 if ( x < 4 ) /
relhumidity, int
Only checksum data..
/
105 cs += u[x]; /
Checksum
/
106 }
107
108 if ( (cs & 0xFF) == u[4] ) {
109
relhumidity = (int)u [0];
110
celsius = (int)u [2];
111 return 1;
112 }
113 return 0;
114 }
115
116 /
117
Main program:
118
/
119 int
120 main(int argc, char
argv) {
121 int relhumidity = 0, celsius = 0;
122 int errors = 0, timeouts = 0, readings = 0;
123 unsigned wait;
124
125 signal(SIGINT,sigint_handler); /
∗∗
Trap on SIGINT
/
126
127 gpio_init(); /
Initialize GPIO access
/
128 gpio_config(gpio_dht11,Input); /
Set GPIO pin as Input
/
129
Search WWH ::




Custom Search