fa06501023 发表于 2012-2-24 23:03:53

关于74ls138+8位数码管一齐亮的问题

小弟刚刚入门单片机,学习数码管程序时遇上了问题,我想设计以P0-P7为总线控制数码管段选,P2.0,P2.1,P2.2控制74ls138位选,但情况并如理想,现附上程序,望各位前辈指点一二。数码管为共阳极,本程序先点亮数字0-4。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uint d,e;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
                                        0x82,0xf8,0x80,0x90,0x88,
                                        0x83,0xc6,0xa1,0x84,0x8e
                                        }; //0~F
uchar code weal[]={        0x00,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7
                                        };
void delay(uint);
void main()
{
       while(1)
       {
                   P0=0xc0;
                  for(e=0;e<8;e++)
                  {
                  
                          P2=weal;
                  }
                  delay(100);
                           P0=0xf9;
                  for(e=0;e<8;e++)
                  {
                  
                          P2=weal;
                       
                  }
                  delay(100);
                  P0=0xa4;
                  for(e=0;e<8;e++)
                  {
                  
                          P2=weal;
                  }
                  delay(100);
                           P0=0xb0;
                  for(e=0;e<8;e++)
                  {
                  
                          P2=weal;
                       
                  }
                  delay(100);
       }
}
void delay(uint x)
{
        uint a,b;
        for(a=x;a>0;a--)
       for(b=76;b>0;b--);
}

raxb 发表于 2012-3-3 11:42:42

回复【楼主位】fa06501023
-----------------------------------------------------------------------

根本就没入门嘛
页: [1]
查看完整版本: 关于74ls138+8位数码管一齐亮的问题