EasyManua.ls Logo

Freenove Ultimate Starter Kit

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 18 74HC595 & 7-segment display.
200
www.freenove.com ā–ˆ
ā–ˆ support@freenove.com
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
}
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);
}
}

Table of Contents