求二位数码管共阴倒计时arduino uon 程序
答案:2 悬赏:10 手机版
解决时间 2021-04-14 13:21
- 提问者网友:無理詩人
- 2021-04-14 09:12
求二位数码管共阴倒计时arduino uon 程序
最佳答案
- 五星知识达人网友:你哪知我潦倒为你
- 2021-04-14 09:27
//设置控制各段的数字IO脚,具体几号引脚对应哪一段,来源为数码管官方引脚图。
int a=7;
int b=6;
int c=5;
int d=11;
int e=10;
int f=8;
int g=9;
int dp=4;
//显示数字1
void digital_1(void)
{
unsigned char j;
digitalWrite(c,LOW);//给数字5引脚低电平,点亮c段
digitalWrite(b,LOW);//点亮b段
for(j=7;j<=11;j++)//熄灭其余段
digitalWrite(j,HIGH);
digitalWrite(dp,HIGH);//熄灭小数点DP段
}
//显示数字2
void digital_2(void)
{
unsigned char j;
digitalWrite(b,LOW);
digitalWrite(a,LOW);
for(j=9;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
}
//显示数字3
void digital_3(void)
{
unsigned char j;
digitalWrite(g,LOW);
digitalWrite(d,LOW);
for(j=5;j<=7;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
digitalWrite(f,HIGH);
digitalWrite(e,HIGH);
}
//显示数字4
void digital_4(void)
{
digitalWrite(c,LOW);
digitalWrite(b,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(dp,HIGH);
digitalWrite(a,HIGH);
digitalWrite(e,HIGH);
digitalWrite(d,HIGH);
}
//显示数字5
void digital_5(void)
{
unsigned char j;
for(j=7;j<=9;j++)
digitalWrite(j,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(dp,HIGH);
digitalWrite(b,HIGH);
digitalWrite(e,HIGH);
}
//显示数字6
void digital_6(void)
{
unsigned char j;
for(j=7;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(c,LOW);
digitalWrite(dp,HIGH);
digitalWrite(b,HIGH);
}
//显示数字7
void digital_7(void)
{
unsigned char j;
for(j=5;j<=7;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
for(j=8;j<=11;j++)
digitalWrite(j,HIGH);
}
//显示数字8
void digital_8(void)
{
unsigned char j;
for(j=5;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
}
void setup()
{
int i;//定义变量
for(i=4;i<=11;i++)
pinMode(i,OUTPUT);//设置4~11引脚为输出模式
}
void loop()
{
while(1)
{
digital_1();//数字1
delay(2000);//延时2s
digital_2();
delay(2000);
digital_3();
delay(2000);
digital_4();
delay(2000);
digital_5();
delay(2000);
digital_6();
delay(2000);
digital_7();
delay(2000);
digital_8();
delay(2000);
}
}
int a=7;
int b=6;
int c=5;
int d=11;
int e=10;
int f=8;
int g=9;
int dp=4;
//显示数字1
void digital_1(void)
{
unsigned char j;
digitalWrite(c,LOW);//给数字5引脚低电平,点亮c段
digitalWrite(b,LOW);//点亮b段
for(j=7;j<=11;j++)//熄灭其余段
digitalWrite(j,HIGH);
digitalWrite(dp,HIGH);//熄灭小数点DP段
}
//显示数字2
void digital_2(void)
{
unsigned char j;
digitalWrite(b,LOW);
digitalWrite(a,LOW);
for(j=9;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
}
//显示数字3
void digital_3(void)
{
unsigned char j;
digitalWrite(g,LOW);
digitalWrite(d,LOW);
for(j=5;j<=7;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
digitalWrite(f,HIGH);
digitalWrite(e,HIGH);
}
//显示数字4
void digital_4(void)
{
digitalWrite(c,LOW);
digitalWrite(b,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(dp,HIGH);
digitalWrite(a,HIGH);
digitalWrite(e,HIGH);
digitalWrite(d,HIGH);
}
//显示数字5
void digital_5(void)
{
unsigned char j;
for(j=7;j<=9;j++)
digitalWrite(j,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(dp,HIGH);
digitalWrite(b,HIGH);
digitalWrite(e,HIGH);
}
//显示数字6
void digital_6(void)
{
unsigned char j;
for(j=7;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(c,LOW);
digitalWrite(dp,HIGH);
digitalWrite(b,HIGH);
}
//显示数字7
void digital_7(void)
{
unsigned char j;
for(j=5;j<=7;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
for(j=8;j<=11;j++)
digitalWrite(j,HIGH);
}
//显示数字8
void digital_8(void)
{
unsigned char j;
for(j=5;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
}
void setup()
{
int i;//定义变量
for(i=4;i<=11;i++)
pinMode(i,OUTPUT);//设置4~11引脚为输出模式
}
void loop()
{
while(1)
{
digital_1();//数字1
delay(2000);//延时2s
digital_2();
delay(2000);
digital_3();
delay(2000);
digital_4();
delay(2000);
digital_5();
delay(2000);
digital_6();
delay(2000);
digital_7();
delay(2000);
digital_8();
delay(2000);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯