Chat
Danh mục
Mạch đo tần số hiển thị LCD 16x2

Mạch đo tần số hiển thị LCD 16x2

Số lượng:
Thêm vào giỏ
Mạch đo tần số hiển thị LCD 16x2 đã được thêm vào giỏ hàng



Code:
#include <reg51.H>
#include"LCD1602.h"
//--------------------------
//5 lcd display Frequency Meter
//--------------------------
//--------------------------------------------------
//Fixed function declaration
void int_0();       //External Interrupt 0

void int_1();       //External Interrupt 1

void t0();     //Timer Interrupt 1

void t1();     //Timer 2 interrupt

void serial_1();    //Serial interrupt 1

void serial_2();    //Serial interrupt 2
//---------------------------------------------------
//User function declaration
void initial();     //Initialization

void IntToStr(unsigned long t, unsigned char *str);//Data conversion mode

void Delay1ms(unsigned int num); //Delay Module
//---------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//Signal and data declarations
unsigned char timecount=0; //Gate count

unsigned char T0count; //Counter overflow count

sbit Gate=P3^1; //Gate output

sbit Clr=P3^7; //Clear signal

unsigned long x; //Frequency count container 1

bit flag=0; //Gate marks the end of

unsigned char TempBuffer[10];//Data buffer

//---------------------------------------------------------------------------------------------------------
void main(void)
{
  initial();

  Gate=1; //Gate opening

  Clr=1; //First clear 74LS393

  LCD_Initial(); //lcd initialization

  GotoXY(0,0); //Point to 0 rows 0

  Print(" Frequency Meter");

  GotoXY(0,1);

  Print("      Hz");

  while(1)

   {
     Clr=0;
if(flag)
{
flag=0;

  IntToStr(x,TempBuffer);       //Numeric conversion

GotoXY(0,1); //Locate

Print(TempBuffer); //Print data

        TR0=1;
}

    }
 

}
void initial() //Initialization
{

  TMOD=0x15;

  TH0=0; //Counter to pay the initial value

  TL0=0; //Counter to pay the initial value

  TH1=0x3b; //Timer initial payment

  TL1=0xb0; //Timer initial payment

  TR1=1; //Timer start

  TR0=1; //Counter Start

  ET0=1; //Interrupt counter open

  ET1=1; //Open timer interrupt

  EX1=1;               // INT1 disconnect

  IT1=0;               // INT1 trigger low (compared to a falling edge trigger)

  EA=1; //Open break

return;
}

void IntToStr(unsigned long t, unsigned char *str)
{
unsigned char a[10]; char i,length;                                
while(t/10) //The count value is converted to digital code values of pipe sections
        {
            a[i]=t%10;
            t=t/10;
            i++;
           }
        a[i]=t;
length=i+1;                                                  
for(i=0; i<length; i++)         //Converted to ASCII code              
a[i]=a[i]+'0';                                    
//for(i=0; a[i]=='0' && i<=6; i++);                    
//for(j=8-n; j<i; j++)       //Fill spaces                
// { *str=' ';  str++; }                            
for(i=length-1; i>=0; i--)                                      
{ *str=a[i]; str++; }  //Adding the number of effective          
*str='\0';
}

void int_1() interrupt 2 using 1 //INT1 interrupt generated from the P3.1 pin

{

T0count=0; //Clear high count

flag=1;


TH0=0; //Counter clear

TL0=0;

}

void t0(void) interrupt 1 using 0 //Counter interrupt service routine

{

T0count++;

}

void t1(void) interrupt 3 using 0 //Timer overflow interrupt program

{

  TH1=0x3b; //Initial reset

  TL1=0xb0;

  timecount++;

  if(timecount==20)

    {
TR0=0; //Stop counter

x=(T0count*65536+TH0*256+TL0)*255+P1;//Take the count
Clr=1; //Produce clear signal

timecount=0; //Count clear timer

Gate=!Gate; //Invert gate

    }

}


( Code full Keil C + Protues)
Khi nhấn nút "Tải Về Máy", bạn sẽ vào trang quảng cáo, vui lòng chờ 5 giây. Nút  hiện ra ở góc phải phía trên, nhấn vào để đến trang download
Bạn nào có nhu cầu vẽ mạch Nguyên lý + Layout + PCB: new.moon9xone@gmail.com

Theo 8051projects.info