electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

code with c to measure the value of frequency problem


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> code with c to measure the value of frequency problem
Author Message
ecestar



Joined: 01 May 2009
Posts: 10


Post24 May 2009 18:11   

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==3Cool{
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++);




}
}
Back to top
Google
AdSense
Google Adsense




Post24 May 2009 18:11   

Ads




Back to top
madicalphy



Joined: 22 Jul 2007
Posts: 68
Helped: 3


Post30 Oct 2009 9:28   

Re: code with c to measure the value of frequency problem


frequency counter and led display of counts , for further information
http://microcontroller51.blogspot.com/2009/09/programmable-frequency-meter.html
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> code with c to measure the value of frequency problem
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
sht11 code problem - always shows the same value (2)
Why does the voltmeter measure the rms value of voltage? (2)
Why does the voltmeter measure the rms value of voltage? (1)
how to measure the current value in the hspice? (10)
how to measure the resistance value of power transistor?? (5)
how can I directly measure the cap or ind value in cds (3)
Whats the problem with this code/// (2)
Help with Measure Frequency on PIC (1)
how to measure the frequency of crystal? (3)
measure the operating frequency of a DC-Dc converter (1)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS