Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
7segment4LED.cpp@0:7a8925d2a8e7, 2015-06-25 (annotated)
- Committer:
 - takashikojo
 - Date:
 - Thu Jun 25 23:30:58 2015 +0000
 - Revision:
 - 0:7a8925d2a8e7
 
Initial version
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| takashikojo | 0:7a8925d2a8e7 | 1 | #include <mbed.h> | 
| takashikojo | 0:7a8925d2a8e7 | 2 | #include "7segment4LED.h" | 
| takashikojo | 0:7a8925d2a8e7 | 3 | |
| takashikojo | 0:7a8925d2a8e7 | 4 | static unsigned char SegPattern[] = { | 
| takashikojo | 0:7a8925d2a8e7 | 5 | 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x27, 0x7f, 0x6f, | 
| takashikojo | 0:7a8925d2a8e7 | 6 | 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71 | 
| takashikojo | 0:7a8925d2a8e7 | 7 | }; | 
| takashikojo | 0:7a8925d2a8e7 | 8 | |
| takashikojo | 0:7a8925d2a8e7 | 9 | FourDigitLED::FourDigitLED(PinName seg0, PinName seg1, PinName seg2, PinName seg3, | 
| takashikojo | 0:7a8925d2a8e7 | 10 | PinName seg4, PinName seg5, PinName seg6, PinName dot, | 
| takashikojo | 0:7a8925d2a8e7 | 11 | PinName digit0, PinName digit1, PinName digit2, PinName digit3 | 
| takashikojo | 0:7a8925d2a8e7 | 12 | ) | 
| takashikojo | 0:7a8925d2a8e7 | 13 | { | 
| takashikojo | 0:7a8925d2a8e7 | 14 | LEDs = new BusOut( seg0, seg1, seg2, seg3, seg4, seg5, seg6, dot, digit0, digit1, digit2, digit3) ; | 
| takashikojo | 0:7a8925d2a8e7 | 15 | scan_digit = 0 ; | 
| takashikojo | 0:7a8925d2a8e7 | 16 | /* test LEDs */ | 
| takashikojo | 0:7a8925d2a8e7 | 17 | LEDs->write(0xfe00 | MASK_DOT | 0x0) ; | 
| takashikojo | 0:7a8925d2a8e7 | 18 | wait(1.0) ; | 
| takashikojo | 0:7a8925d2a8e7 | 19 | setNum(0, 8); setNum(1, 8); setNum(2, 8); setNum(3, 8); | 
| takashikojo | 0:7a8925d2a8e7 | 20 | setDot(0, 1); setDot(1, 1); setDot(2, 1); setDot(3, 1); | 
| takashikojo | 0:7a8925d2a8e7 | 21 | /* end test */ | 
| takashikojo | 0:7a8925d2a8e7 | 22 | Scan_tick.attach(this, &FourDigitLED::Scan, 0.005); | 
| takashikojo | 0:7a8925d2a8e7 | 23 | wait(1.0) ; | 
| takashikojo | 0:7a8925d2a8e7 | 24 | val[0] = 0 ; val[1] = 0 ; val[2] = 0 ; val[3] = 0 ; | 
| takashikojo | 0:7a8925d2a8e7 | 25 | } | 
| takashikojo | 0:7a8925d2a8e7 | 26 | |
| takashikojo | 0:7a8925d2a8e7 | 27 | FourDigitLED::~FourDigitLED() | 
| takashikojo | 0:7a8925d2a8e7 | 28 | { | 
| takashikojo | 0:7a8925d2a8e7 | 29 | } | 
| takashikojo | 0:7a8925d2a8e7 | 30 | |
| takashikojo | 0:7a8925d2a8e7 | 31 | void FourDigitLED::Scan (void) | 
| takashikojo | 0:7a8925d2a8e7 | 32 | { | 
| takashikojo | 0:7a8925d2a8e7 | 33 | int d ; | 
| takashikojo | 0:7a8925d2a8e7 | 34 | d= ++scan_digit ; | 
| takashikojo | 0:7a8925d2a8e7 | 35 | d= d % DIGITS ; | 
| takashikojo | 0:7a8925d2a8e7 | 36 | LEDs->write(~(0x100 << d) & 0xff00 | (val[d] & 0xff) ) ; | 
| takashikojo | 0:7a8925d2a8e7 | 37 | } | 
| takashikojo | 0:7a8925d2a8e7 | 38 | |
| takashikojo | 0:7a8925d2a8e7 | 39 | int FourDigitLED::setNum(int d, int n) | 
| takashikojo | 0:7a8925d2a8e7 | 40 | { | 
| takashikojo | 0:7a8925d2a8e7 | 41 | if((n <0) || (n >= 16))return n ; | 
| takashikojo | 0:7a8925d2a8e7 | 42 | val[d] = (val[d] & 0xff80) | SegPattern[n] ; | 
| takashikojo | 0:7a8925d2a8e7 | 43 | return n ; | 
| takashikojo | 0:7a8925d2a8e7 | 44 | } | 
| takashikojo | 0:7a8925d2a8e7 | 45 | |
| takashikojo | 0:7a8925d2a8e7 | 46 | int FourDigitLED::setDot(int d, bool n) | 
| takashikojo | 0:7a8925d2a8e7 | 47 | { | 
| takashikojo | 0:7a8925d2a8e7 | 48 | val[d] = (val[d] & 0xff7f) | ((n == false) ? 0x0 : 0x80) ; | 
| takashikojo | 0:7a8925d2a8e7 | 49 | return n ; | 
| takashikojo | 0:7a8925d2a8e7 | 50 | } | 
| takashikojo | 0:7a8925d2a8e7 | 51 | |
| takashikojo | 0:7a8925d2a8e7 | 52 | void FourDigitLED::dump(void) { | 
| takashikojo | 0:7a8925d2a8e7 | 53 | printf("val = %02x, %02x, %02x, %02x\n", val[3], val[2], val[1], val[0]) ; | 
| takashikojo | 0:7a8925d2a8e7 | 54 | } |