V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  allright  ›  全部回复第 1 页 / 共 1 页
回复总数  4
2017-05-07 22:03:48 +08:00
回复了 allright 创建的主题 C 大家帮我看看这段代码是什么意思!
@ijustdo 感谢大神,好人一生平安!
2017-05-07 22:03:14 +08:00
回复了 allright 创建的主题 C 大家帮我看看这段代码是什么意思!
@mdzz 万分感谢!
2017-05-07 22:01:46 +08:00
回复了 allright 创建的主题 C 大家帮我看看这段代码是什么意思!
感谢大神,好人一生平安!
2017-05-07 15:00:15 +08:00
回复了 allright 创建的主题 C 大家帮我看看这段代码是什么意思!
#include<reg52.h>
#include "LCD1602.h"
#include "DS18B20.h" //头文件
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit bobao=P2^3;
sbit key=P3^2;

sbit back=P2^0;


uchar data Test[16]=" sudu:00.0m/s "; //液晶显示数据
uchar data tabt[16]=" wendu:00.0C "; //液晶显示数据
ulong tmp;
bit nn;
uchar i;
int wendu;
long sum1=0;
uint temp1;
uchar point1;
uint xdata getdat1[50];
int xianshi;
char moshi;
int min,max;
long tt;
int sec;

//显示函数
void display()
{

/* tabt[0]=sec/100+'0';
tabt[1]=sec%100/10+'0';
tabt[2]=sec%10+'0';
*/
tabt[9]=wendu/100+'0';
tabt[10]=wendu%100/10+'0';
tabt[12]=wendu%10+'0';
ShowString(0,Test); //显示第一行
ShowString(1,tabt); //显示第 2 行
}

//T0 定时中断,晶振 24M

void T0_int(void) interrupt 1
{
static uint counter=0;
TH0 = 0x63;
TL0 = 0x0C0;
if(counter++==25)
{
counter=0;
temp1=(TH1*256+TL1);
sum1=sum1+temp1-getdat1[point1];
getdat1[point1]=temp1;
point1++;
point1=point1%10;
tmp=sum1/10;
if(tmp<10)tmp=tmp;
else if(tmp<32&&tmp>=10)tmp=20-10*(32-tmp)/(32-10);
else if(tmp<50&&tmp>=32)tmp=30-10*(50-tmp)/(50-32);
else if(tmp<67&&tmp>=50)tmp=40-10*(67-tmp)/(67-50);
else if(tmp<90&&tmp>=67)tmp=50-10*(90-tmp)/(90-67);
else if(tmp<100&&tmp>=90)tmp=60-10*(100-tmp)/(100-90);
else if(tmp<120&&tmp>=100)tmp=70-10*(120-tmp)/(120-100);
else if(tmp<140&&tmp>=120)tmp=80-10*(140-tmp)/(140-120);
else if(tmp<160&&tmp>=140)tmp=90-10*(160-tmp)/(160-140);
else if(tmp<170&&tmp>=160)tmp=100-10*(170-tmp)/(170-160);
else if(tmp<186&&tmp>=170)tmp=110-10*(186-tmp)/(186-170);
else if(tmp<216&&tmp>=186)tmp=120-10*(216-tmp)/(216-186);
else if(tmp<228&&tmp>=216)tmp=130-10*(228-tmp)/(228-216);
else if(tmp<246&&tmp>=228)tmp=140-10*(246-tmp)/(246-228);
else if(tmp<250&&tmp>=246)tmp=150-10*(250-tmp)/(250-246);
else if(tmp<289&&tmp>=250)tmp=160-10*(289-tmp)/(289-250);
else if(tmp<600&&tmp>=289)tmp=300-140.0*311/(600-tmp);
else if(tmp>=600)tmp=300;
if(moshi==0)
{
xianshi=tmp;
}
else if(moshi==1)
{
if(tmp>max)
{
xianshi=max=tmp;
}
}
else if(moshi==2)
{
if(tmp<min)
{
xianshi=min=tmp;
}
}
Test[7]=xianshi/100+'0';
Test[8]=xianshi%100/10+'0';
Test[10]=xianshi%10+'0';
if(xianshi>0)tt=0;
TH1=TL1=0;
}
}
void int0(void) interrupt 0
{
if(key==0)
{
DelayMs(5);
if(key==0)
{
while(key==0);
moshi++;
if(moshi>2)moshi=0;
if(moshi==0)
{
Test[2]='s';
Test[3]='u';
Test[4]='d';
Test[5]='u';
}
else if(moshi==1)
{
Test[2]=' ';
Test[3]='m';
Test[4]='a';
Test[5]='x';
max=xianshi;
}
else if(moshi==2)
{
Test[2]=' ';
Test[3]='m';
Test[4]='i';
Test[5]='n';
min=xianshi;
}

}
}
tt=0;
}
void main(void)
{
for(i=0;i<50;i++)getdat1[i]=0;
TMOD = 0x51;/*01010001 T1 计数,T0 定时*/
TH1 = 0;
TL1 = 0;
TH0=0x3c;
TL0=0xb0;
TR0 = 1; //开定时器 0
TR1 = 1; //启动计时器 1
EA = 1; //开总中断
ET0 = 1; //开定时器 0 中断
ET1 = 1; //开定时器 0 中断
PT0=1; //定时器 0 优先级高
IT0=1;
EX0=1;

InitLcd(); //液晶初始化
DelayMs(25); //延时函数
back=0;
while(1)
{
wendu=ReadTemperature()/10;
display();
tt++;
if(tt>2100)
{
tt=2100;
WriteCommand(0x01);
back=1;
while(tt==2100) ;
back=0;
}
}

}


它的完整程序是这样的,是一个用计频率的方法测风速。
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2413 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 16:11 · PVG 00:11 · LAX 09:11 · JFK 12:11
Developed with CodeLauncher
♥ Do have faith in what you're doing.