From 3ac92b944264b434cebb6b861de62580d0e1dc1a Mon Sep 17 00:00:00 2001 From: Suhayl <838119509@qq.com> Date: Mon, 16 Jul 2018 09:01:47 +0800 Subject: [PATCH] Update the C code of the 4-digital-display After the system is updated, in the ShiftOut function, the IO port pin changes too fast, resulting in communication abnormality with 74HC595. In the update, the SHIFT function is override. --- Code/C_Code/18.2.1_StopWatch/StopWatch.c | 40 +++++++++++++++++++----- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/Code/C_Code/18.2.1_StopWatch/StopWatch.c b/Code/C_Code/18.2.1_StopWatch/StopWatch.c index 765e7de..05ae9f5 100644 --- a/Code/C_Code/18.2.1_StopWatch/StopWatch.c +++ b/Code/C_Code/18.2.1_StopWatch/StopWatch.c @@ -2,7 +2,7 @@ * Filename : StopWatch.c * Description : Control 4_Digit_7_Segment_Display by 74HC595 * Author : freenove -* modification: 2016/07/07 +* modification: 2018/07/16 **********************************************************************/ #include #include @@ -23,24 +23,48 @@ void selectDigit(int digit){ digitalWrite(digitPin[2],((digit&0x02) == 0x02) ? LOW : HIGH); digitalWrite(digitPin[3],((digit&0x01) == 0x01) ? LOW : HIGH); } -void outData(int8_t data){ //function used to output data for 74HC595输出数据函数 +void _shiftOut(int dPin,int cPin,int order,int val){ + int i; + for(i = 0; i < 8; i++){ + digitalWrite(cPin,LOW); + if(order == LSBFIRST){ + digitalWrite(dPin,((0x01&(val>>i)) == 0x01) ? HIGH : LOW); + delayMicroseconds(1); + } + else {//if(order == MSBFIRST){ + digitalWrite(dPin,((0x80&(val<