1602显示方式是正确,却是固定值,不随输入改变而改变
#include <REG52.H>
#include<stdio.h>
#include<math.h>
#include "LCD1602.h"
#define uchar unsigned char
#define uint unsigned int
sbit clr=P3^0;
sbit gate=P3^1;
uint num=0;
uint j=0,counter=0;
unsigned long int Hight_byte=0,Low_byte=0;
//ms延时------------------------------
void delayms(uint ms) //延时xx毫秒
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
//定时计数 初始化----------------------------------
void CT_init()
{
TMOD = 0x25; // T0计数,T1定时
TH0 = 0x00;
TL0 = 0x00;
TH1 = 0x06;
TL1 = 0x06;
clr=1;
clr=0;
gate=0;
gate=1;
ET0 = 1;
ET1 = 1;
EA = 1;
TR0 = 1;
TR1 = 1;
}
//主函数--------------------------------------
void main()
{
unsigned long fre=0,oldfre=1;
bit mode=0;
uchar buff_f[10];
uchar buff_p[10];
uint temp=0;
LCD_Initial();
CT_init();
GotoXY(0,0);
Print("DianXin8 WANGHEI") ;
GotoXY(0,1);
Print("Stu No.120401222");
delayms(1000);
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN);
while(1)
{
fre=(Hight_byte*256)+Low_byte;
if(fre!=oldfre)
{
oldfre=fre;
if(fre==0)
{
GotoXY(0,0);Print("F= 0000000000 Hz");
GotoXY(0,1);Print("F= 0000000000 Hz");
}
else
{
sprintf(buff_p,"%0.6f",1000.0/fre);
sprintf(buff_f,"%ld",fre);
GotoXY(0,0);Print("F= Hz");
GotoXY(0,1);Print("P= ms");
GotoXY(2,0);Print(buff_f);
GotoXY(2,1);Print(buff_p);
}
}
}
}
/*--------------------------------------------------------------*/
//计数器T0中断服务程序
void T0_counter(void) interrupt 1 using 1
{
}
/*--------------------------------------------------------------*/
//定时器T1中断服务程序
void T1_timer(void) interrupt 3 using 3
{
if(num==3999){
gate=0;
TR0=0;TR1=0;
Hight_byte=TH0*256+TL0;
Low_byte=P1;
clr=1;
clr=0;
TH0 = 0x00;
TL0 = 0x00;
TH1 = 0x06;
TL1 = 0x06;
num=0;
gate=1;
TR0=1;TR1=1;
}
else num++;
}