7ezhil7
Junior Member level 2
Hi,
I created a program in Mikro c which includes DHT11 sensor.The code got compiled sucessfully in Mikroc.I need to simulate in Proteus 8.1 which contains Hitech c compiler.I dont know how to convert that.So please help me to convert the code also correct any logic mistakes present in my code.
Thanks in advance.
I created a program in Mikro c which includes DHT11 sensor.The code got compiled sucessfully in Mikroc.I need to simulate in Proteus 8.1 which contains Hitech c compiler.I dont know how to convert that.So please help me to convert the code also correct any logic mistakes present in my code.
Thanks in advance.
Code:
// LCD module connections
sbit LCD_RS at RE2_bit;
sbit LCD_EN at RE0_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISE2_bit;
sbit LCD_EN_Direction at TRISE0_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
char *text,mytext[4];
unsigned char a = 0, b = 0,i = 0,sum = 0, t1= 0,t2 = 0,rh1 = 0,rh2 = 0,rhout = 0,tempout = 0,tempin = 0, ws = 0,tempdiff = 0,t = 0;
void out();void in();
void ReadDataout();
void ReadDatain(); void windspeed();
void out()
{
TRISA = 0b11111110;
PORTA.F0 = 0;
delay_ms(18);
PORTA.F0 = 1;
delay_ms(30);
TRISA =0b00000001;
delay_ms(40);
a = 0;
delay_ms(40);
if (PORTA.F0 == 0)
{delay_us(80);
if (PORTE.F0 == 1) a = 1; delay_us(40);}
if(a == 1)
{
ReadDataout();
rh1=i;
ReadDataout();
rh2=i;
ReadDataout();
t1=i;
ReadDataout();
t2=i;
ReadDataout();
sum = i;
if(sum == rh1+rh2+t1+t2)
{rhout = rh1;
tempout = t1;
text = "TempOUT: .0C";
Lcd_Out(1,1,text);
text = "HumiOUT: .0%";
Lcd_Out(2,1,text);
ByteToStr(t1,mytext);
Lcd_Out(1,9,Ltrim(mytext));
ByteToStr(rh1,mytext);
Lcd_Out(2,9,Ltrim(mytext));
}
else
{
Lcd_Cmd(_LCD_CURSOR_OFF); // cursor off
Lcd_Cmd(_LCD_CLEAR); // clear LCD
text = "Checksumerror-out";
Lcd_Out(1,1,text);
}
}
else
{
text="No response";
Lcd_Out(1,1,text);
text = "out";
Lcd_Out(2,1,text);
}
delay_ms(2000);
}
void ReadDataout()
{
for(b=0;b<8;b++)
{
while(!PORTA.F0);
delay_us(30);
if(PORTA.F0 == 0) i&=~(1<<(7-b)); //Clear bit (7-b)
else
{i|= (1<<(7-b));
while(PORTA.F0);
}
}
}
void in()
{
TRISA = 0b11111101;
PORTA.F1 = 0;
delay_ms(18);
PORTA.F1 = 1;
delay_ms(30);
TRISA =0b00000010;
delay_ms(40);
a = 0;
delay_us(40);
if (PORTA.F1 == 0){
delay_us(80);
if (PORTA.F1 == 1) a = 1; delay_us(40);}
if(a == 1)
{
ReadDatain();
rh1=i;
ReadDatain();
rh2=i;
ReadDatain();
t1=i;
ReadDatain();
t2=i;
ReadDatain();
sum = i;
if(sum == rh1+rh2+t1+t2)
{
tempin = t1;
text = "TempIN: .0C";
Lcd_Out(1,1,text);
text = "HumiIN: .0%";
Lcd_Out(2,1,text);
ByteToStr(t1,mytext);
Lcd_Out(1,8,Ltrim(mytext));
ByteToStr(rh1,mytext);
Lcd_Out(2,8,Ltrim(mytext));
}
else
{
Lcd_Cmd(_LCD_CURSOR_OFF); // cursor off
Lcd_Cmd(_LCD_CLEAR); // clear LCD
text = "Checksumerror-in";
Lcd_Out(1,1,text);
}
}
else
{
text="No response";
Lcd_Out(1,1,text);
text = "in";
Lcd_Out(2,1,text);
}
delay_ms(2000);
}
void ReadDatain()
{
for(b=0;b<8;b++)
{
while(!PORTA.F1);
delay_us(30);
if(PORTA.F1 == 0) i&=~(1<<(7-b)); //Clear bit (7-b)
else
{i|= (1<<(7-b));
while(PORTA.F1);
}
}
}
void main()
{
TRISA=11000000;
TRISC=0;PORTC=0;
TRISB = 0;PORTB = 0; //Configure PORTB as output
TRISD=0;PORTD=0;
Lcd_Init();
while(1)
{
Lcd_Cmd(_LCD_CURSOR_OFF); // cursor off
Lcd_Cmd(_LCD_CLEAR);
out();
in();
tempdiff = tempout-tempin;
if(tempdiff < 8 && (25 < rhout < 80))
{PORTC=1;}
}
}