Last active
September 15, 2019 05:02
-
-
Save 34j/5d947685c05b6dffbc725ca4917939cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void LEDDisp(){ | |
| for (int i = 0; i < DigitOfLED; i++) { | |
| if (i == 3) { | |
| LED9 = 0; | |
| } else if (i == 2) { | |
| LED8 = 0; | |
| } else if (i == 1) { | |
| LED6 = 0; | |
| } else if (i == 0) { | |
| LED12 = 0; | |
| } | |
| LED11 = LEDBoolToInt(LEDdisp[i][0]); | |
| LED7 = LEDBoolToInt(LEDdisp[i][1]); | |
| LED4 = LEDBoolToInt(LEDdisp[i][2]); | |
| LED2 = LEDBoolToInt(LEDdisp[i][3]); | |
| LED1 = LEDBoolToInt(LEDdisp[i][4]); | |
| LED10 = LEDBoolToInt(LEDdisp[i][5]); | |
| LED5 = LEDBoolToInt(LEDdisp[i][6]); | |
| LED3 = LEDBoolToInt((LEDDecimalpoint == i)); | |
| if (i == 3) { | |
| LED12 = 1; | |
| } else if (i == 2) { | |
| LED9 = 1; | |
| } else if (i == 1) { | |
| LED8 = 1; | |
| } else if (i == 0) { | |
| LED6 = 1; | |
| } | |
| __delay_ms(0.5); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define LED12 LATCbits.LATC5 | |
| #define LED11 LATCbits.LATC4 | |
| #define LED10 LATCbits.LATC3 | |
| #define LED9 LATCbits.LATC6 | |
| #define LED8 LATCbits.LATC7 | |
| #define LED7 LATBbits.LATB7 | |
| #define LED6 LATBbits.LATB6 | |
| #define LED5 LATBbits.LATB5 | |
| #define LED4 LATBbits.LATB4 | |
| #define LED3 LATCbits.LATC2 | |
| #define LED2 LATCbits.LATC1 | |
| #define LED1 LATCbits.LATC0 | |
| #define DigitOfLED 4 | |
| #define NumberOfLEDIn1Digit 7 | |
| const bool LEDE[NumberOfLEDIn1Digit] = {true, false, false, true, true, true, true}; //E | |
| const bool isCathodeCommon = false; | |
| bool LEDdisp[DigitOfLED][NumberOfLEDIn1Digit]; | |
| int LEDDecimalpoint; | |
| const bool LEDNumArray[10][NumberOfLEDIn1Digit] = { | |
| {true, true, true, true, true, true, false}, //0 | |
| {false, true, true, false, false, false, false}, //1 | |
| {true, true, false, true, true, false, true}, //2 | |
| {true, true, true, true, false, false, true}, //3 | |
| {false, true, true, false, false, true, true}, //4 | |
| {true, false, true, true, false, true, true}, //5 | |
| {true, false, true, true, true, true, true}, //6 | |
| {true, true, true, false, false, true, false}, //7 | |
| {true, true, true, true, true, true, true}, //8 | |
| {true, true, true, true, false, true, true}, //9 | |
| }; | |
| float Pow(float x, float y) {//math.hを使うとメモリ消費が… | |
| float value = 1; | |
| if (y > 0) { | |
| for (int i = 0; i < y; i++) { | |
| value *= x; | |
| } | |
| } else { | |
| for (int i = 0; i > y; i--) { | |
| value /= x; | |
| } | |
| } | |
| return value; | |
| } | |
| void ChangeValue(float value) { | |
| int digit = 1; | |
| while (value > 10) { | |
| value /= 10; | |
| digit++; | |
| } | |
| if (value < 0.1) { | |
| digit--; | |
| } | |
| if (digit > DigitOfLED || digit < -DigitOfLED + 3) {//valueが4桁では表せない時、EEEEと表示 | |
| for (int i = 0; i < DigitOfLED; i++) { | |
| for (int j = 0; j < NumberOfLEDIn1Digit; j++) { | |
| LEDdisp[i][j] = LEDE[j]; | |
| } | |
| } | |
| LEDDecimalpoint = DigitOfLED; | |
| } else { | |
| int ivalue = (int) (value * Pow(10, DigitOfLED - 1)); //Cの^は累乗じゃない | |
| for (int i = 0; i < DigitOfLED; i++) { | |
| int num = ivalue % 10; | |
| ivalue /= 10; | |
| for (int j = 0; j < NumberOfLEDIn1Digit; j++) { | |
| LEDdisp[i][j] = LEDNumArray[num][j]; | |
| } | |
| } | |
| if (digit <= 0) { | |
| LEDDecimalpoint = DigitOfLED - 1; | |
| } else if (digit == 4) { | |
| LEDDecimalpoint = DigitOfLED; | |
| } else { | |
| LEDDecimalpoint = DigitOfLED - digit; | |
| } | |
| } | |
| } | |
| int LEDBoolToInt(bool value) { | |
| value = !(value || isCathodeCommon); | |
| if (value == true) return 1; | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define LED12 LATCbits.LATC5 | |
| #define LED11 LATCbits.LATC4 | |
| #define LED10 LATCbits.LATC3 | |
| #define LED9 LATCbits.LATC6 | |
| #define LED8 LATCbits.LATC7 | |
| #define LED7 LATBbits.LATB7 | |
| #define LED6 LATBbits.LATB6 | |
| #define LED5 LATBbits.LATB5 | |
| #define LED4 LATBbits.LATB4 | |
| #define LED3 LATCbits.LATC2 | |
| #define LED2 LATCbits.LATC1 | |
| #define LED1 LATCbits.LATC0 | |
| #define DigitOfLED 4 | |
| #define NumberOfLEDIn1Digit 7 | |
| #define DemicalPointPos 3 | |
| const bool LEDE[NumberOfLEDIn1Digit] = {true, false, false, true, true, true, true}; //E | |
| const bool isCathodeCommon = false; | |
| bool LEDdisp[DigitOfLED][NumberOfLEDIn1Digit]; | |
| int LEDDecimalpoint; | |
| const bool LEDNumArray[10][NumberOfLEDIn1Digit] = { | |
| {true, true, true, true, true, true, false}, //0 | |
| {false, true, true, false, false, false, false}, //1 | |
| {true, true, false, true, true, false, true}, //2 | |
| {true, true, true, true, false, false, true}, //3 | |
| {false, true, true, false, false, true, true}, //4 | |
| {true, false, true, true, false, true, true}, //5 | |
| {true, false, true, true, true, true, true}, //6 | |
| {true, true, true, false, false, true, false}, //7 | |
| {true, true, true, true, true, true, true}, //8 | |
| {true, true, true, true, false, true, true}, //9 | |
| }; | |
| float Pow(float x, float y) {//math.hを使うとメモリ消費が… | |
| float value = 1; | |
| if (y > 0) { | |
| for (int i = 0; i < y; i++) { | |
| value *= x; | |
| } | |
| } else { | |
| for (int i = 0; i > y; i--) { | |
| value /= x; | |
| } | |
| } | |
| return value; | |
| } | |
| void ChangeValue(float value) { | |
| if (digit >= Pow(10, DemicalPointPos) {//valueが4桁では表せない時、EEEEと表示 | |
| for (int i = 0; i < DigitOfLED; i++) { | |
| for (int j = 0; j < NumberOfLEDIn1Digit; j++) { | |
| LEDdisp[i][j] = LEDE[j]; | |
| } | |
| } | |
| LEDDecimalpoint = DigitOfLED; | |
| } else { | |
| int ivalue = (int) (value * Pow(10, DigitOfLED - DemicalPointPos)); //Cの^は累乗じゃない | |
| for (int i = 0; i < DigitOfLED; i++) { | |
| int num = ivalue % 10; | |
| ivalue /= 10; | |
| for (int j = 0; j < NumberOfLEDIn1Digit; j++) { | |
| LEDdisp[i][j] = LEDNumArray[num][j]; | |
| } | |
| } | |
| LEDDecimalpoint = DemicalPointPos; | |
| } | |
| } | |
| int LEDBoolToInt(bool value) { | |
| value = !(value || isCathodeCommon); | |
| if (value == true) return 1; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment