欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

請高手看下這個單片機程序是有什么問題,一按鍵顯示就亂了

[復制鏈接]
跳轉到指定樓層
樓主
ID:614901 發表于 2020-3-16 21:57 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include<reg52.h>
#include"display.h"
#include"key.h"

unsigned char hour,miniute,second,keyval;
extern unsigned char temp[8];
extern unsigned char code duanma[10];//={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// 顯示段碼值0~9
extern unsigned char code weima[];//={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分別對應相應的數碼管點亮,即位碼

bit flag;
void main()
{
        TMOD=0x01;
        EA=1;
        ET0=1;
        TR0=1;
        //        TH0=(65536-2000)/256;
//        TL0=(65536-2000)%256;
        while(1)
        {
                keyval=keyscan();
                switch(keyval)
                {
                        case 1: hour++;break;
                        case 2: miniute++;break;
                        case 3: second++;break;
                        default:break;
                }
                if(flag==1)
                {
                        temp[0]=duanma[hour/10];
                        temp[1]=duanma[hour%10];
                        temp[2]=0x40;
                        temp[3]=duanma[miniute/10];
                        temp[4]=duanma[miniute%10];
                        temp[5]=0x40;
                        temp[6]=duanma[second/10];
                        temp[7]=duanma[second%10];
                        flag=0;
                }
        
        }
}

void timer0()interrupt 1
{
        static unsigned int i,k;
        TH0=(65536-2000)/256;
        TL0=(65536-2000)%256;
        display(0,8);
        i++;
        k++;
        if(k==10)
        {
                flag=1;
                k=0;
        }

                        
                if(i==500)
                {
                        second++;
                        i=0;
               
                if(second==60)
                {
                        miniute++;
                        second=0;
                }
                if(miniute==60)
                {
                        hour++;
                        if(hour==60)
                                hour=0;
                }
           }
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:614901 發表于 2020-3-16 21:59 | 只看該作者
還有debug的時候不能設置斷點,而換個程序就可以
回復

使用道具 舉報

板凳
ID:235200 發表于 2020-3-17 01:07 | 只看該作者
程序的結構還是得改一改,計秒 分 時最好放在循環程序中
回復

使用道具 舉報

地板
ID:213173 發表于 2020-3-17 08:47 | 只看該作者
還得看你的display.c和key.c,多數可能是keyscan()里使用了阻滯式延時所致。
回復

使用道具 舉報

5#
ID:614901 發表于 2020-3-17 23:10 | 只看該作者
wulin 發表于 2020-3-17 08:47
還得看你的display.c和key.c,多數可能是keyscan()里使用了阻滯式延時所致。

#include<reg52.h>
#include"key.h"
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;

void delayus(t)
{
        while(t--);
}

void delayms(tt)
{
        while(tt--)
        {
                delayus(245);
                        delayus(245);
        }
}


unsigned char keyscan()
{
        k1=1;
        if(!k1)
        {
                delayms(20);
                if(!k1)
                {
                       
                        while(!k1);
                        return(1);
                }
        }

        k2=1;
        if(!k2)
        {
                delayms(20);
                if(!k2)
                {
                       
                        while(!k2);
                        return(2);
                }
        }

        k3=1;
        if(!k3)
        {
                delayms(20);
                if(!k3)
                {
                       
                        while(!k3);
                        return(3);
                }
        }

        k4=1;
        if(!k4)
        {
                delayms(20);
                if(!k4)
                {
                       
                        while(!k4);
                        return(4);
                }
        }
}
回復

使用道具 舉報

6#
ID:614901 發表于 2020-3-17 23:10 | 只看該作者
wulin 發表于 2020-3-17 08:47
還得看你的display.c和key.c,多數可能是keyscan()里使用了阻滯式延時所致。
  1. #include<reg52.h>
  2. #include"display.h"
  3. #include"key.h"


  4. sbit wei=P2^3;
  5. sbit duan=P2^2;
  6. unsigned char temp[8];
  7. unsigned char code duanma[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// 顯示段碼值0~9
  8. unsigned char code weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分別對應相應的數碼管點亮,即位碼

  9. void display(unsigned char firstbit,unsigned char Num)
  10. {
  11.         unsigned char i;

  12.                 duan=1;
  13.                 P0=0;
  14.                 duan=0;

  15.                 wei=1;
  16.                 P0=weima[i+firstbit];
  17.                 wei=0;

  18.                 duan=1;
  19.                 P0=temp[i];
  20.                 duan=0;

  21.         
  22.         i++;
  23.         if(i==Num)
  24.                 i=0;
  25. }
復制代碼
回復

使用道具 舉報

7#
ID:614901 發表于 2020-3-17 23:11 | 只看該作者
csmyldl 發表于 2020-3-17 01:07
程序的結構還是得改一改,計秒 分 時最好放在循環程序中

開始我是放循環中的出了這個問題我放到中斷里還是有
回復

使用道具 舉報

8#
ID:614901 發表于 2020-3-17 23:13 | 只看該作者
csmyldl 發表于 2020-3-17 01:07
程序的結構還是得改一改,計秒 分 時最好放在循環程序中

我在設中斷秒標志時  定時器定50ms 就沒有這個問題  一設2ms就有了
回復

使用道具 舉報

9#
ID:614901 發表于 2020-3-17 23:14 | 只看該作者
wulin 發表于 2020-3-17 08:47
還得看你的display.c和key.c,多數可能是keyscan()里使用了阻滯式延時所致。

一開始定時器我設50ms就沒有問題,一改成2ms就有了
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表