Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing DHT11 with PIC16F877A

Status
Not open for further replies.

niyati doshi

Newbie level 2
Newbie level 2
Joined
Feb 9, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,325
Hi eveyone,
I need a help in programming for DHT11 interfacing with PIC16F877A.
I need to transfer my data on Rx, Tx pin of micro controller.
There's a code for on interfacing with LCD but whenever i am modifiying the code for USART my data is not coming on Rx Tx pin.
Please help me with the code.

CODE:

char message1[] = "Temp = 00.0 C";
char message2[] = "RH = 00.0 %";
unsigned short TOUT = 0, CheckSum, i, Check;
unsigned short T_Byte1, T_Byte2, RH_Byte1, RH_Byte2;
unsigned short Data, DataDir, heck ;
char usart_rd;

void StartSignal(){
DataDir = 0;
Data = 0;
Delay_ms(25);
Data = 1;
Delay_us(30);
DataDir = 1;
}
unsigned short CheckResponse(){
TOUT = 0;
TMR2 = 0;
T2CON.TMR2ON = 1;
while(!Data && !TOUT);
if (TOUT) return 0;
else {
TMR2 = 0;
while(Data && !TOUT);
if (TOUT) return 0;
else {
T2CON.TMR2ON = 0;
return 1;
}
}
}
unsigned short ReadByte(){
unsigned short num = 0, t, i;
DataDir = 1;
for(i=0;i<8;i++)
{
while(!Data);
TMR2 = 0;
T2CON.TMR2ON = 1;
while(Data);
T2CON.TMR2ON = 0;
if(TMR2 > 40) num |= 1<<(7-i);
}
return num;
}

void interrupt(){
if(PIR1.TMR2IF){
TOUT = 1;
T2CON.TMR2ON = 0;
PIR1.TMR2IF = 0;
}
}

void main(){
PORTA = 0b11111111;
PORTB = 0;
TRISB = 0;
PORTC = 0;
TRISC = 0;
PORTD = 0;
TRISD = 0;
CMCON = 7;
INTCON.GIE = 1;
INTCON.PEIE = 1;

PIE1.TMR2IE = 1;
T2CON = 0;
PIR1.TMR2IF =0;
TMR2 = 0;
Usart_Init(9600);
Delay_ms(100);
LCD_Init(&PORTD); // Initialize LCD connected to PORTB

LCD_Cmd(LCD_CLEAR); // Clear display
LCD_Cmd(LCD_CURSOR_OFF); // Turn cursor off

do {
Delay_ms(1000);
StartSignal();
heck = 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();

if (CheckSum == ((RH_Byte1 + RH_Byte2 + T_Byte1 + T_Byte2) & 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;
Lcd_Cmd(Lcd_CLEAR);
Lcd_Out(1, 1, message1);
Lcd_Out(2, 1, message2);
usart_rd = message1;
}

else{
Lcd_Cmd(Lcd_CLEAR);
Lcd_Out(1, 1, "Checksum Error!");
Lcd_Out(2, 1, "Trying Again ...");
}
}

}while(1);
TRISC = 0;
PORTC = 0;
UART1_Init(9600);
Delay_ms(100);
while(1){
if(UART1_Data_Ready()){
usart_rd = UART1_Read();
UART1_Write(usart_rd);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top