找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1239|回复: 1
收起左侧

我的这个程序数码管不能正常显示有大佬帮忙看一下吗

[复制链接]
ID:863894 发表于 2020-12-21 10:25 | 显示全部楼层 |阅读模式
u8 baojing=600;float t1,t2,t3,t_zhi;
u8 a=0,b=0,c=0,d=0;
u16 flag=0;
u16 p_temp;
unsigned char code LEDCODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char code dot[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
void delay(u16 ms)
{
        u16 i,j;
        for(i=ms;i>0;i--)
           for(j=110;j>0;j--);
}
void display(void){
        u16 temp3=t_zhi*10;
        if(t_zhi<1000)
        {a=temp3%10000/1000;
                b=temp3%1000/100;
                c=temp3%100/10;
                d=temp3%10;
        P0=LEDCODE[a];
        P2=0X01;//000000001
                delay(1);
                P2=0X00;
                P0=LEDCODE[b];
                P2=0X02;//0000 0010
                delay(1);
                P2=0X00;
                P0=dot[c];
                P2=0X04;//0000 0100
                delay(1);
                P2=0X00;
          P0=LEDCODE[d];
                P2=0X08;//0000 1000
                delay(1);
                P2=0X00;
}
        }
u16 get_temp()
{
        u8 i;
        u16 temp2=0;
        sck=0;
        sd=0;
        cs=0;
        for(i=0;i<16;i++)
        {sck=1;
                if(sd==1)
                {
                temp2=temp2|0x01;
        }
        delay(10);
        sck=0;
        delay(10);
        temp2<<=1;
}
        cs=1;
if(temp2&0x00004)
{
        normal=1;
}
temp2=(temp2&0x7fff)>>3;
return(temp2);
temp2=0;
delay(200);
}
void get_baojing(void)
{
        if(t_zhi<=500&&t_zhi>=baojing)
        {delay(500);
                shengyin=~shengyin;
                unnormal=0;
        }
}
void change()
{if(key1==0)
        {delay(10);
                if(key1==0)
                {flag=1;
                }
        }
                if(key2==0&&flag==1)
                {baojing=baojing+5;
                        flag=0;
                }
                if(key3==0&&flag==1)
                {baojing=baojing-5;
                        flag=0;
                }
        }
void main (void)
{
        delay(10);
        normal=0;
        sd=0;
        while(1)
        {p_temp=get_temp();
                t1=0.25*p_temp;
                delay(500);
                p_temp=0;
                p_temp=get_temp();
                t2=0.25*p_temp;
                delay(500);
                p_temp=0;
                p_temp=get_temp();
                t3=0.25*p_temp;
                t_zhi=((t1*t3)-(t2*t2))/((t3+t1)-(2*t2));
                get_baojing();
                display();
                change();
                t_zhi=0;
        }
}
       

回复

使用道具 举报

ID:863894 发表于 2020-12-21 10:26 | 显示全部楼层
#include <REGX51.H> #include <absacc.h> #include <math.h> typedef unsigned char u8; typedef unsigned int u16; sbit sd=P1^0; sbit sck=P1^1; sbit cs=P1^2; sbit unnormal=P3^7; sbit normal=P3^5; sbit shengyin=P1^7; sbit  key1=P1^3; sbit  key2=P1^4; sbit  key3=P1^5;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表