The frequency counting of the input signal is completed by using the t0 and T1 timing counter function of AT89S51 single chip microcomputer. The counted frequency results are displayed by 8-bit dynamic nixie tube. It is required to be able to accurately count the signal frequency of 0-250KHZ, and the counting error shall not exceed ± 1Hz.

1. Circuit schematic diagram

Design of signal frequency counting function based on AT89S51 single chip microcomputer

Figure 4.31.1

2. Hardware connection on the system board

(1)。 Connect p0.0-p0.7 in the “single chip microcomputer system” area with abcdefgh port in the “dynamic digital display” area with 8-core flat cable.

(2)。 Connect p2.0-p2.7 in the “single chip microcomputer system” area with s1s2s3s4s5s6s7s8 port in the “dynamic digital display” area with 8-core flat cable.

(3)。 Connect p3.4 (T0) terminal in “single chip microcomputer system” area to wave terminal in “frequency generator” area with wire.

3. Program design content

(1)。 The working mode settings of timer / counter t0 and T1 can be seen from the figure. T0 counts the input frequency signal when working in the counting state, but for t0 working in the counting state, the maximum count value is FOSC / 24. Since FOSC = 12Mhz, the maximum count frequency of t0 is 250kHz. The concept of frequency is to count the number of pulses in one second, that is, the frequency value. Therefore, T1 works in the timing state, stops the counting of t0 every 1 second of timing, reads the counted value from the counting unit of T0, and then performs data processing. Send it to the nixie tube for display.

(2)。 T1 works in the timing state, and the maximum timing time is 65ms, which can not reach the timing of 1s. Therefore, the timing of 50ms is adopted, with a total of 20 times, and the timing function of 1s can be completed.

4. C language source program

#include

unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,

0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};

unsigned char dispbuf[8]={0,0,0,0,0,0,10,10};

unsigned char temp[8];

unsigned char dispcount;

unsigned char T0count;

unsigned char timecount;

bit flag;

unsigned long x;

void main(void)

{

unsigned char i;

TMOD=0x15;

TH0=0;

TL0=0;

TH1=(65536-4000)/256;

TL1=(65536-4000)%256;

TR1=1;

TR0=1;

ET0=1;

ET1=1;

EA=1;

while(1)

{

if(flag==1)

{

flag=0;

x=T0count*65536+TH0*256+TL0;

for(i=0;i《8;i++)

{

temp=0;

}

i=0;

while(x/10)

{

temp=x%10;

x=x/10;

i++;

}

temp=x;

for(i=0;i《6;i++)

{

dispbuf=temp;

}

TImecount=0;

T0count=0;

TH0=0;

TL0=0;

TR0=1;

}

}

}

void t0(void) interrupt 1 using 0

{

T0count++;

}

void t1(void) interrupt 3 using 0

{

TH1=(65536-4000)/256;

TL1=(65536-4000)%256;

TImecount++;

if(TImecount==250)

{

TR0=0;

TImecount=0;

flag=1;

}

P0=dispcode[dispbuf[dispcount]];

P2=dispbit[dispcount];

dispcount++;

if(dispcount==8)

{

dispcount=0;

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *