V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
allright
V2EX  ›  C

大家帮我看看这段代码是什么意思!

  •  
  •   allright · 2017-05-07 11:29:23 +08:00 · 2781 次点击
    这是一个创建于 2547 天前的主题,其中的信息可能已经有所发展或是发生改变。

    temp1=(TH1256+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;

    17 条回复    2017-05-07 22:03:48 +08:00
    MrFireAwayH
        1
    MrFireAwayH  
       2017-05-07 11:32:45 +08:00 via Android
    格式惨不忍睹……

    大概是在进行某种加密算法吧
    lechain
        2
    lechain  
       2017-05-07 11:36:41 +08:00 via Android
    应用了某个分段函数对数据进行了处理,里面的数学函数你可以花点时间提取出来的
    daimao
        3
    daimao  
       2017-05-07 12:13:52 +08:00 via iPhone
    这不就是分段函数吗
    zhengjian
        4
    zhengjian  
       2017-05-07 13:27:19 +08:00
    Kilerd
        5
    Kilerd  
       2017-05-07 13:34:12 +08:00
    V2EX 第 217841 号会员,加入于 2017-02-27 22:45:30 +08:00
    AltairT
        6
    AltairT  
       2017-05-07 14:05:55 +08:00
    前面看起来使用 sum1 累积总的变化量,后面是根据数值大小进行修正.但是为什么要除以 10 得到 tmp 再进行修正呢?
    allright
        7
    allright  
    OP
       2017-05-07 15:00:15 +08:00   ❤️ 1
    #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;
    }
    }

    }


    它的完整程序是这样的,是一个用计频率的方法测风速。
    kokutou
        8
    kokutou  
       2017-05-07 15:22:02 +08:00
    感觉是防抖吧。。
    现实中温度不会剧烈变化,但是温度传感器读取的值会不停上下抖动。
    这段应该是去抖动的。
    Hconk
        9
    Hconk  
       2017-05-07 15:24:51 +08:00 via Android
    @AltairT 51 单片机的程序,用 1602 显示,可能是液晶显示的位数有限就除 10 舍掉一位。
    ijustdo
        10
    ijustdo  
       2017-05-07 15:31:54 +08:00   ❤️ 1
    告诉你吧 虽然没有写过 但是能猜测出 你看看风力测试器 一个杆子上一个标一吹发生唯一 然后没风又还原
    风的速度不是匀速的 呵呵呵
    基本就是风把他吹到发生位置片以后 他有他弹性自动复位初始位置
    所以在一定的频率内他的位移不是匀速的 是个角速度性质的加速度

    估计这个差不多就是 把风力测试器的位移速度转换为真实风速的一段了 。。。。
    ijustdo
        11
    ijustdo  
       2017-05-07 15:35:05 +08:00
    所以你要搞清楚这段代码 最快捷的方法是 找到原始的开发者
    第二科学快捷的方法是 找这段代码用到的地方的传感器硬件 然后找硬件的 pdf 和原理

    原来我的通假字吧 我笔记本装的语音输入法
    ijustdo
        12
    ijustdo  
       2017-05-07 15:39:29 +08:00
    不懂原理或者不懂代码运行环境的写代码 都是耍流氓
    mdzz
        13
    mdzz  
       2017-05-07 15:52:20 +08:00
    https://ooo.0o0.ooo/2017/05/07/590ed1fdea2ce.png
    大概是这样的
    AltairT
        14
    AltairT  
       2017-05-07 16:45:59 +08:00 via iPhone
    @Hconk 51 还是大学时用过😅怪不得前面有 Th*256 + Tl
    allright
        15
    allright  
    OP
       2017-05-07 22:01:46 +08:00
    感谢大神,好人一生平安!
    allright
        16
    allright  
    OP
       2017-05-07 22:03:14 +08:00
    @mdzz 万分感谢!
    allright
        17
    allright  
    OP
       2017-05-07 22:03:48 +08:00
    @ijustdo 感谢大神,好人一生平安!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2708 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:05 · PVG 19:05 · LAX 04:05 · JFK 07:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.