Frequency Counter using AT89C2051 and LCD
http://www.8051projects.net/downloads221.html
Theory of Operation
As we all know frequency of a signal is number of cycle per second. I made use of this logic to calculate frequency of the input signal.
8051 has two timers, Timer 0 is configured for 1 second delay to sample the input signal and Timer 1 is used as a counter to calculate number of cycles in that 1 second. If timer1 overflows then the overflow is counter in another register which is considered as the high byte of Frequency. Input signal is provided at P3.5/T1 which is input for Timer 1 in counter mode. LCD is connected to microcontroller port 1 in 4-bit mode. Currently program is using 2 Line LCD but it can be used for 1 line LCD too.
Program initializes the Timer0 in 16-bit mode with 50mS delay value, a tick value of 20 is loaded to have total delay of 1s (50 x 20 = 1000 mS). Timer 1 is configured in 16-bit counter mode. After a sample of 1 sec, we get the number of cycles hence the frequency of input signal from timer1 registers (TH1:TL1) and high byte of Frequency. So total 3 byte value is then converted to a decimal equivalent represented in hex. This decimal value is then updated to LCD. The whole process repeats again.
another thing i have 89c51 what changes i have to do in assembley code and shematic?
thank you
[ Edited Mon Feb 01 2010, 12:01 pm ]
XX0,XX1,XX2,XX3 is input 4 byte number, YY0,YY1,YY2,YY3 is temporary number used inside X2D routine, and lastly ZZ0,ZZ1,ZZ2,ZZ3 is the o/p BCD number of X2D routine.
TMR0_ISR is used as interrupt service routine for 1 sec timer.
TMR1_ISR is interrupt routine for counting incoming signal frequency.
disp_num to display a number on LCD.
lcd_reset soft reset for LCD.
lcd_init 4-bit lcd initialization routine.
lcd_wait busy flag wait routine.
lcd_cmd to send command to LCD in 4-bit mode.
lcd_dat to send data to LCD in 4-bit mode.
delayms is routine for delay in miliseconds. uses delay variable which tells how much delay needed.
X2D 4-byte hex to BCD conversion.
another thing when i send frequency more than 500KHZ(the frequency is right until 500KHZ), the LCD shows 300KHZ or something like that and incorrect but in download section you wrote 16.5MHZ. is something wrong in my circuit?
[ Edited Wed Feb 03 2010, 09:16 am ]