7セグLEDの出力サンプルソース。

Dependencies:   mbed

Committer:
syuzabu
Date:
Thu May 12 11:49:20 2011 +0000
Revision:
0:a935ccd0e492

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
syuzabu 0:a935ccd0e492 1 /*--------------------------------------------------------------
syuzabu 0:a935ccd0e492 2 / 7sed LED out sample
syuzabu 0:a935ccd0e492 3 --------------------------------------------------------------*/
syuzabu 0:a935ccd0e492 4 #include "mbed.h"
syuzabu 0:a935ccd0e492 5
syuzabu 0:a935ccd0e492 6 // 7seg LED - a, b, c, d, e, f, g, DP - [port assined]
syuzabu 0:a935ccd0e492 7 BusOut ledX(p25, p24, p14, p13, p12, p27, p26, p15); // 2digit
syuzabu 0:a935ccd0e492 8 BusOut ledY(p22, p21, p19, p17, p16, p23, p18, p20); // 1digit
syuzabu 0:a935ccd0e492 9
syuzabu 0:a935ccd0e492 10 // mbed LED
syuzabu 0:a935ccd0e492 11 BusOut mled(LED4, LED3, LED2, LED1);
syuzabu 0:a935ccd0e492 12
syuzabu 0:a935ccd0e492 13 int main() {
syuzabu 0:a935ccd0e492 14 // 7seg LED bit pattern - Dgfe dcba
syuzabu 0:a935ccd0e492 15 const int n0 = 0x3F; // 0011 1111
syuzabu 0:a935ccd0e492 16 const int n1 = 0x06; // 0000 0110
syuzabu 0:a935ccd0e492 17 const int n2 = 0x5B; // 0101 1011
syuzabu 0:a935ccd0e492 18 const int n3 = 0x4F; // 0100 1111
syuzabu 0:a935ccd0e492 19 const int n4 = 0x66; // 0110 0110
syuzabu 0:a935ccd0e492 20 const int n5 = 0x6D; // 0110 1101
syuzabu 0:a935ccd0e492 21 const int n6 = 0x7D; // 0111 1101
syuzabu 0:a935ccd0e492 22 const int n7 = 0x07; // 0000 0111
syuzabu 0:a935ccd0e492 23 const int n8 = 0x7F; // 0111 1111
syuzabu 0:a935ccd0e492 24 const int n9 = 0x6F; // 0110 1111
syuzabu 0:a935ccd0e492 25
syuzabu 0:a935ccd0e492 26 // convert: count -> 7seg number
syuzabu 0:a935ccd0e492 27 const int nX[] = {n0, n1, n2, n3, n4, n5, n6, n7, n8, n9};
syuzabu 0:a935ccd0e492 28
syuzabu 0:a935ccd0e492 29 int nCntX = 0; // 7seg LED counter
syuzabu 0:a935ccd0e492 30 int nCntY = 0; // mbed LED counter
syuzabu 0:a935ccd0e492 31
syuzabu 0:a935ccd0e492 32 // port init
syuzabu 0:a935ccd0e492 33 ledX = ~0;
syuzabu 0:a935ccd0e492 34 ledY = ~0;
syuzabu 0:a935ccd0e492 35 mled = 0;
syuzabu 0:a935ccd0e492 36
syuzabu 0:a935ccd0e492 37 while(1) {
syuzabu 0:a935ccd0e492 38 // 7seg LED count up
syuzabu 0:a935ccd0e492 39 ledX = ~nX[nCntX / 10];
syuzabu 0:a935ccd0e492 40 ledY = ~nX[nCntX % 10];
syuzabu 0:a935ccd0e492 41 nCntX++;
syuzabu 0:a935ccd0e492 42
syuzabu 0:a935ccd0e492 43 // 7seg LED limit count 99
syuzabu 0:a935ccd0e492 44 if (100 == nCntX) {
syuzabu 0:a935ccd0e492 45 nCntX = 0;
syuzabu 0:a935ccd0e492 46 nCntY++;
syuzabu 0:a935ccd0e492 47
syuzabu 0:a935ccd0e492 48 // mled LED count up
syuzabu 0:a935ccd0e492 49 mled = 0x0F & nCntY;
syuzabu 0:a935ccd0e492 50 }
syuzabu 0:a935ccd0e492 51
syuzabu 0:a935ccd0e492 52 wait(0.1);
syuzabu 0:a935ccd0e492 53 }
syuzabu 0:a935ccd0e492 54 }