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.

code with c to measure the value of frequency problem

Status
Not open for further replies.

ecestar

Newbie level 5
Joined
May 1, 2009
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,404
code with c

can any one helpe me i write cde with c language to measure the value of frequency wich input to the microcontroller and display character to each value by using lcd.

the prpblem is when i put constant frequency that input the 8051 then i have

on the lcd many caracter for each time .

can any one help me please and this is my code


/*---------------------------------------------------------*/
#include <reg66x.h>
#include <reg52.h>
#include <stdio.h>
#define NewLine 0xc0
#define ClrDisp 0x01
#define TwoLine10dots 0x38
#define ScrOnCurOffBlinkOff 0x0F
#define IncCurDntMovDis 0x06
#define OUT P1

int check ;
sbit BusyFlag=P1^7;
sbit RS =P3^5;
sbit RW =P3^6;
sbit E =P3^7;

/*---------------------------------------------------------
Timer 0 Overflow Interrupt
---------------------------------------------------------*/
unsigned long tt ;
unsigned long t;

void T0_ISR (void) interrupt 1
{

TF0 = 0; // Reset the interrupt request

}


/*---------------------------------------------------------
MAIN C function
---------------------------------------------------------*/

/*---------------------------------------------------------
---------------------------------------------------------*/
int temp(){
int x,y;
y=tt/335;
x=y+31;
return x;
}





void checkBusy(void){


OUT=0XFF ;
do{ ;
E =0;
RS =0;
RW =1;
E =1;
}while(BusyFlag);
E=0;
RW = 0;
}

void sendCmd (unsigned char Cmd){
checkBusy();
RS = 0;
RW = 0;

OUT = Cmd;
E =1;
E =0;
}
void sendData (unsigned char ch){
checkBusy();
RS = 1;
RW = 0;
OUT=ch;
E = 1;
E = 0;
}
void init_LCD (void){
sendCmd(TwoLine10dots);
sendCmd(ScrOnCurOffBlinkOff);
sendCmd(IncCurDntMovDis);

}



void main (void)
{
int a;
/*--------------------------------------
Set serial port for 9600 baud at
11.0592 MHz. Note that we use Timer 1
for the baud rate generator.
--------------------------------------*/
SCON = 0x53;
PCON =0x00;
TH1 = 0xFA;
TL1 = 0xFA;
TR1 = 1;
TI = 1 ;

/*--------------------------------------
Enable interrupts for timer 0.
--------------------------------------*/
ET0 = 1;
EA = 1;

/*--------------------------------------
Set Timer0 for 16-bit interval timer
mode.
--------------------------------------*/
TMOD = 0x21;

while (1)
{
/*--------------------------------------
Clear the timer overflow counter and
the timer low and high registers. Then,
start the timer.
--------------------------------------*/
TH0 = 0;
TL0 = 0;
TR0 = 1;


/*--------------------------------------
Wait for the pulse to start.
Then, wait for the pulse to end.
--------------------------------------*/
while (!INT0);
while (INT0);

/*--------------------------------------
Compute the width of the pulse -- one
clock cycle is 1us for a standard 8051
and display it.
--------------------------------------*/
tt=((unsigned long)(TH0*256)+TL0) ;
printf ("%1d\n",tt=(unsigned long)(TH0*256)+TL0) ;

a=temp();
if (a==32){
init_LCD();
sendCmd(ClrDisp);
sendData('A');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else if (a==33){
init_LCD();
sendCmd(ClrDisp);
sendData('b');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else if (a==34){
init_LCD();
sendCmd(ClrDisp);
sendData('c');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else if (a==35){
init_LCD();
sendCmd(ClrDisp);
sendData('d');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else if (a==36){
init_LCD();
sendCmd(ClrDisp);
sendData('e');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else if (a==37){
init_LCD();
sendCmd(ClrDisp);
sendData('f');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else if (a==38){
init_LCD();
sendCmd(ClrDisp);
sendData('g');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else if (a==39){
init_LCD();
sendCmd(ClrDisp);
sendData('h');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else if (a==40){
init_LCD();
sendCmd(ClrDisp);
sendData('i');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else if (a==41){
init_LCD();
sendCmd(ClrDisp);
sendData('j');
sendCmd(NewLine);
for(t=0;t<1000;t++){}
}
else {


// for(t=0;t<10000000;t++){}

}







// for(t=0;t<10000;t++);




}
}
 

frequency counter and led display of counts , for further information
**broken link removed**
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top