本帖最后由 跳线工程师 于 2017-3-16 11:05 编辑
已经上传
仿真文件和hex文件
代码如下:
#include<reg51.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define x_clk 24000000.0 // 晶振频率
sbit GATE=P3^2; // 定时器0,1的门控位 D触发器输出Q 接INT0和INT1口(门控位)
sbit CLRP = P1^0; // D触发器清零端
sbit D_OPEN = P1^1; // D触发器D输入端
sbit RS=P2^0; // lcd1602数据/命令选择器(H/L)
sbit RW=P2^1; // lcd读写选择端(H/L)
sbit E=P2^6; // 1602使能信号
uchar str_buff[30];
uint counter0,counter1;
void delay(uint x)
{uint i,j;
for(i=0;i<x;i++)
for(j=0;j<110;j++);
}
void writecom(uchar com)
{RS=0;
RW=0;
P0=com;
delay(12);
E=1;
E=0;
}
void writedata(uchar *str)
{
RS=1;
RW=0;
while(*str!=' ')
{P0=*str;
str++;
delay(12);
E=1;
E=0;}
}
void init1602()
{RW=0;
E=0;
writecom(0x38);// 设置16*2显示,5*7点阵,8位数据接口
writecom(0x0c);// 设置开显示,不显示光标
writecom(0x06);//写一个字符后地址加1
writecom(0x01);//显示清零,数据指针清0
}
void main()
{
long float fx,temp,
time;
uint i;
init1602();
TMOD=0XD9; //设置计数器1,和定时器0
TR0=1;TR1=1;
ET0=1;ET1=1;
EA=1;
writecom(0x80);
writedata("Welcometostuelab");
D_OPEN=0;
CLRP=0;
while(1)
{
D_OPEN=0;
CLRP=0;
TH0=0;TL0=0;counter0=0;
TL1=0;TH1=0;counter1=0;
CLRP=1;
D_OPEN=1;
while(counter0<28);
D_OPEN=0;
while(GATE);
temp=counter0*65536.0+TH0*256.0+TL0;
time=(temp*12.0)/x_clk;//time=temp/1843.2;
//sprintf(str_buff," %-8.3fmS",time);
//write_com=0x80;
//write_com=0x01;//显示清零,数据指针清0
//printf0(0x00,"G=");
//printf0(0x02,str_buff);
fx=x_clk/12.0/temp;
fx=fx*(counter1*65536+TH1*256+TL1);
if (fx>1000000) sprintf(str_buff,"%-8.0fHz",fx);
else if(fx>100000) sprintf(str_buff,"%-8.1fHz",fx);
else if(fx>10000) sprintf(str_buff,"%-8.2fHz",fx);
else if(fx>1000) sprintf(str_buff,"%-8.3fHz",fx);
else if(fx>100) sprintf(str_buff,"%-8.4fHz",fx);
else if(fx>10) sprintf(str_buff,"%-8.5fHz",fx);
else if(fx>1) sprintf(str_buff,"%-8.6fHz",fx);
else sprintf(str_buff,"%-8.7fHz",fx);
writecom(0x80+0x40);
writedata("f=");
writecom(0x80+0x42);
writedata(str_buff);
}
}
void time0(void) interrupt 1
{counter0++;
}
void time1(void) interrupt 3
{counter1++;
}
-
-
-
仿真.zip
下载积分: 积分 -1 分
43.78 KB, 下载次数: 46, 下载积分: 积分 -1 分
一周热门 更多>