}
else {//if(order == MSBFIRST){
digitalWrite(dPin,((0x80&(val<<i)) == 0x80) ? HIGH : LOW);
delayMicroseconds(1);
}
digitalWrite(cPin,HIGH);
delayMicroseconds(1);
}
}
void outData(int8_t data){ //function used to output data for 74HC595
digitalWrite(latchPin,LOW);
_shiftOut(dataPin,clockPin,MSBFIRST,data);
digitalWrite(latchPin,HIGH);
}
void display(int dec){ //display function for 7-segment display
int delays = 1;
outData(0xff);
selectDigit(0x01); //select the first, and display the single digit
outData(num[dec%10]);
delay( delays); //display duration
outData(0xff);
selectDigit(0x02); //select the second, and display the tens digit
outData(num[dec%100/10]);
delay( delays);
outData(0xff);
selectDigit(0x04); //select the third, and display the hundreds digit
outData(num[dec%1000/100]);
delay( delays);
outData(0xff);
selectDigit(0x08); //select the fourth, and display the thousands digit
outData(num[dec%10000/1000]);
delay( delays);
}
void timer(int sig){ //Timer function
if(sig == SIGALRM){ //If the signal is SIGALRM, the value of counter plus 1, and
update the number displayed by 7-segment display
counter ++;
alarm(1); //set the next timer time
printf("counter : %d \n",counter);
}
}