Hello, I have wired up a frequency meter using 89C4051.The signal is connected to P3.4/T0 pin.The circuit runs on 24MHz crystal.Can anyone give me the code of a frequency counter?Thanks in advance...
lol!
Not being a C51 guy I cannot answer in detail. What you need is a counting hardware timer that generates interrupts. You might also need to make your IO pin generate an interrupt and then calculate in the timer ISR, or instead use capture/compare functionality of the timer if you have it. Did you read the user manual of your processor?
hi, Can you just give the code (not in detail) in KEIL C....?
"Can you just give the code (not in detail) in KEIL C....?"
This is the simplified code without any lousy detail:
#include <whatever_is_needed.h> #include "my_timer_support.h" #include "my_display_support.h" #include "my_io_support.h" void main(void) { init_my_timer(); init_my_display(); init_other_io(); perform_self_test(); perform_auto_calibration(); for (;;) { check_current_range(); check_count(); if (full_timing_period()) { eval_frequency(); display_frequency(); prepare_new_timing_period(); } } }
Hi, I am unable to get the detail from your program.Please go through the code I have done.Thanks in advance....
IN ISR ------------- void timer0_isr(void) { while((tick--)!=0) timer0_isr_go(); TR1=0; TF1=0; TR0=TF0=0; LCD_command(0x01); } void timer0_isr_go(void) { TH0=0x3C; TL0=0xBA; } void timer1_isr(void) { freq++; }
IN MAIN PROGRAM ----------------
void measure_freq() { unsigned char xx2[5],xx1,xx0[5]; while(1) { LCD_command(0x01); TH0=0x3C; TL0=0xBA; tick=0x20;
freq=0; TH1=0; TL1=0;
TR0=TR1=1; while(TF0!=0) { LCD_command(0x01); timer0_isr(); timer1_isr(); } *xx2=freq; xx1=TH1; *xx0=TL1; n=strlen(xx0); LCD_row1(); print_str_lcd(xx0,n); LCD_row2(); LCD_puts("xx1");
init_serial(); serial_data(); printf ("\nValue of XX2 : %d ",xx2); printf ("\nValue of XX1 : %d ",xx1); printf ("\nValue of XX0 : %d ",xx0);
} }
Completely unreadable! Post it formatted!
"Please go through the code I have done."
great work. This is will be the best code for keil c, for generations to come.
just load it up to your mcu and you are done!
keep up the good work.
What, exactly, is your goal here?
You asked: "Can you just give the code (not in detail)"
Per gave you code - not in detail
Then you said: "I am unable to get the detail from your program"
So what, exactly, were you expecting??
If you want to learn embedded programming, then you need to get down and invest time (and, possibly, money) in proper study.
If you don't want to learn embedded programming, then don't mess with it - pay someone to do it properly for you.
But just asking people to give you ready-to-run code is not going to teach you much - if anything.
And expecting them to do it for free is cheeky at best.
Hi, I have arranged the program in correct order.Please go through it and let me know the mistakes...
ISR PROGRAM ------------ void timer0_isr(void) {
while((tick--)!=0) timer0_isr_go(); TR1=0; TF1=0; TR0=TF0=0; LCD_command(0x01);
}
void timer0_isr_go(void) { TH0=0x3C; TL0=0xBA; }
void timer1_isr(void) { freq++; }
SUBROUTINE ---------------
void measure_freq() {
unsigned char xx2,xx1,xx0; while(1)
{
LCD_command(0x01);
TH0=0x3C;
TL0=0xBA;
tick=0x20;
freq=0;
TH1=0;
TL1=0;
TR0=TR1=1;
while(TF0!=0);
xx2=freq;
xx1=TH1;
xx0=TL1;
init_serial();
serial_data();
printf ("\nValue of XX2 : %d ",xx2);
printf ("\nValue of XX1 : %d ",xx1);
printf ("\nValue of XX0 : %d ",xx0);
Hi, Where is the code available which you have done?Please give me he link....
"I have arranged the program in correct order"
But you have not posted it using the correct tags - have you?!
Look at this picture: www.danlhenry.com/.../keil_code.png - it shows you that the instructions are really quite simple and very clearly stated.
You were the one who said, "Please go through the code I have done" - Ashley was just quoting what you said!
Before asking others to "go through" your code, have you gone through it yourself?
Have you followed it through "manually" using pencil & paper?
Have you run it in the Simulator?
www.8052.com/.../169331
www.8052.com/.../92049
Again, if you just want the job done for you, then you must expect to pay for that.
without really looking at your scribbles (code has comments) I see this
you must be measuring and awfully low frequency.
Erik
"you must be measuring and awfully low frequency."
it depends on how low your "low" is.
you must be measuring and awfully low frequency." it depends on how low your "low" is.
actually, I was wrong, it should have been
"you must be measuring and awfully high frequency. do read the maximun clock rate for the T0 input"