Friday, August 14, 2020

Programming of Frequency Counter Circuit using 8051 Microcontroller.

#include
#define lcd P1
sbit rs=P3^0;
sbit e=P3^1;

unsigned long z=0;
void delay (int);
void display (unsigned char);
void cmd (unsigned char);
void init (void);
void string (char *);
void intro (void);
char i=0;


void delay (int i)
{
int j=0;
for(j=0;j
{
TMOD=0x51;
TH0=0xFC;
TL0=0x66;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
}

void cmd (unsigned char c)
{
lcd=c;
rs=0;
e=1;
delay(10);
e=0;
}
void display (unsigned char c)
{
lcd=c;
rs=1;
e=1;
delay(10);
e=0;
}
void string (char *c)
{
while(*c)
{
display(*c++);
}
}
void init (void)
{
cmd(0x38);
cmd(0x01);
  cmd(0x0c);
cmd(0x80);
}
void intro (void)
{
cmd(0x80);
string("  Electronics  ");
cmd(0xc0);
string("      Hub      ");
delay(2000);
cmd(0x01);
cmd(0x80);
string("   Frequency   ");
cmd(0xc0);
string("    Counter    ");
delay(2000);
cmd(0x01);
cmd(0x80);
}

void main()
{
unsigned int temp=0;
unsigned int temp1=0;
unsigned int frequency;
init();
intro();
delay(100);
while(1)
{

  TMOD=0x51;
TH1=0;
TL1=0;
TR1=1;
delay(100);
TR1=0;
frequency=(TH1*256)+TL1;
frequency=frequency*10;
 

////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(i==0)
{
string("Frequency In Hz");
i++;
}


    cmd(0xc5);
if((frequency>=1) && (frequency<10 span="">
{
string("    ");
  temp=frequency*10000;
  temp1=((temp/10000)+48);
  display(temp1);

  }
  else if((frequency>=10) && (frequency<100 span="">
{
string("   ");
temp=frequency*1000;
  temp1=((temp/10000)+48);
  display(temp1);

temp1=(((temp/1000)%10)+48);
  display(temp1);

}
//////////////////////////////////////////////////////////////////////
else if((frequency>=100) && (frequency<1000 span="">
{
string("  ");
temp=frequency*100;
  temp1=((temp/10000)+48);
  display(temp1);

temp1=(((temp/1000)%10)+48);
  display(temp1);

temp1=(((temp/100)%10)+48);
display(temp1);

}

else if((frequency>=1000) && (frequency<10000 span="">
{
string(" ");
temp=frequency*10;
  temp1=((temp/10000)+48);
  display(temp1);

temp1=(((temp/1000)%10)+48);
  display(temp1);

temp1=(((temp/100)%10)+48);
display(temp1);

temp1=(((temp/10)%10)+48);
display(temp1);

}
else if((frequency>=10000) && (frequency<100000 span="">
{
temp=frequency*1;
  temp1=((temp/10000)+48);
  display(temp1);

temp1=(((temp/1000)%10)+48);
  display(temp1);

temp1=(((temp/100)%10)+48);
display(temp1);

temp1=(((temp/10)%10)+48);
display(temp1);

temp1=((temp%10)+48);
display(temp1);


}
else
{
string("    0");
}
delay(500);
 }
while(1);
}

WATER LEVEL INDICATOR USING 8051 MICROCONTROLLER

WATER LEVEL INDICATOR 8051 MICROCONTROLLER CODE.

#define  F_CPU 8000000UL
#include
#include

int main(void)
{
DDRB = 0x00; // PORTB pins as input
DDRD = 0xff; // PORTD as output
DDRC = 0x01; // Buzzer
unsigned char seg[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
    while(1)
    {
        if((PINB & 0xff)==0x00) // 8th probe, Tank full
{
PORTC = 0x01;
PORTD = seg[8];
}
else if((PINB & 0xff)==0x01) // 7th probe
{
PORTC = 0x01;
_delay_ms(500);
PORTC = 0x00;
_delay_ms(500);
PORTD = seg[7];
}
else if((PINB & 0xff)==0x03) // 6th probe
{
PORTC = 0x00;
PORTD = seg[6];
}
else if((PINB & 0xff)== 0x07) // 5th probe
{
PORTC = 0x00;
PORTD = seg[5];
}
else if((PINB & 0xff)== 0x0f) // 4th probe
{
PORTC = 0x00;
PORTD = seg[4];
}
else if((PINB & 0xff)==0x1f) // 3rd probe
{
PORTC = 0x00;
PORTD = seg[3];
}
else if((PINB & 0xff) == 0x3f) // 2nd probe
{
PORTC = 0x00;
PORTD = seg[2];
}
else if((PINB & 0xff) == 0x7f) // 1st probe
{
PORTC = 0x00;
PORTD = seg[1];
}
else                                // Tank empty
{
PORTC = 0x00;
PORTD = seg[0];
}
    }
}