RSS

Code For Designing a Pulse Counter

PULSE COUNTER :
This software is written in "C" language. In this software, first enable the timer and serial interrups. Then configure the timer by mode & reload the value to give the correct speed (9600 Baud). SCON gives necessary UART signal and your data is sent serially. When port pin P3.5 goes low, the internal counter increases by 1. This count is displayed on LCD as well as hyper terminal on PC.






PROGRAM:



#include

#define LCD P1

unsigned int Count,d1,d2,d3,d4,x1,x2,x3,x4;

sbit Pulse = P3^5;
sbit LED = P3^7;
sbit rs = P3^4;
sbit rw = P3^3;
sbit en = P3^2;

void LCDInit ( );
void lcdcmd (unsigned char );
void lcdwrt (unsigned char );
void Delay (unsigned int );
void Convert (unsigned int );
void SerialTx (unsigned char );

void main(void)
{
unsigned char z,Display;
unsigned char code str1[]=" PULSE COUNTER ";
unsigned char code str2[]=" Design By ";
unsigned char code str3[]=" SAMIK ";
unsigned char code str4[]=" SANTRA ";
unsigned char code str5[]="PULSE: 0000 ";
P0=0xFF;
P1=0xFF;
P2=0xFF;
P3=0xFF;
IE=0x00;

Count=0x00;

//////////////////////SERIALIZATION DATA//////////////
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;

LED = 0x00;

LCDInit();

for(z=0;z<16;z++)
{

Display=str1[z];
lcdwrt(Display);
Delay(1);
SerialTx(Display);
Delay(1);
}

SerialTx('\r');
SerialTx('\n');
lcdcmd(0xC0);

for(z=0;z<16;z++)
{

Display=str2[z];
lcdwrt(Display);
Delay(1);
SerialTx(Display);
Delay(1);
}
Delay(200);

SerialTx('\r');
SerialTx('\n');
lcdcmd(0x01);
Delay(1);

for(z=0;z<16;z++)
{

Display=str3[z];
lcdwrt(Display);
Delay(1);
SerialTx(Display);
Delay(1);
}

SerialTx('\r');
SerialTx('\n');
lcdcmd(0xC0);

for(z=0;z<16;z++)
{

Display=str4[z];
lcdwrt(Display);
Delay(1);
SerialTx(Display);
Delay(1);
}
Delay(200);

SerialTx('\r');
SerialTx('\n');
lcdcmd(0x01);
Delay(1);

lcdcmd(0xC0);

for(z=0;z<16;z++)
{

Display=str5[z];
lcdwrt(Display);
Delay(1);
SerialTx(Display);
Delay(1);
}
Delay(70);

SerialTx('\r');
SerialTx('\n');

while(1)
{
LED=1;
Delay(30);
if(Pulse==0)
{
Count=Count+1;
Convert(Count);
if(Count==9999)
Count=0x00;
}
}
}

void Convert(unsigned int value)
{
x1 = value / 10;
d1 = value % 10;

x2 = x1 / 10;
d2 = x1 % 10;

x3 = x2 / 10;
d3 = x2 % 10;

d4 = x3 % 10;

d1=d1|0x30;
d2=d2|0x30;
d3=d3|0x30;
d4=d4|0x30;

lcdcmd(0xC7);

lcdwrt(d4);
lcdwrt(d3);
lcdwrt(d2);
lcdwrt(d1);
Delay(1);

SerialTx(d4);
SerialTx(d3);
SerialTx(d2);
SerialTx(d1);
Delay(1);

SerialTx('\r');
SerialTx('\n');

LED=0;
Delay(30);
}

void LCDInit()
{
lcdcmd(0x38);
Delay(10);
lcdcmd(0x0E);
Delay(10);
lcdcmd(0x01);
Delay(10);
lcdcmd(0x0C);
Delay(10);
lcdcmd(0x80);
Delay(10);
return;
}

void lcdcmd(unsigned char value)
{
LCD=value;
rs=0;
rw=0;
en=1;
Delay(1);
en=0;
return;
}

void lcdwrt(unsigned char value)
{
LCD=value;
rs=1;
rw=0;
en=1;
Delay(1);
en=0;
return;
}

void SerialTx(unsigned char value)
{
SBUF = value;
while(TI==0);
TI = 0;
}

void Delay(unsigned int x)
{
unsigned int i,j;
for (i=0;i<=x;i++)
for (j=0;j<=500;j++);
}

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comments:

Post a Comment