久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2978|回復: 12
打印 上一主題 下一主題
收起左側

單片機數碼管閃動,發暗是為什么?而且打開數碼管后,led也會跟著閃動

[復制鏈接]
跳轉到指定樓層
樓主
單片機數碼管閃動,發暗是為什么?而且打開數碼管后,led也會跟著閃動,兩個數碼管全開,有些led燈會直接黑了,測了發現變黑的led燈電壓變低。
這是代碼,剛接觸一段時間,不是很懂,網上查了資料,改了時延,都不行,大神求教
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uint cyc0=1200;
uchar codevalue[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};  //êy1üê,ê0~9oíèáá
uchar codevalue_dot[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78, 0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e};
uchar codecho[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};                  //
uint count_s=60;
uint tvalue;
uchar button[8]={0,0,0,0,0,0,0,0}; //啟動 設置 + - 低檔 高檔 照明 殺菌燈
uchar Jmark[5]={0,0,0,0,0};//低檔 高檔 風扇 燈 殺菌燈
uchar Ledmark[5]={0,0,0,0,0};//啟動 低檔 高檔 照明 殺菌燈
uchar num;

dis[5]=0;
bit timeOpen=0;
sbit DQ=P3^7;//溫度傳輸引腳定義
sbit duan=P3^2;
sbit wei=P3^3;
sbit led1=P2^0;
sbit led2=P2^1;
sbit led3=P2^2;
sbit led4=P2^3;
sbit led5=P2^4;
sbit led6=P3^6;

sbit j1=P2^5;
sbit j2=P2^6;
sbit j3=P2^7;
sbit j4=P3^0;
sbit j5=P3^1;

sbit Button1=P1^0;
sbit Button2=P1^1;
sbit Button3=P1^2;
sbit Button4=P1^3;
sbit Button5=P1^4;
sbit Button6=P1^5;
sbit Button7=P1^6;
sbit Button8=P1^7;




void t_clr()
{
        TMOD |= 0x01; //使用模式1,16位定時器,使用"|"符號可以在使用多個定時器時不受影響
//TH0=0x00; //給定初值
//TL0=0x00;
        EA=1; //總中斷打開
        ET0=1; //定時器中斷打開
        TR0=1; //定時器開關打開
        TH0=0X3c;
        TL0=0Xaf;
}

void dataCompute(){
        dis[0]=codevalue[tvalue%1000/100];
        dis[1]=codevalue_dot[tvalue%100/10];
        dis[2]=codevalue[tvalue%10];
        if(timeOpen==1){
                dis[3]=codevalue[count_s/10];
                dis[4]=codevalue[count_s%10];
        }else{
                dis[3]=0xff;
                dis[4]=0xff;
        }
       
}
void delay500us(void)   //誤差 0us
{
    unsigned char a,b;
    for(b=71;b>0;b--)
        for(a=2;a>0;a--);
}
void delay(uint z)
{
        uint x,y;
    for(x=z;x>0;x--)
      for(y=110;y>0;y--);   
}

//設置
void setMark(){

                        //低檔
                if(Jmark[0]==0){
                        j1=1;
                }else{
                        j1=0;
                }
                //高檔
                if(Jmark[1]==0){
                        j2=1;
                }else{
                        j2=0;
                }

                //風扇
                if(Jmark[2]==0){
                        j3=1;
                }else{
                        j3=0;
                }
                //-----------led控制-----------
                //啟動
                if(Ledmark[0]==0){
                        led1=1;
                        led6=1;
                }else{
                        led1=0;
                        led6=0;
                }
                //低檔
                if(Ledmark[1]==0){
                        led2=1;
                }else{
                        led2=0;
                }
                //高檔
                if(Ledmark[2]==0){
                        led3=1;
                }else{
                        led3=0;
                }
       
                        //照明
                if(Jmark[3]==0){
                        j4=1;
                }else{
                        j4=0;
                }
                //殺菌燈
                if(Jmark[4]==0){
                        j5=1;
                }else{
                        j5=0;
                }
                //照明
                if(Ledmark[3]==0){
                        led4=1;
                }else{
                        led4=0;
                }
                //殺菌燈
                if(Ledmark[4]==0){
                        led5=1;
                }else{
                        led5=0;
                }
}
void display()
{
        uchar k;
        for(k=0;k<5;k++)                                //LEDê
        {
       
         wei=1;
           P0=codecho[k];
         wei=0;
         duan=1;
                P0=dis[k];
         duan=0;
                delay(10);
                wei=0;
                duan=0;
         }
       
}
void key(){
        if(!Button1){
                               
                                delay(120);
                                if(!Button1){

                                        if(button[1]==1){
                                                        button[1]=0;
                                                        Ledmark[0]=0;
                                                        Ledmark[1]=0;
                                                        Ledmark[2]=0;
                                                        Ledmark[4]=0;
                                                        Jmark[0]=0;
                                                        Jmark[1]=0;
                                                        Jmark[2]=0;
                                                        timeOpen=0;
                                                        TR0=0; //關中斷 暫停倒計時
                                        }else{
                                                        button[1]=1;
                                                        Ledmark[0]=1;
                                                        Jmark[2]=1;
                                                        Jmark[0]=1;
                                                if(timeOpen==1){
                                                        TR0=1; //開中斷
                                                }                                               
                                        }
                        }
                }
                        if(!Button2){ //時間設置按鈕
                                       
                                delay(120);
                                if(!Button2){
                                        if(button[2]==1){        
                                                        button[2]=0;
                                                        timeOpen=0;  //時間顯示部分可能需要修改
                                        }else{                                                       
                                                        button[2]=1;
                                                       
                                                        dataCompute();
                                                        if(button[1]==1){
                                                                timeOpen=1;
                                                        }
                                        }
                                }
                       
                }
                        if(!Button3){ //+
                               
                                delay(120);
                                if(!Button3){
                                        if(button[2]==1){
                                                if(count_s<99){
                                                        count_s++;
                                                }
                                                       
                                        }
                                }
                       
                }
                        if(!Button4){ //-
                               
                                delay(120);
                                if(!Button4){
                                        if(button[2]==1){
                                                        if(count_s){
                                                                count_s--;
                                                        }
                                        }
                                }
                       
                }
                        if(!Button5){
                               
                                delay(120);
                                if(!Button5){
                                        if(button[1]==1){
                                                if(button[4]==1){
                                                button[4]=0;
                                        }else{
                                                button[4]=1;
                                                Ledmark[1]=1;
                                                Ledmark[2]=0;
                                                Jmark[0]=1;
                                                Jmark[1]=0;
                                        }
                                        }
                                       
                                }
                       
                }
                        if(!Button6){
                               
                                delay(120);
                                if(!Button6){
                                        if(button[1]==1){
                                                if(button[5]==1){
                                                button[5]=0;
                                                Ledmark[1]=1;
                                                Ledmark[2]=0;
                                                Jmark[0]=1;
                                                Jmark[1]=0;
                                        }else{
                                                button[5]=1;
                                                        Ledmark[1]=0;
                                                Ledmark[2]=1;
                                                Jmark[0]=1;
                                                Jmark[1]=1;
                                        }
                                        }
                                       
                                }
                       
                }
                        if(!Button7){
                                delay(120);
                                if(!Button7){
                                        if(button[7]==1){
                                                        button[7]=0;
                                                        Jmark[3]=0;
                                                        Ledmark[3]=0;
                                        }else{
                                                        button[7]=1;
                                                        Jmark[3]=1;
                                                        Ledmark[3]=1;
                                        }
                                }
                       
                }
                        if(!Button8){
                                delay(120);
                                if(!Button8){
                                        if(button[8]==1){
                                                        button[8]=0;
                                                        Jmark[4]=0;
                                                        Ledmark[4]=0;
                                        }else{
                                                        button[8]=1;
                                                        Jmark[4]=1;
                                                        Ledmark[4]=1;
                                        }
                                }
                       
                }
        }




void init(){  //初始化
led1=1;
led2=1;
led3=1;
led4=1;
led5=1;
led6=1;

j1=1;
j2=1;
j3=1;
j4=1;
j5=1;
timeOpen=0;
count_s=60;
}
/******************************ds18203***************************************/
void delay_18B20(unsigned int i)//óê±1¢
{
        while(i--);
}

void ds1820rst()/*ds1820′*/
{  unsigned char x=0;
         DQ = 1;          //DQ′
         delay_18B20(4);  //óê±
         DQ = 0;          //DQà-μí
         delay_18B20(100); //è·óê±′óóú480us
         DQ = 1;          //à-
         delay_18B20(40);         
   }  

   uchar ds1820rd()
  { unsigned char i=0;
         unsigned char dat = 0;
         for (i=8;i>0;i--)
         {   DQ = 0; //3Do
                  dat>>=1;
                  DQ = 1; //3Do
                  if(DQ)
                  dat|=0x80;
                  delay_18B20(10);
         }
        return(dat);
  }

  void ds1820wr(uchar wdata)
  {unsigned char i=0;
    for (i=8; i>0; i--)
   { DQ = 0;
     DQ = wdata&0x01;
     delay_18B20(10);
     DQ = 1;
     wdata>>=1;
   }
}



  read_temp()
{uchar a,b;
  ds1820rst();   
  ds1820wr(0xcc);
  ds1820wr(0x44);
  ds1820rst();   
  ds1820wr(0xcc);
  ds1820wr(0xbe);
  a=ds1820rd();
  b=ds1820rd();
  tvalue=b;
  tvalue<<=8;
  tvalue=tvalue|a;
  tvalue=tvalue*(0.625);
        return(tvalue);
  }

void main()
{
                t_clr();  
                init();
   while(1)
        {
                read_temp();
                dataCompute();
                key();
                setMark();
    display();
               
               

         }
  }
void t0() interrupt 1
{       
    TR0=0;
    TH0=0X3c;
                TL0=0Xaf;
    cyc0--;
        if (cyc0==0)
                {cyc0=1200;
                count_s--;  
        if (count_s!=0 && timeOpen==1)  
            {
             TR0=1;
            }
        else if(count_s==0){
            TR0=0;
                                                init();
                                }
                }
    else
        TR0=1;
          
}



BJ1S]N_P{~W}[UN8R[7%UW5.png (60.5 KB, 下載次數: 28)

BJ1S]N_P{~W}[UN8R[7%UW5.png

IMG_20200310_213528.jpg (6.32 MB, 下載次數: 22)

IMG_20200310_213528.jpg
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:692132 發表于 2020-3-11 05:50 來自手機 | 只看該作者
電源電壓跌了就是電源帶負載能力弱,測電壓
回復

使用道具 舉報

板凳
ID:401564 發表于 2020-3-11 08:21 | 只看該作者
看不懂,因為不會
你這個是自己畫的板子?如果是我,我就不會用74573,所以,我到現在還不會用這個IC
8051單片機帶8個數字以下的數碼是沒有壓力的,完全可以的,特別是STC的8051,它吸入電流大
這樣一來,你只需要12個IO就可以了,省去了畫板的的難度和IO
要是我的話,直接開工畫個V2.0版本的,幾天就可以到手了
回復

使用道具 舉報

地板
ID:332444 發表于 2020-3-11 08:36 | 只看該作者
好濫的程序,去淘換點好的,邏輯思路清晰的程序.
回復

使用道具 舉報

5#
ID:413157 發表于 2020-3-11 10:27 | 只看該作者
有可能是電流過小,當LED的電流小于5mA時是不會亮的,你可以計數一下,數碼管和LED都會有壓降。
回復

使用道具 舉報

6#
ID:679425 發表于 2020-3-11 10:35 | 只看該作者
數碼管和LED都會有壓降
回復

使用道具 舉報

7#
ID:699194 發表于 2020-3-11 10:38 | 只看該作者
實現這么小點的功效,沒必要用一大堆程序,可以去優化簡潔程序,其實實現你那種效果,程序就只是你的十分之一而已,你要學會優化程序
回復

使用道具 舉報

8#
ID:676158 發表于 2020-3-11 12:56 | 只看該作者
學習單片機lq 發表于 2020-3-11 05:50
電源電壓跌了就是電源帶負載能力弱,測電壓

我換了紅色燈泡,就能亮,應該就是電壓問題。。
回復

使用道具 舉報

9#
ID:676158 發表于 2020-3-11 13:00 | 只看該作者
Y_G_G 發表于 2020-3-11 08:21
看不懂,因為不會
你這個是自己畫的板子?如果是我,我就不會用74573,所以,我到現在還不會用這個IC
8051單片 ...

是的,是我自己畫的。因為我還有8個鍵盤和6的led,引腳不夠,所以才用的那個74573
回復

使用道具 舉報

10#
ID:676158 發表于 2020-3-11 13:03 | 只看該作者
xianfajushi 發表于 2020-3-11 08:36
好濫的程序,去淘換點好的,邏輯思路清晰的程序.

這是我自己寫的。。開發的時候需求還不是很清楚,所以我自己寫了一個。。。程序有改進的地方嗎?
回復

使用道具 舉報

11#
ID:676158 發表于 2020-3-11 13:04 | 只看該作者
付浩東 發表于 2020-3-11 10:27
有可能是電流過小,當LED的電流小于5mA時是不會亮的,你可以計數一下,數碼管和LED都會有壓降。

謝謝!是這個原因。
回復

使用道具 舉報

12#
ID:676158 發表于 2020-3-11 13:04 | 只看該作者
haierzaifei11 發表于 2020-3-11 10:35
數碼管和LED都會有壓降

謝謝!是這個原因
回復

使用道具 舉報

13#
ID:676158 發表于 2020-3-11 13:05 | 只看該作者
我叫小大打 發表于 2020-3-11 10:38
實現這么小點的功效,沒必要用一大堆程序,可以去優化簡潔程序,其實實現你那種效果,程序就只是你的十分之 ...

怎么優化。不是很懂!求告知!
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲精选一区二区 | 精品在线99| aaa在线| 狠狠干网站 | 久久久青草婷婷精品综合日韩 | 在线观看国产www | 午夜在线视频 | h视频免费在线观看 | 亚洲欧美激情精品一区二区 | 一区二区三区欧美 | 国产精品久久久乱弄 | 51ⅴ精品国产91久久久久久 | www久久久| 五月花丁香婷婷 | 欧美日产国产成人免费图片 | 自拍中文字幕 | 亚洲人成一区二区三区性色 | 一级黄色生活视频 | 黄色一级网 | 欧美日韩国产欧美 | 久久大| 日韩精品一区二区三区中文字幕 | 国产视频久 | 国产高清视频一区 | 国产综合久久 | 麻豆天堂 | 国产视频久久久 | 日日夜夜影院 | 国产成人精品区一区二区不卡 | 亚洲精品丝袜日韩 | 99精品欧美一区二区三区综合在线 | 亚洲欧美综合精品久久成人 | 一区久久| 欧美一级欧美一级在线播放 | 中文字幕在线第二页 | 黄色av大片| 涩涩视频在线观看 | 日本淫视频 | 日韩毛片在线免费观看 | 成人在线视频免费播放 | 久久成人免费视频 |