小弟刚刚入门单片机,学习数码管程序时遇上了问题,我想设计以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[e];
}
delay(100);
P0=0xf9;
for(e=0;e<8;e++)
{
P2=weal[e];
}
delay(100);
P0=0xa4;
for(e=0;e<8;e++)
{
P2=weal[e];
}
delay(100);
P0=0xb0;
for(e=0;e<8;e++)
{
P2=weal[e];
}
delay(100);
}
}
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=76;b>0;b--);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
-----------------------------------------------------------------------
根本就没入门嘛
一周热门 更多>