displays a float (decimal number) to 4 digit, 7 segment LED display LDQ-N514R1 using mbed LPC1768
Fork of 7SegmentDisplay by
main.cpp@3:c747b832518f, 2016-09-06 (annotated)
- Committer:
- captaintim
- Date:
- Tue Sep 06 06:27:58 2016 +0000
- Revision:
- 3:c747b832518f
- Parent:
- 2:3cf4eba9de56
Added ability to increment the float number by moving While (1) statement and making a few other changes.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ShingyoujiPai | 0:463ff11d33fa | 1 | #include "mbed.h" |
ShingyoujiPai | 0:463ff11d33fa | 2 | |
captaintim | 1:46dbd77e0701 | 3 | /*test program to learn how to write code for a 4 digit, 7-segment LED display LDQ-N524R1 |
captaintim | 1:46dbd77e0701 | 4 | The schematic for this (COMMON CATHODE) display shows the following connections |
captaintim | 1:46dbd77e0701 | 5 | schematic located at http://www.lumex.com/ldq-n514ri (open Specs PDF for drawing) |
captaintim | 1:46dbd77e0701 | 6 | The Common Cathode means that to turn on the segments of the 7-segment (including decimal point) |
captaintim | 1:46dbd77e0701 | 7 | you write a one to that segment. |
captaintim | 1:46dbd77e0701 | 8 | For this 4 digit display (LDQ-N524R1), each digit works backward--like its wired Common Anode so |
captaintim | 1:46dbd77e0701 | 9 | You write a ZERO to turn on the selected digit AND a ONE to turn off the digit. |
captaintim | 1:46dbd77e0701 | 10 | |
captaintim | 1:46dbd77e0701 | 11 | Pin Out wiring guide:(connect the display pin # to XX mbed pin) |
ShingyoujiPai | 0:463ff11d33fa | 12 | |
captaintim | 1:46dbd77e0701 | 13 | CONTROL DISPLAY Pin# MBED Pin# |
captaintim | 1:46dbd77e0701 | 14 | ---------------------------------- |
captaintim | 1:46dbd77e0701 | 15 | Digit1 12 14 |
captaintim | 1:46dbd77e0701 | 16 | Digit2 9 13 |
captaintim | 1:46dbd77e0701 | 17 | Digit3 8 12 |
captaintim | 1:46dbd77e0701 | 18 | Digit4 6 11 |
captaintim | 1:46dbd77e0701 | 19 | DP 3 10 |
captaintim | 1:46dbd77e0701 | 20 | A 11 21 |
captaintim | 1:46dbd77e0701 | 21 | B 7 22 |
captaintim | 1:46dbd77e0701 | 22 | C 4 23 |
captaintim | 1:46dbd77e0701 | 23 | D 2 24 |
captaintim | 1:46dbd77e0701 | 24 | E 1 25 |
captaintim | 1:46dbd77e0701 | 25 | F 5 26 |
captaintim | 1:46dbd77e0701 | 26 | G 5 27 |
captaintim | 1:46dbd77e0701 | 27 | |
captaintim | 1:46dbd77e0701 | 28 | There is no blanking on this display, |
captaintim | 2:3cf4eba9de56 | 29 | Program demonstrates writing to all four digits of the 7-segment LED display of the LDQ-N514R1 a decimal number |
captaintim | 2:3cf4eba9de56 | 30 | Since the segments only light up for one selected digit, all 4 digit has to be flashed to show 4 separate numbers |
captaintim | 2:3cf4eba9de56 | 31 | Television used this by flashing 30 screens per second call persistence enhanced cathode ray tubes. |
ShingyoujiPai | 0:463ff11d33fa | 32 | |
captaintim | 1:46dbd77e0701 | 33 | Author: Cap'n Tim Johnson PE |
captaintim | 1:46dbd77e0701 | 34 | Retired Professor |
captaintim | 1:46dbd77e0701 | 35 | Wentworth Institude of Technology |
captaintim | 1:46dbd77e0701 | 36 | Dept. Electrical Engineering and Technology |
captaintim | 1:46dbd77e0701 | 37 | Boston, MA |
captaintim | 1:46dbd77e0701 | 38 | */ |
captaintim | 1:46dbd77e0701 | 39 | |
captaintim | 1:46dbd77e0701 | 40 | //Setup: |
captaintim | 1:46dbd77e0701 | 41 | DigitalOut Digit1(p14); //construct to control digits |
captaintim | 1:46dbd77e0701 | 42 | DigitalOut Digit2(p13); |
captaintim | 1:46dbd77e0701 | 43 | DigitalOut Digit3(p12); |
captaintim | 1:46dbd77e0701 | 44 | DigitalOut Digit4(p11); |
captaintim | 2:3cf4eba9de56 | 45 | DigitalOut myled (LED1); //Signal used for runtime checking |
captaintim | 1:46dbd77e0701 | 46 | |
captaintim | 1:46dbd77e0701 | 47 | //these are the pins associated with writing to the "led" |
captaintim | 1:46dbd77e0701 | 48 | DigitalOut led[8]={p21, p22, p23, p24, p25, p26, p27, p10}; |
captaintim | 1:46dbd77e0701 | 49 | |
captaintim | 1:46dbd77e0701 | 50 | //segments are in alphabetical order a-g, followed by Decimal point in the array below |
captaintim | 1:46dbd77e0701 | 51 | |
captaintim | 1:46dbd77e0701 | 52 | int matrix[11][8]={ |
captaintim | 1:46dbd77e0701 | 53 | {1,1,1,1,1,1,0,0}, //zero |
captaintim | 1:46dbd77e0701 | 54 | {0,1,1,0,0,0,0,0}, //one |
captaintim | 1:46dbd77e0701 | 55 | {1,1,0,1,1,0,1,0}, //two |
captaintim | 1:46dbd77e0701 | 56 | {1,1,1,1,0,0,1,0}, //three |
captaintim | 1:46dbd77e0701 | 57 | {0,1,1,0,0,1,1,0}, //four |
captaintim | 1:46dbd77e0701 | 58 | {1,0,1,1,0,1,1,0}, //five |
captaintim | 1:46dbd77e0701 | 59 | {1,0,1,1,1,1,1,0}, //six |
captaintim | 1:46dbd77e0701 | 60 | {1,1,1,0,0,0,0,0}, //seven |
ShingyoujiPai | 0:463ff11d33fa | 61 | {1,1,1,1,1,1,1,0}, //eight |
captaintim | 1:46dbd77e0701 | 62 | {1,1,1,0,0,1,1,0}, //nine |
ShingyoujiPai | 0:463ff11d33fa | 63 | {0,0,0,0,0,0,0,1} //dot |
ShingyoujiPai | 0:463ff11d33fa | 64 | }; |
ShingyoujiPai | 0:463ff11d33fa | 65 | |
captaintim | 2:3cf4eba9de56 | 66 | //create matrix to handle decimal point |
captaintim | 2:3cf4eba9de56 | 67 | int matrixdecimal[11][8]={ |
captaintim | 2:3cf4eba9de56 | 68 | {1,1,1,1,1,1,0,1}, //zero |
captaintim | 2:3cf4eba9de56 | 69 | {0,1,1,0,0,0,0,1}, //one |
captaintim | 2:3cf4eba9de56 | 70 | {1,1,0,1,1,0,1,1}, //two |
captaintim | 2:3cf4eba9de56 | 71 | {1,1,1,1,0,0,1,1}, //three |
captaintim | 2:3cf4eba9de56 | 72 | {0,1,1,0,0,1,1,1}, //four |
captaintim | 2:3cf4eba9de56 | 73 | {1,0,1,1,0,1,1,1}, //five |
captaintim | 2:3cf4eba9de56 | 74 | {1,0,1,1,1,1,1,1}, //six |
captaintim | 2:3cf4eba9de56 | 75 | {1,1,1,0,0,0,0,1}, //seven |
captaintim | 2:3cf4eba9de56 | 76 | {1,1,1,1,1,1,1,1}, //eight |
captaintim | 2:3cf4eba9de56 | 77 | {1,1,1,0,0,1,1,1}, //nine |
captaintim | 2:3cf4eba9de56 | 78 | {0,0,0,0,0,0,0,1} //dot...actually a leading null space |
captaintim | 2:3cf4eba9de56 | 79 | }; |
ShingyoujiPai | 0:463ff11d33fa | 80 | |
captaintim | 2:3cf4eba9de56 | 81 | //set persistance (wait value on digits or flash rate) |
captaintim | 2:3cf4eba9de56 | 82 | float f = 0.005; |
captaintim | 2:3cf4eba9de56 | 83 | //enter a float number here (with a decimal in it) starting point |
captaintim | 2:3cf4eba9de56 | 84 | volatile float temp = 31.45; |
captaintim | 3:c747b832518f | 85 | int t = temp * 100; |
captaintim | 2:3cf4eba9de56 | 86 | |
captaintim | 2:3cf4eba9de56 | 87 | int main(){ |
captaintim | 3:c747b832518f | 88 | while (1){ |
captaintim | 2:3cf4eba9de56 | 89 | //finessing the digits out one at a time knowing 2nd digit has the decimal |
captaintim | 3:c747b832518f | 90 | //int tempasinteger = temp * 100; //removes decimal and typecasts float to integer |
captaintim | 3:c747b832518f | 91 | int temp1a = t/1000; //typecast float to integer for 1st digit (was) |
captaintim | 3:c747b832518f | 92 | int temp2 = t - temp1a*1000; //gets last 3 digits |
captaintim | 2:3cf4eba9de56 | 93 | int temp2a = temp2/100; //typecast float to integer for 2nd digit |
captaintim | 2:3cf4eba9de56 | 94 | int temp3 = temp2 - temp2a*100; //get last 2 digits |
captaintim | 2:3cf4eba9de56 | 95 | |
captaintim | 2:3cf4eba9de56 | 96 | int temp3a=temp3/10; //typecast float to integer for 3rd digit |
captaintim | 2:3cf4eba9de56 | 97 | int temp4=temp3-temp3a*10; //gets last digit |
captaintim | 2:3cf4eba9de56 | 98 | int temp4a = temp4; //convenient renaming for writing digit to display |
captaintim | 2:3cf4eba9de56 | 99 | |
captaintim | 2:3cf4eba9de56 | 100 | //begin one write of the display by turning off all the digits |
captaintim | 1:46dbd77e0701 | 101 | Digit1 = 1; //turn off digit1 |
captaintim | 1:46dbd77e0701 | 102 | Digit2 = 1; //turn off digit2 |
captaintim | 1:46dbd77e0701 | 103 | Digit3 = 1; //turn off digit3 |
captaintim | 1:46dbd77e0701 | 104 | Digit4 = 1; //turn off digit4 |
captaintim | 3:c747b832518f | 105 | // while (1) { |
captaintim | 2:3cf4eba9de56 | 106 | //turns off last led's segments values |
captaintim | 1:46dbd77e0701 | 107 | for(int i = 0; i<8;i++){ |
captaintim | 2:3cf4eba9de56 | 108 | led[i] = 0;} |
captaintim | 2:3cf4eba9de56 | 109 | //belows holds row of matrix and assign column value from matrix |
captaintim | 2:3cf4eba9de56 | 110 | Digit1 = 0; //turns on digit1 |
captaintim | 2:3cf4eba9de56 | 111 | for (int i=0; i<8; i++){ |
captaintim | 2:3cf4eba9de56 | 112 | led[i] = matrix[temp1a][i]; |
captaintim | 2:3cf4eba9de56 | 113 | } |
captaintim | 2:3cf4eba9de56 | 114 | wait(f); |
captaintim | 2:3cf4eba9de56 | 115 | Digit1=1; |
ShingyoujiPai | 0:463ff11d33fa | 116 | |
captaintim | 2:3cf4eba9de56 | 117 | //turns off last led's segments values |
captaintim | 2:3cf4eba9de56 | 118 | for(int i = 0; i<8;i++){ |
captaintim | 2:3cf4eba9de56 | 119 | led[i] = 0;} |
captaintim | 2:3cf4eba9de56 | 120 | //belows holds row of matrix and assign column value from matrix |
captaintim | 2:3cf4eba9de56 | 121 | Digit2 = 0; //turns on digit2 with decimal |
captaintim | 1:46dbd77e0701 | 122 | for (int i=0; i<8; i++){ |
captaintim | 2:3cf4eba9de56 | 123 | //since we have prior knowledge of the decimal location |
captaintim | 2:3cf4eba9de56 | 124 | //and this is a demonstration program, we add the decimal for this digit |
captaintim | 2:3cf4eba9de56 | 125 | led[i] = matrixdecimal[temp2a][i]; |
captaintim | 2:3cf4eba9de56 | 126 | } |
captaintim | 2:3cf4eba9de56 | 127 | wait(f); |
captaintim | 2:3cf4eba9de56 | 128 | Digit2=1; |
captaintim | 2:3cf4eba9de56 | 129 | |
captaintim | 2:3cf4eba9de56 | 130 | //turns off last led's segments values |
captaintim | 2:3cf4eba9de56 | 131 | for(int i = 0; i<8;i++){ |
captaintim | 2:3cf4eba9de56 | 132 | led[i] = 0;} |
captaintim | 2:3cf4eba9de56 | 133 | //belows holds row of matrix and assign column value from matrix |
captaintim | 2:3cf4eba9de56 | 134 | Digit3 = 0; //turns on digit3 |
captaintim | 2:3cf4eba9de56 | 135 | for (int i=0; i<8; i++){ |
captaintim | 2:3cf4eba9de56 | 136 | led[i] = matrix[temp3a][i]; |
captaintim | 2:3cf4eba9de56 | 137 | } |
captaintim | 2:3cf4eba9de56 | 138 | wait(f); |
captaintim | 2:3cf4eba9de56 | 139 | Digit3=1; |
captaintim | 2:3cf4eba9de56 | 140 | |
captaintim | 2:3cf4eba9de56 | 141 | //turns off last led's segments values |
captaintim | 2:3cf4eba9de56 | 142 | for(int i = 0; i<8;i++){ |
captaintim | 2:3cf4eba9de56 | 143 | led[i] = 0;} |
captaintim | 2:3cf4eba9de56 | 144 | //belows holds row of matrix and assign column value from matrix |
captaintim | 2:3cf4eba9de56 | 145 | Digit4 = 0; //turns on digit4 |
captaintim | 2:3cf4eba9de56 | 146 | for (int i=0; i<8; i++){ |
captaintim | 3:c747b832518f | 147 | led[i] = matrix[temp4a][i]; |
captaintim | 3:c747b832518f | 148 | } |
captaintim | 2:3cf4eba9de56 | 149 | wait(f); |
captaintim | 2:3cf4eba9de56 | 150 | Digit4=1; |
captaintim | 2:3cf4eba9de56 | 151 | |
captaintim | 3:c747b832518f | 152 | //loop & increment |
captaintim | 3:c747b832518f | 153 | if (t <3600) |
captaintim | 3:c747b832518f | 154 | t=t+1; |
captaintim | 3:c747b832518f | 155 | else |
captaintim | 3:c747b832518f | 156 | t=3200; |
captaintim | 3:c747b832518f | 157 | |
captaintim | 3:c747b832518f | 158 | |
captaintim | 3:c747b832518f | 159 | } //close for while 1 |
captaintim | 3:c747b832518f | 160 | } //close for main |