|
转载自:零知开源快速入门15-数码管显示(1位)
http://www.lingzhilab.com/forum.php?mod=viewthread&tid=194&fromuid=2
(出处: 零知实验室)
一、工具原料
- 电脑,windows系统
- 零知开发板
- micro-usb线
- 数码管1个(共阳)
- 220Ω 电阻8个
- 面包板一个+若干跳线
二、硬件连接
1、电路原理图
2、电路连接
三、方法步骤
1、打开零知实验室软件开发工具,然后新建项目,输入以下代码:
- /**
- * 文件: 数码管-1位.ino by 零知实验室(www.lingzhilab.com)
- * -- 零知开源,让电子制作变得更简单! --
- * 时间: 2018/06/26 16:13
- * 说明: 测试1位数码管
- **/
- //下面为定义a~h, dp的引脚
- int a = 1;//a段
- int b = 0;
- int c = 2;
- int d = 5;
- int e = 4;
- int f = 6;
- int g = 9;
- int dp = 3;
- //分别显示0-9
- void digital_show_0(void);
- void digital_show_1(void);
- void digital_show_2(void);
- void digital_show_3(void);
- void digital_show_4(void);
- void digital_show_5(void);
- void digital_show_6(void);
- void digital_show_7(void);
- void digital_show_8(void);
- void digital_show_9(void);
- // the setup routine runs once when you press reset:
- void setup() {
- // put your setup code here, to run once:
- int i = 0;
- for(i=0; i<=6; i++)
- {
- pinMode(i, OUTPUT);
- }
- pinMode(9, OUTPUT);
- }
- // the loop routine runs over and over again forever:
- void loop() {
- // put your main code here, to run repeatedly:
- digital_show_0();
- delay(1000);
- digital_show_1();
- delay(1000);
- digital_show_2();
- delay(1000);
- digital_show_3();
- delay(1000);
- digital_show_4();
- delay(1000);
- digital_show_5();
- delay(1000);
- digital_show_6();
- delay(1000);
- digital_show_7();
- delay(1000);
- digital_show_8();
- delay(1000);
- digital_show_9();
- delay(1000);
- }
- void digital_show_0(void) //显示数字0
- {
- unsigned char j;
- digitalWrite(a,LOW);
- digitalWrite(b,LOW);
- digitalWrite(c,LOW);
- digitalWrite(d,LOW);
- digitalWrite(e,LOW);
- digitalWrite(f,LOW);
- digitalWrite(g,HIGH);
- digitalWrite(dp,HIGH);
- }
- void digital_show_1(void) //显示数字1
- {
- digitalWrite(a,HIGH);
- digitalWrite(b,LOW);
- digitalWrite(c,LOW);
- digitalWrite(d,HIGH);
- digitalWrite(e,HIGH);
- digitalWrite(f,HIGH);
- digitalWrite(g,HIGH);
- digitalWrite(dp,HIGH);
- }
- void digital_show_2(void) //显示数字2
- {
- digitalWrite(a,LOW);
- digitalWrite(b,LOW);
- digitalWrite(c,HIGH);
- digitalWrite(d,LOW);
- digitalWrite(e,LOW);
- digitalWrite(f,HIGH);
- digitalWrite(g,LOW);
- digitalWrite(dp,HIGH);
- }
- void digital_show_3(void) //显示数字3
- {
- digitalWrite(a,LOW);
- digitalWrite(b,LOW);
- digitalWrite(c,LOW);
- digitalWrite(d,LOW);
- digitalWrite(e,HIGH);
- digitalWrite(f,HIGH);
- digitalWrite(g,LOW);
- digitalWrite(dp,HIGH);
- }
- void digital_show_4(void) //显示数字4
- {
- digitalWrite(c,LOW);
- digitalWrite(b,LOW);
- digitalWrite(f,LOW);
- digitalWrite(g,LOW);
- digitalWrite(dp,HIGH);
- digitalWrite(a,HIGH);
- digitalWrite(e,HIGH);
- digitalWrite(d,HIGH);
- }
- void digital_show_5(void) //显示数字5
- {
- digitalWrite(a,LOW);
- digitalWrite(b, HIGH);
- digitalWrite(c,LOW);
- digitalWrite(d,LOW);
- digitalWrite(e, HIGH);
- digitalWrite(f,LOW);
- digitalWrite(g,LOW);
- digitalWrite(dp,HIGH);
- }
- void digital_show_6(void) //显示数字6
- {
- digitalWrite(a,LOW);
- digitalWrite(b,HIGH);
- digitalWrite(c,LOW);
- digitalWrite(d,LOW);
- digitalWrite(e,LOW);
- digitalWrite(f,LOW);
- digitalWrite(g,LOW);
- digitalWrite(dp,HIGH);
- }
- void digital_show_7(void) //显示数字7
- {
- digitalWrite(a,LOW);
- digitalWrite(b,LOW);
- digitalWrite(c,LOW);
- digitalWrite(d,HIGH);
- digitalWrite(e,HIGH);
- digitalWrite(f,HIGH);
- digitalWrite(g,HIGH);
- digitalWrite(dp,HIGH);
- }
- void digital_show_8(void) //显示数字8
- {
- digitalWrite(a,LOW);
- digitalWrite(b,LOW);
- digitalWrite(c,LOW);
- digitalWrite(d,LOW);
- digitalWrite(e,LOW);
- digitalWrite(f,LOW);
- digitalWrite(g,LOW);
- digitalWrite(dp,HIGH);
- }
- void digital_show_9(void) //显示数字9
- {
- digitalWrite(a,LOW);
- digitalWrite(b,LOW);
- digitalWrite(c,LOW);
- digitalWrite(d,LOW);
- digitalWrite(e, HIGH);
- digitalWrite(f,LOW);
- digitalWrite(g,LOW);
- digitalWrite(dp,HIGH);
- }
[color=rgb(51, 102, 153) !important]复制代码
2、按照之前的方式先【编译】,然后【上传】到开发板中。
四、成果展示
上面步骤成功完成后,我们就可以看到预期的结果了,如下:
|
|