本帖最后由 xo37 于 2019-2-21 07:22 编辑
1. 代码为纯源码;
2. 代码为本人原创;
3. 转载,请注明出处;
4. 机械设计一名,粗陋之处,各位高手请无视;
- unsigned char ChuShiHua[] = {0xfc, 0xfc, 0x02, 0xfc, 0xfc, 0x02, 0xfc, 0xfc};
- unsigned char Di_pin = 8; //连接到
- unsigned char Clk_pin = 9;
- unsigned char KaiShi = 7;
- unsigned char TingZhi = 3;
- unsigned char Qing = 2;
- unsigned char TestFlag = 0;
- unsigned char DisLCD[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- void QingLing(void);
- void ZhuanHuan(void);
- char m, s;
- char hx[] = {0, 0, 0, 0};
- char mx[] = {0, 0};
- char sx[] = {0, 0};
- int h;
- //-------------------------------------------------------------------------------
- //数码笔段定义: 8字的最上面一笔段为A笔段,顺时针方向依次为BCDEF笔段,中间的是G笔段
- //数码笔段顺序: D76543210
- // ABCDEFGX
- //unsigned char LCDbianma[] = {0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, 0xFE, 0xF6, 0x00, 0x02}; //,0x9C,0xCE,0x9E,0x8E};
- // 0 1 2 3 4 5 6 7 8 9 空格 - C P E F
- //-------------------------------------------------------------------------------
- void setup()
- {
- pinMode(Di_pin, OUTPUT);
- pinMode(Clk_pin, OUTPUT);
- pinMode(KaiShi, INPUT_PULLUP);
- pinMode(TingZhi, INPUT_PULLUP);
- pinMode(Qing, INPUT_PULLUP);
- QingLing();
- }
- void loop()
- {
- if (digitalRead(KaiShi) == LOW)
- {
- delay(50);
- if (digitalRead(KaiShi) == LOW)
- {
- TestFlag = 1;
- }
- }
- if (digitalRead(Qing) == LOW)
- {
- QingLing ();
- }
- while (TestFlag == 1)
- {
- for (long TimeS = 0; ; TimeS++)
- {
- h = TimeS / 3600; // 小时
- m = (TimeS - h * 3600) / 60; // 分钟
- s = TimeS - h * 3600 - m * 60;
- hx[3] = h / 1000; // 千位
- hx[2] = h / 100; // 百位
- hx[1] = h / 10; // 十位
- hx[0] = h % 10; // 个位
- mx[1] = m / 10; // 十位
- mx[0] = m % 10; // 个位
- sx[1] = s / 10; // 十位
- sx[0] = s % 10; // 个位
- //digitalWrite(latchPin, LOW);
- //shiftOut(Di_pin, Clk_pin, LSBFIRST,0x00); // 这里刷数据必须用 LSBFIRST(从最低位开始刷数据)
- //digitalWrite(latchPin, HIGH);
- if (TimeS < 360000) // 99.99.99小时内分辨率为1秒
- {
- ZhuanHuan(hx[1], 0);
- //delay(10);
- ZhuanHuan(hx[0], 1);
- //delay(10);
- DisLCD[2] = 0x02;
- ZhuanHuan(mx[1], 3);
- //delay(10);
- ZhuanHuan(mx[0], 4);
- //delay(10);
- DisLCD[5] = 0x02;
- ZhuanHuan(sx[1], 6);
- //delay(10);
- ZhuanHuan(sx[0], 7);
- //delay(10);
- }
- else // 大于99.99.99小时,分辨率为1分钟
- {
- // DisLCD[7] = 0x00;
- DisLCD[0] = 0x00;
- ZhuanHuan(hx[3], 1);
- //delay(10);
- ZhuanHuan(hx[2], 2);
- //delay(10);
- ZhuanHuan(hx[1], 3);
- //delay(10);
- ZhuanHuan(hx[0], 4);
- //delay(10);
- DisLCD[5] = 0x02;
- ZhuanHuan(mx[1], 6);
- //delay(10);
- ZhuanHuan(mx[0], 7);
- //delay(10);
- }
- for (unsigned char i = 0; i < 8; i++) //一共8位数,i<8
- {
- //开始刷屏
- shiftOut(Di_pin, Clk_pin, LSBFIRST, DisLCD[i]); // 这里刷数据必须用 LSBFIRST(从最低位开始刷数据)
- }
- if (digitalRead(TingZhi) == LOW)
- {
- TestFlag = 0;
- TimeS = 0;
- break;
- }
- delay(1000);
- }
- }
- }
- //Serial.println(digitalRead(KaiShi));
- //Serial.println(digitalRead(Stop));
- //Serial.println(digitalRead(QingL));
- void QingLing()
- {
- for (unsigned char i = 0; i < 8; i++) //一共8位数,i<8
- {
- //初始化上电显示为 00-00-00
- shiftOut(Di_pin, Clk_pin, LSBFIRST, ChuShiHua[i]); // 这里刷数据必须用 LSBFIRST(从最低位开始刷数据)
- }
- }
- void ZhuanHuan(int d, int a)
- {
- switch (d)
- {
- case 0:
- DisLCD[a] = 0xFC;
- break;
- case 1:
- DisLCD[a] = 0x60;
- break;
- case 2:
- DisLCD[a] = 0xDA;
- break;
- case 3:
- DisLCD[a] = 0xF2;
- break;
- case 4:
- DisLCD[a] = 0x66;
- break;
- case 5:
- DisLCD[a] = 0xB6;
- break;
- case 6:
- DisLCD[a] = 0xBE;
- break;
- case 7:
- DisLCD[a] = 0xE0;
- break;
- case 8:
- DisLCD[a] = 0xFE;
- break;
- case 9:
- DisLCD[a] = 0xF6;
- break;
- }
- }
复制代码
|