1个回答
展开全部
#include<reg51.h>
//-----------------------------------------------
void delay(unsigned int i) //延时
{
unsigned char j;
while(i--) for(j = 0; j < 115; j++);
}
//-----------------------------------------------
void main(void)
{
unsigned char n1;
unsigned char code SEG[] = {
0xc0, 0xf9, 0xa4, 0xb0, 0x99, //0-4
0x92, 0x82, 0xf8, 0x80, 0x90};//5-9
while(1) {
P0 = SEG[n1]; //P0口,外接共阳数码管的段选端
delay(2000);
n1++; if(n1 > 9) n1 = 0;
}
}
4个(任意个)共阳数码管的段选端,接在 P0,其位选,都接电源即可。
//-----------------------------------------------
void delay(unsigned int i) //延时
{
unsigned char j;
while(i--) for(j = 0; j < 115; j++);
}
//-----------------------------------------------
void main(void)
{
unsigned char n1;
unsigned char code SEG[] = {
0xc0, 0xf9, 0xa4, 0xb0, 0x99, //0-4
0x92, 0x82, 0xf8, 0x80, 0x90};//5-9
while(1) {
P0 = SEG[n1]; //P0口,外接共阳数码管的段选端
delay(2000);
n1++; if(n1 > 9) n1 = 0;
}
}
4个(任意个)共阳数码管的段选端,接在 P0,其位选,都接电源即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询