#include<reg51.h>
#define uchar unsigned char
#define DY_PORT P1 //设置LED连接的I/O组
#define DY_SPEED 1000 //设置每一个明亮级的停留时间(值域:0~65535)
sbit led1=P3^0;
sbit led2=P3^1;
sbit led3=P3^2;
sbit led4=P3^3;
//共阳极四位数码管
#define dig1 led1=0; led2=1; led3=1; led4=1; //P3^0选择第一个八
#define dig2 led1=1; led2=0; led3=1; led4=1; //P3^1选择第二个八
#define dig3 led1=1; led2=1; led3=0; led4=1;
#define dig4 led1=1; led2=1; led3=1; led4=0;
void delay (unsigned int a){ // 1ms延时程序
unsigned int i;
while( --a != 0){
for(i = 0; i < 600; i++);//STC
单片机在外部晶振为12MHz时i值上限为600
} //AT89C51单片机在外部晶振为12MHz时i值上限为125
}
main()
{
uchar number[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98};
uchar i;
while(1)
{
dig1
for (i=1;i<11;i++)
{
DY_PORT=number[i];
delay (DY_SPEED);
}
dig2
for(i=1;i<11;i++)
{
DY_PORT=number[i];
delay (DY_SPEED);
}
dig3
for(i=1;i<11;i++)
{
DY_PORT=number[i];
delay (DY_SPEED);
}
dig4
for(i=1;i<11;i++)
{
DY_PORT=number[i];
delay (DY_SPEED);
}
}
}
#include<reg51.h>
#define uchar unsigned char
#define DY_PORT P1 //设置LED连接的I/O组
#define DY_SPEED 1000 //设置每一个明亮级的停留时间(值域:0~65535)
sbit led1=P3^0;
sbit led2=P3^1;
sbit led3=P3^2;
sbit led4=P3^3;
//共阳极四位数码管
#define dig1 led1=1; led2=0; led3=0; led4=0; //P3^0选择第一个八
#define dig2 led1=0; led2=1; led3=0; led4=0; //P3^1选择第二个八
#define dig3 led1=0; led2=0; led3=1; led4=0;
#define dig4 led1=0; led2=0; led3=0; led4=1;
void delay (unsigned int a){ // 1ms延时程序
unsigned int i;
while( --a != 0){
for(i = 0; i < 600; i++);//STC单片机在外部晶振为12MHz时i值上限为600
} //AT89C51单片机在外部晶振为12MHz时i值上限为125
}
main()
{
uchar number[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98};
uchar i;
while(1)
{
dig1
for (i=0;i<10;i++)
{
DY_PORT=number;
delay (DY_SPEED);
}
dig2
for(i=0;i<10;i++)
{
DY_PORT=number;
delay (DY_SPEED);
}
dig3
for(i=0;i<10;i++)
{
DY_PORT=number;
delay (DY_SPEED);
}
dig4
for(i=0;i<10;i++)
{
DY_PORT=number;
delay (DY_SPEED);
}
}
}
好像跟没改之前现象一样
一周热门 更多>