Tom Fleet
/
ShiftReg_7seg
A quick example of how to use a 7 Segment CA display with a 74HC164 Shift Register.
main.cpp@0:9c559759e6dc, 2013-02-22 (annotated)
- Committer:
- tomfleet
- Date:
- Fri Feb 22 13:57:49 2013 +0000
- Revision:
- 0:9c559759e6dc
Version 1, Working as expected.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomfleet | 0:9c559759e6dc | 1 | // Name: ShiftReg_7seg |
tomfleet | 0:9c559759e6dc | 2 | // Description: An example of how to print characters to a common anode 7-segment display. |
tomfleet | 0:9c559759e6dc | 3 | |
tomfleet | 0:9c559759e6dc | 4 | #include "mbed.h" |
tomfleet | 0:9c559759e6dc | 5 | #define dpMask 0x80 //bitiwse OR with data to enable decimal point |
tomfleet | 0:9c559759e6dc | 6 | SPI shiftReg (p5, p6, p7); |
tomfleet | 0:9c559759e6dc | 7 | DigitalOut MR (p8); |
tomfleet | 0:9c559759e6dc | 8 | DigitalOut myled(LED1); |
tomfleet | 0:9c559759e6dc | 9 | char charTable[16] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x83, 0xF8, 0x80, 0x98, 0x88, 0x83, 0xC6, 0xA1, 0x86 ,0x8E};//0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F |
tomfleet | 0:9c559759e6dc | 10 | |
tomfleet | 0:9c559759e6dc | 11 | void setup() |
tomfleet | 0:9c559759e6dc | 12 | { |
tomfleet | 0:9c559759e6dc | 13 | MR = 0; |
tomfleet | 0:9c559759e6dc | 14 | wait(0.1); |
tomfleet | 0:9c559759e6dc | 15 | MR = 1; |
tomfleet | 0:9c559759e6dc | 16 | shiftReg.write(0x00); |
tomfleet | 0:9c559759e6dc | 17 | wait(1); |
tomfleet | 0:9c559759e6dc | 18 | shiftReg.write(0xFF); |
tomfleet | 0:9c559759e6dc | 19 | wait(1); |
tomfleet | 0:9c559759e6dc | 20 | } |
tomfleet | 0:9c559759e6dc | 21 | |
tomfleet | 0:9c559759e6dc | 22 | int main() { |
tomfleet | 0:9c559759e6dc | 23 | setup(); |
tomfleet | 0:9c559759e6dc | 24 | while(1) { |
tomfleet | 0:9c559759e6dc | 25 | for (int i = 0; i < sizeof(charTable); i++) |
tomfleet | 0:9c559759e6dc | 26 | { |
tomfleet | 0:9c559759e6dc | 27 | shiftReg.write(charTable[i]); |
tomfleet | 0:9c559759e6dc | 28 | wait(0.2); |
tomfleet | 0:9c559759e6dc | 29 | } |
tomfleet | 0:9c559759e6dc | 30 | } |
tomfleet | 0:9c559759e6dc | 31 | } |