标题:新手求教数码管问题~
只看楼主
fergus
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-9-15
结帖率:66.67%
已结贴  问题点数:20 回复次数:1 
新手求教数码管问题~
#include<reg51.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit LS138A=P2^2;
sbit LS138B=P2^3;
sbit LS138C=P2^4;
main()
{
uint8 code input[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint16 count;
uint8 i,sec,out[8];
TMOD=0x01;
TH0=0xFC;
TL0=0x67;
TR0=1;
    while(1)
    {
        if(1==TF0)
        {
        TF0=0;
        TH0=0xFC;
        TL0=0x67;
        count++;
        }                                       
        if(1000==count)
            {
            count=0;
            sec++;
            }
            out[0]=input[sec];
            out[1]=input[sec];
            out[2]=input[sec];
            out[3]=input[sec];
            out[4]=input[sec];
            out[5]=input[sec];
            out[6]=input[sec];
            out[7]=input[sec];
            for(i=0;i<8;i++)
                {
                P0=out[i];
                switch(i)
                     {
                      case 0:LS138A=0;LS138B=0;LS138C=0;break;
                      case 1:LS138A=1;LS138B=0;LS138C=0;break;
                     case 2:LS138A=0;LS138B=1;LS138C=0;break;
                     case 3:LS138A=1;LS138B=1;LS138C=0;break;
                      case 4:LS138A=0;LS138B=0;LS138C=1;break;
                     case 5:LS138A=1;LS138B=0;LS138C=1;break;
                     case 6:LS138A=0;LS138B=1;LS138C=1;break;
                     case 7:LS138A=1;LS138B=1;LS138C=1;break;
                      default:break;
                     }
                 }
    }
}
这样数码管可以0,1,2这样一直显示。
可把out[2]=input[sec];改为input[sec+1];为什么显示就完全乱了呢?
搜索更多相关主题的帖子: include 数码管 count 
2011-12-01 11:06
lulu0713
Rank: 2
等 级:论坛游民
帖 子:4
专家分:20
注 册:2007-11-26
得分:20 
if(count==1000)
            {
            count=0;
            sec++;
            }
            if(sec==8)sec=0;
            out[0]=input[sec];
            out[1]=input[sec];
加一句防SEC过8
2011-12-08 16:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-356680-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.365915 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved