Skip to content

Commit 0c1355e

Browse files
author
Martin Crossley
committed
Incorporate review comments
1 parent 805ae87 commit 0c1355e

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

pio/seven_segment/7_segment.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ const PIO pio = pio0;
77
const uint first_segment_pin = 8; // gpio 15-8 = segments E,D,B,G,A,C,F,dp
88
const uint first_digit_pin = 16; // gpio 19-16 = common anodes 4,3,2,1
99

10-
// EDBGACF. bit ordering depends on your display and wiring
10+
// By convention the segments are labelled as follows:
11+
//
12+
// AAAA
13+
// F B
14+
// F B
15+
// GGGG
16+
// E C
17+
// E C
18+
// DDDD .
19+
20+
// You can define a custom bit pattern like this:
21+
// the order here is EDBGACF. but should match the way you wire up the GPIOs
1122
const uint32_t Pico = 0b10111010 << 24 | // 'P'
1223
0b10000000 << 16 | // 'i'
1324
0b11010000 << 8 | // 'c'

pio/seven_segment/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The total current required is typically more than the GPIO pins can supply so yo
77

88
The PIO code uses four `side-set` pins to control the digit multiplex lines and displays the segment patterns received on the FIFO. It uses a non-blocking PULL to keep showing the same segments until the CPU sends new data.
99

10-
The provided example uses spells out the word **Pico** and then counts from 0 to 9999.
10+
The provided example spells out the word **Pico** and then counts from 0 to 9999.
1111

1212
== Wiring information
1313
Connect the display to your board using a circuit like the one below, making any changes for your display and transistors.

pio/seven_segment/pio_7_segment_library/7_segment_lib.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ static const uint8_t segments[] = {
2222
//
2323
uint32_t int_to_seven_segment (int num) {
2424
uint32_t word = 0;
25-
if (num == 0) {
26-
word = segments[0];
27-
} else {
28-
for (int bitshift = 0; bitshift < 32 && num > 0; bitshift += 8) {
29-
word |= segments[num % 10] << bitshift;
30-
num /= 10;
25+
if (num > 9999) {
26+
// argument exceeds 4 digits: display an 'E' symbol
27+
word = 0b11011010
28+
} else {
29+
if (num == 0) {
30+
word = segments[0];
31+
} else {
32+
for (int bitshift = 0; bitshift < 32 && num > 0; bitshift += 8) {
33+
word |= segments[num % 10] << bitshift;
34+
num /= 10;
35+
}
3136
}
3237
}
3338
return word;

0 commit comments

Comments
 (0)