This repository uses MCUXpresso, you may also want to look at the similar mbed project.
- Displays common characters and decimal point numbers on 4 digit 7-segment LEDs.
- Supports longer strings with scrolling display.
- Can be used on other 7-segment setups supporting i2c Inter-Integrated Circuit communication *
* Most probably only with adapting the encoded character constants in the source code. See Implementation.
There is an axf Release that can be used for K64F Boards with a display at 7bit address 0x38.
The package from the internet of things course during CH Open 2015 is very good to experiment with different sensors and other peripherals. CH Open 2015 Custom Shield.
The mbed 8bit address 0x70, printed on the Custom Shield, has to be addressed with 7bit address 0x38 here (right shift).
Above you see the running main method. The K64F base board under the custom shield is branched with standard USB to supply power and program loading.
Most of the header and source directories are created automatically by MCUXpresso based on the selected SDK components and the configured pins and clocks.
The only manually added C++ source files are:
source/SAA1064.hsource/SAA1064.cppsource/K64F_SAA1064_7Segment_Display_MCU.cpp— contains themain()function.
A new C++ project with i2c libraries may not have the full pin setup necessary. Make sure the I2C0 pin setup for I2C0 is done with routing, highlighted in yellow.
A side effect of these routes is the following initialization code in board/pin-mux.c
void BOARD_InitPins(void)
{
/* Port E Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortE);
/* PORTE24 (pin 31) is configured as I2C0_SCL */
PORT_SetPinMux(PORTE, 24U, kPORT_MuxAlt5);
/* PORTE25 (pin 32) is configured as I2C0_SDA */
PORT_SetPinMux(PORTE, 25U, kPORT_MuxAlt5);
}Displaying characters on a 7-segment display requires hardware knowledge and low-level bit manipulation. Each character is represented by seven segments plus a decimal point, forming an 8-bit pattern (1 byte). The SAA1064 uses these patterns to turn individual segments on or off.
Below is a typical 7-segment layout and the corresponding bit numbering used in the SEGMENT_MAP:
a
---
f | | b
-g-
e | | c
---
d dp
| Segment | Bit Position |
|---|---|
| a | 6 |
| b | 7 |
| c | 2 |
| d | 1 |
| e | 0 |
| f | 5 |
| g | 4 |
| dp | 3 |
Example: To display 0 with no decimal point:
SEGMENT_MAP['0'] = 0xE7; // 11100111This turns a, b, c, d, e, f ON, g AND dp OFF.
SEGMENT_MAP['0'] | 0x08 // turns on decimal pointDifferent displays may use a different segment-to-bit wiring, so the patterns in SEGMENT_MAP might not work out-of-the-box. To adapt:
- Identify which bit controls which segment on your hardware.
- Update the SEGMENT_MAP values so that each segment lights up correctly.
- Initialize i2c SDA and SCL pins correctly in MCUXpresso and pin_mux.c
- Create SAA1064 object with address from your hardware
SAA1064(uint8_t deviceAddress = SAA1064_ADDR );
