Teste Com Pic16f628a e Sensor Dht11
Teste Com Pic16f628a e Sensor Dht11
! "
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
}
unsigned short CheckResponse(){
TOUT = 0;
TMR2 = 0;
T2CON.TMR2ON = 1;
// start timer
while(!Data && !TOUT);
if (TOUT) return 0;
else {
TMR2 = 0;
while(Data && !TOUT);
if (TOUT) return 0;
else {
T2CON.TMR2ON = 0;
return 1;
}
}
}
! "
! "
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
Delay_ms(100);
StartSignal();
check = CheckResponse();
if (!check) {
Lcd_Cmd(_Lcd_Clear);
Lcd_Out(1, 1, "No response");
Lcd_Out(2, 1, "from the sensor");
}
else{
RH_Byte1 = ReadByte();
RH_Byte2 = ReadByte();
T_Byte1 = ReadByte();
T_Byte2 = ReadByte();
CheckSum = ReadByte();
// Check for error in Data reception
if (CheckSum == ((RH_Byte1 + RH_Byte2 + T_Byte1 + T_By
yte2) & 0xFF))
{
message1[7] = T_Byte1/10 + 48;
message1[8] = T_Byte1%10 + 48;
message1[10] = T_Byte2/10 + 48;
message2[7] = RH_Byte1/10 + 48;
message2[8] = RH_Byte1%10 + 48;
message2[10] = RH_Byte2/10 + 48;
message1[11] = 223;
// Degree symbol
Lcd_Cmd(_Lcd_Clear);
Lcd_Out(1, 1, message1);
Lcd_Out(2, 1, message2);
}
else{
Lcd_Cmd(_Lcd_Clear);
Lcd_Out(1, 1, "Checksum Error!");
Lcd_Out(2, 1, "Trying Again ...");
}
}
if(T_Byte1 + T_Byte2 >= temp){
portb.f0=0;
}
if(T_Byte1 + T_Byte2 < temp){
portb.f0=1;
}
! "
168:
169:
170:
171:
}while(tela == 0);
for(i=0; i<16; i++) { // Move o texto para a direita 4x
x
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
if(tela == 1){
Lcd_Cmd(_Lcd_Clear);
while(tela==1){
Lcd_Out(1, 1, "SET TEMPERATURA");
message1[7] = T_Byte1/10 + 48;
message1[8] = T_Byte1%10 + 48;
message1[10] = T_Byte2/10 + 48;
message1[11] = 223;
// Degree symbol
Lcd_Out(2, 1, message1);
delay_ms(50);
if (RA2_bit == 1){
//T_Byte1 ++;
T_Byte2 ++;
T_Byte2 ++;
T_Byte2 ++;
}
if (RA3_bit == 1){
//T_Byte1 --;
T_Byte2 --;
T_Byte2 --;
T_Byte2 --;
}
temp = T_Byte1 + T_Byte2;
if(RA4_bit == 1){
delay_ms(500);
tela++;
for(i=0; i<16; i++) { // Move o texto para a direita
a 4x
207:
208:
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
! "
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
}
}
}
}
if(tela == 2){
Lcd_Cmd(_Lcd_Clear);
while(tela==2){
message2[7] = RH_Byte1/10 + 48;
message2[8] = RH_Byte1%10 + 48;
message2[10] = RH_Byte2/10 + 48;
Lcd_Out(1, 1, "SET HUMIDADE");
Lcd_Out(2, 1, message2);
delay_ms(200);
if(RA4_bit == 1){
delay_ms(500);
tela++;
for(i=0; i<16; i++) { // Move o texto para a dir
reita 4x
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
}
}
}
if(tela == 3){
Lcd_Cmd(_Lcd_Clear);
while(tela==3){
Lcd_Out(1, 1, "SET ROLAGEM ON");
Lcd_Out(2, 5, "5 SEGUNDOS");
delay_ms(200);
if(RA4_bit == 1){
delay_ms(500);
tela=0;
for(i=0; i<16; i++) { // Move o texto para a dir
reita 4x
248:
249:
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
! "
250:
251:
252:
253:
}
254:
}
255: }
}
}
}
! "