7-Segment Display Driver class, via an 8-bit shift register (such as the 74HC595)
Fork of 7SegSRDriver by
7SegSRDriver.cpp@2:c3d7b44e116f, 2017-06-06 (annotated)
- Committer:
- sefyou
- Date:
- Tue Jun 06 13:28:42 2017 +0000
- Revision:
- 2:c3d7b44e116f
- Parent:
- 0:1832d0ed8da8
yo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
paul80nd | 0:1832d0ed8da8 | 1 | #include "mbed.h" |
paul80nd | 0:1832d0ed8da8 | 2 | #include "7SegSRDriver.h" |
paul80nd | 0:1832d0ed8da8 | 3 | |
sefyou | 2:c3d7b44e116f | 4 | /*********************************************** CHRONOMETRE ****************************************************************/ |
sefyou | 2:c3d7b44e116f | 5 | SSegSRDriver_chronometre::SSegSRDriver_chronometre(PinName srData, PinName srClock, PinName srLatch, bool disp_type): _srData(srData), _srClock(srClock), _srLatch(srLatch) { |
paul80nd | 0:1832d0ed8da8 | 6 | _disp_type = disp_type; |
sefyou | 2:c3d7b44e116f | 7 | bus_chronometre_1(0); |
sefyou | 2:c3d7b44e116f | 8 | bus_chronometre_2(0); |
sefyou | 2:c3d7b44e116f | 9 | bus_chronometre_3(0); |
sefyou | 2:c3d7b44e116f | 10 | bus_chronometre_4(0); |
paul80nd | 0:1832d0ed8da8 | 11 | } |
paul80nd | 0:1832d0ed8da8 | 12 | |
sefyou | 2:c3d7b44e116f | 13 | void SSegSRDriver_chronometre::clear() { |
sefyou | 2:c3d7b44e116f | 14 | bus_chronometre_1(0); |
sefyou | 2:c3d7b44e116f | 15 | bus_chronometre_2(0); |
sefyou | 2:c3d7b44e116f | 16 | bus_chronometre_3(0); |
sefyou | 2:c3d7b44e116f | 17 | bus_chronometre_4(0); |
paul80nd | 0:1832d0ed8da8 | 18 | } |
paul80nd | 0:1832d0ed8da8 | 19 | |
sefyou | 2:c3d7b44e116f | 20 | void SSegSRDriver_chronometre::write_chronometre(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 21 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 22 | bus_chronometre_1((nbr_envoye[number] << 1) | dp); |
paul80nd | 0:1832d0ed8da8 | 23 | } |
paul80nd | 0:1832d0ed8da8 | 24 | } |
paul80nd | 0:1832d0ed8da8 | 25 | |
sefyou | 2:c3d7b44e116f | 26 | void SSegSRDriver_chronometre::write_chronometre_2(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 27 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 28 | bus_chronometre_2((nbr_envoye_2[number] << 1) | dp); |
sefyou | 2:c3d7b44e116f | 29 | } |
sefyou | 2:c3d7b44e116f | 30 | } |
paul80nd | 0:1832d0ed8da8 | 31 | |
sefyou | 2:c3d7b44e116f | 32 | void SSegSRDriver_chronometre::write_chronometre_3(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 33 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 34 | bus_chronometre_3((nbr_envoye_3[number] << 1) | dp); |
sefyou | 2:c3d7b44e116f | 35 | } |
sefyou | 2:c3d7b44e116f | 36 | } |
paul80nd | 0:1832d0ed8da8 | 37 | |
sefyou | 2:c3d7b44e116f | 38 | void SSegSRDriver_chronometre::write_chronometre_4(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 39 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 40 | bus_chronometre_3((nbr_envoye_4[number] << 1) | dp); |
sefyou | 2:c3d7b44e116f | 41 | } |
sefyou | 2:c3d7b44e116f | 42 | } |
sefyou | 2:c3d7b44e116f | 43 | |
sefyou | 2:c3d7b44e116f | 44 | void SSegSRDriver_chronometre::bus_chronometre_1(unsigned char Val) { // Val= les segments a éclairer |
sefyou | 2:c3d7b44e116f | 45 | |
sefyou | 2:c3d7b44e116f | 46 | if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
paul80nd | 0:1832d0ed8da8 | 47 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 48 | for (int i=7;i>=0;i--) { // on parcours l'octet |
paul80nd | 0:1832d0ed8da8 | 49 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 50 | _srData = (Val & (1<<i)); //décoposition de l'octet en bit |
paul80nd | 0:1832d0ed8da8 | 51 | _srClock = 1; |
paul80nd | 0:1832d0ed8da8 | 52 | } |
paul80nd | 0:1832d0ed8da8 | 53 | _srLatch = 1; |
paul80nd | 0:1832d0ed8da8 | 54 | _srData = 0; |
paul80nd | 0:1832d0ed8da8 | 55 | } |
sefyou | 2:c3d7b44e116f | 56 | |
sefyou | 2:c3d7b44e116f | 57 | } |
sefyou | 2:c3d7b44e116f | 58 | |
sefyou | 2:c3d7b44e116f | 59 | void SSegSRDriver_chronometre::bus_chronometre_2(unsigned char Value) |
sefyou | 2:c3d7b44e116f | 60 | { |
sefyou | 2:c3d7b44e116f | 61 | |
sefyou | 2:c3d7b44e116f | 62 | if (Value<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
sefyou | 2:c3d7b44e116f | 63 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 64 | for (int i=7;i>=0;i--) // on parcours l'octet |
sefyou | 2:c3d7b44e116f | 65 | { |
sefyou | 2:c3d7b44e116f | 66 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 67 | _srData = (Value & (1<<i)); //décoposition de l'octet |
sefyou | 2:c3d7b44e116f | 68 | _srClock = 1; |
sefyou | 2:c3d7b44e116f | 69 | } |
sefyou | 2:c3d7b44e116f | 70 | _srLatch = 1; |
sefyou | 2:c3d7b44e116f | 71 | _srData = 0; |
sefyou | 2:c3d7b44e116f | 72 | } |
sefyou | 2:c3d7b44e116f | 73 | } |
sefyou | 2:c3d7b44e116f | 74 | |
sefyou | 2:c3d7b44e116f | 75 | void SSegSRDriver_chronometre::bus_chronometre_3(unsigned char Value) |
sefyou | 2:c3d7b44e116f | 76 | { |
sefyou | 2:c3d7b44e116f | 77 | |
sefyou | 2:c3d7b44e116f | 78 | if (Value<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
sefyou | 2:c3d7b44e116f | 79 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 80 | for (int i=7;i>=0;i--) // on parcours l'octet |
sefyou | 2:c3d7b44e116f | 81 | { |
sefyou | 2:c3d7b44e116f | 82 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 83 | _srData = (Value & (1<<i)); //décoposition de l'octet |
sefyou | 2:c3d7b44e116f | 84 | _srClock = 1; |
sefyou | 2:c3d7b44e116f | 85 | } |
sefyou | 2:c3d7b44e116f | 86 | _srLatch = 1; |
sefyou | 2:c3d7b44e116f | 87 | _srData = 0; |
sefyou | 2:c3d7b44e116f | 88 | } |
sefyou | 2:c3d7b44e116f | 89 | } |
sefyou | 2:c3d7b44e116f | 90 | |
sefyou | 2:c3d7b44e116f | 91 | void SSegSRDriver_chronometre::bus_chronometre_4(unsigned char Value) |
sefyou | 2:c3d7b44e116f | 92 | { |
sefyou | 2:c3d7b44e116f | 93 | |
sefyou | 2:c3d7b44e116f | 94 | if (Value<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
sefyou | 2:c3d7b44e116f | 95 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 96 | for (int i=7;i>=0;i--) // on parcours l'octet |
sefyou | 2:c3d7b44e116f | 97 | { |
sefyou | 2:c3d7b44e116f | 98 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 99 | _srData = (Value & (1<<i)); //décoposition de l'octet |
sefyou | 2:c3d7b44e116f | 100 | _srClock = 1; |
sefyou | 2:c3d7b44e116f | 101 | } |
sefyou | 2:c3d7b44e116f | 102 | _srLatch = 1; |
sefyou | 2:c3d7b44e116f | 103 | _srData = 0; |
sefyou | 2:c3d7b44e116f | 104 | } |
sefyou | 2:c3d7b44e116f | 105 | } |
sefyou | 2:c3d7b44e116f | 106 | |
sefyou | 2:c3d7b44e116f | 107 | |
sefyou | 2:c3d7b44e116f | 108 | /*********************************************** DOMICILE ****************************************************************/ |
sefyou | 2:c3d7b44e116f | 109 | |
sefyou | 2:c3d7b44e116f | 110 | SSegSRDriver_domicile::SSegSRDriver_domicile(PinName srData, PinName srClock, PinName srLatch, bool disp_type): _srData(srData), _srClock(srClock), _srLatch(srLatch) { |
sefyou | 2:c3d7b44e116f | 111 | _disp_type = disp_type; |
sefyou | 2:c3d7b44e116f | 112 | bus_domicile_1(0); |
sefyou | 2:c3d7b44e116f | 113 | bus_domicile_2(0); |
sefyou | 2:c3d7b44e116f | 114 | bus_domicile_3(0); |
sefyou | 2:c3d7b44e116f | 115 | } |
sefyou | 2:c3d7b44e116f | 116 | |
sefyou | 2:c3d7b44e116f | 117 | void SSegSRDriver_domicile::clear() { |
sefyou | 2:c3d7b44e116f | 118 | bus_domicile_1(0); |
sefyou | 2:c3d7b44e116f | 119 | bus_domicile_2(0); |
sefyou | 2:c3d7b44e116f | 120 | bus_domicile_3(0); |
sefyou | 2:c3d7b44e116f | 121 | } |
sefyou | 2:c3d7b44e116f | 122 | |
sefyou | 2:c3d7b44e116f | 123 | void SSegSRDriver_domicile::write_domicile(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 124 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 125 | bus_domicile_1((nbr_envoye[number] << 1) | dp); |
sefyou | 2:c3d7b44e116f | 126 | } |
sefyou | 2:c3d7b44e116f | 127 | } |
sefyou | 2:c3d7b44e116f | 128 | |
sefyou | 2:c3d7b44e116f | 129 | void SSegSRDriver_domicile::write_domicile_2(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 130 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 131 | bus_domicile_2((nbr_envoye_2[number] << 1) | dp); |
sefyou | 2:c3d7b44e116f | 132 | } |
sefyou | 2:c3d7b44e116f | 133 | } |
sefyou | 2:c3d7b44e116f | 134 | |
sefyou | 2:c3d7b44e116f | 135 | void SSegSRDriver_domicile::write_domicile_3(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 136 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 137 | bus_domicile_3((nbr_envoye_3[number] << 1) | dp); |
sefyou | 2:c3d7b44e116f | 138 | } |
sefyou | 2:c3d7b44e116f | 139 | } |
sefyou | 2:c3d7b44e116f | 140 | |
sefyou | 2:c3d7b44e116f | 141 | void SSegSRDriver_domicile::bus_domicile_1(unsigned char Val) { // Val= les segments a éclairer |
sefyou | 2:c3d7b44e116f | 142 | |
sefyou | 2:c3d7b44e116f | 143 | if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
sefyou | 2:c3d7b44e116f | 144 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 145 | for (int i=7;i>=0;i--) { // on parcours l'octet |
sefyou | 2:c3d7b44e116f | 146 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 147 | _srData = (Val & (1<<i)); //décoposition de l'octet en bit |
sefyou | 2:c3d7b44e116f | 148 | _srClock = 1; |
sefyou | 2:c3d7b44e116f | 149 | } |
sefyou | 2:c3d7b44e116f | 150 | _srLatch = 1; |
sefyou | 2:c3d7b44e116f | 151 | _srData = 0; |
sefyou | 2:c3d7b44e116f | 152 | } |
sefyou | 2:c3d7b44e116f | 153 | |
sefyou | 2:c3d7b44e116f | 154 | } |
sefyou | 2:c3d7b44e116f | 155 | |
sefyou | 2:c3d7b44e116f | 156 | void SSegSRDriver_domicile::bus_domicile_2(unsigned char Val) { // Val= les segments a éclairer |
sefyou | 2:c3d7b44e116f | 157 | |
sefyou | 2:c3d7b44e116f | 158 | if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
sefyou | 2:c3d7b44e116f | 159 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 160 | for (int i=7;i>=0;i--) { // on parcours l'octet |
sefyou | 2:c3d7b44e116f | 161 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 162 | _srData = (Val & (1<<i)); //décoposition de l'octet en bit |
sefyou | 2:c3d7b44e116f | 163 | _srClock = 1; |
sefyou | 2:c3d7b44e116f | 164 | } |
sefyou | 2:c3d7b44e116f | 165 | _srLatch = 1; |
sefyou | 2:c3d7b44e116f | 166 | _srData = 0; |
sefyou | 2:c3d7b44e116f | 167 | } |
sefyou | 2:c3d7b44e116f | 168 | |
sefyou | 2:c3d7b44e116f | 169 | } |
sefyou | 2:c3d7b44e116f | 170 | |
sefyou | 2:c3d7b44e116f | 171 | void SSegSRDriver_domicile::bus_domicile_3(unsigned char Val) { // Val= les segments a éclairer |
sefyou | 2:c3d7b44e116f | 172 | |
sefyou | 2:c3d7b44e116f | 173 | if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
sefyou | 2:c3d7b44e116f | 174 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 175 | for (int i=7;i>=0;i--) { // on parcours l'octet |
sefyou | 2:c3d7b44e116f | 176 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 177 | _srData = (Val & (1<<i)); //décoposition de l'octet en bit |
sefyou | 2:c3d7b44e116f | 178 | _srClock = 1; |
sefyou | 2:c3d7b44e116f | 179 | } |
sefyou | 2:c3d7b44e116f | 180 | _srLatch = 1; |
sefyou | 2:c3d7b44e116f | 181 | _srData = 0; |
sefyou | 2:c3d7b44e116f | 182 | } |
sefyou | 2:c3d7b44e116f | 183 | |
sefyou | 2:c3d7b44e116f | 184 | } |
sefyou | 2:c3d7b44e116f | 185 | |
sefyou | 2:c3d7b44e116f | 186 | |
sefyou | 2:c3d7b44e116f | 187 | /*********************************************** VISITEUR ****************************************************************/ |
sefyou | 2:c3d7b44e116f | 188 | |
sefyou | 2:c3d7b44e116f | 189 | SSegSRDriver_visiteur::SSegSRDriver_visiteur(PinName srData, PinName srClock, PinName srLatch, bool disp_type): _srData(srData), _srClock(srClock), _srLatch(srLatch) { |
sefyou | 2:c3d7b44e116f | 190 | _disp_type = disp_type; |
sefyou | 2:c3d7b44e116f | 191 | bus_visiteur_1(0); |
sefyou | 2:c3d7b44e116f | 192 | bus_visiteur_2(0); |
sefyou | 2:c3d7b44e116f | 193 | bus_visiteur_3(0); |
sefyou | 2:c3d7b44e116f | 194 | } |
sefyou | 2:c3d7b44e116f | 195 | |
sefyou | 2:c3d7b44e116f | 196 | void SSegSRDriver_visiteur::clear() { |
sefyou | 2:c3d7b44e116f | 197 | bus_visiteur_1(0); |
sefyou | 2:c3d7b44e116f | 198 | bus_visiteur_2(0); |
sefyou | 2:c3d7b44e116f | 199 | bus_visiteur_3(0); |
sefyou | 2:c3d7b44e116f | 200 | } |
sefyou | 2:c3d7b44e116f | 201 | |
sefyou | 2:c3d7b44e116f | 202 | void SSegSRDriver_visiteur::write_visiteur(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 203 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 204 | bus_visiteur_1((nbr_envoye[number] << 1) | dp); |
sefyou | 2:c3d7b44e116f | 205 | } |
sefyou | 2:c3d7b44e116f | 206 | } |
sefyou | 2:c3d7b44e116f | 207 | |
sefyou | 2:c3d7b44e116f | 208 | void SSegSRDriver_visiteur::write_visiteur_2(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 209 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 210 | bus_visiteur_2((nbr_envoye_2[number] << 1) | dp); |
sefyou | 2:c3d7b44e116f | 211 | } |
sefyou | 2:c3d7b44e116f | 212 | } |
sefyou | 2:c3d7b44e116f | 213 | |
sefyou | 2:c3d7b44e116f | 214 | void SSegSRDriver_visiteur::write_visiteur_3(unsigned char number, bool dp) { |
sefyou | 2:c3d7b44e116f | 215 | if (number<10) { |
sefyou | 2:c3d7b44e116f | 216 | bus_visiteur_3((nbr_envoye_3[number] << 1) | dp); |
sefyou | 2:c3d7b44e116f | 217 | } |
sefyou | 2:c3d7b44e116f | 218 | } |
sefyou | 2:c3d7b44e116f | 219 | |
sefyou | 2:c3d7b44e116f | 220 | void SSegSRDriver_visiteur::bus_visiteur_1(unsigned char Val) { // Val= les segments a éclairer |
sefyou | 2:c3d7b44e116f | 221 | |
sefyou | 2:c3d7b44e116f | 222 | if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
sefyou | 2:c3d7b44e116f | 223 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 224 | for (int i=7;i>=0;i--) { // on parcours l'octet |
sefyou | 2:c3d7b44e116f | 225 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 226 | _srData = (Val & (1<<i)); //décoposition de l'octet en bit |
sefyou | 2:c3d7b44e116f | 227 | _srClock = 1; |
sefyou | 2:c3d7b44e116f | 228 | } |
sefyou | 2:c3d7b44e116f | 229 | _srLatch = 1; |
sefyou | 2:c3d7b44e116f | 230 | _srData = 0; |
sefyou | 2:c3d7b44e116f | 231 | } |
sefyou | 2:c3d7b44e116f | 232 | |
sefyou | 2:c3d7b44e116f | 233 | } |
sefyou | 2:c3d7b44e116f | 234 | |
sefyou | 2:c3d7b44e116f | 235 | void SSegSRDriver_visiteur::bus_visiteur_2(unsigned char Val) { // Val= les segments a éclairer |
sefyou | 2:c3d7b44e116f | 236 | |
sefyou | 2:c3d7b44e116f | 237 | if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
sefyou | 2:c3d7b44e116f | 238 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 239 | for (int i=7;i>=0;i--) { // on parcours l'octet |
sefyou | 2:c3d7b44e116f | 240 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 241 | _srData = (Val & (1<<i)); //décoposition de l'octet en bit |
sefyou | 2:c3d7b44e116f | 242 | _srClock = 1; |
sefyou | 2:c3d7b44e116f | 243 | } |
sefyou | 2:c3d7b44e116f | 244 | _srLatch = 1; |
sefyou | 2:c3d7b44e116f | 245 | _srData = 0; |
sefyou | 2:c3d7b44e116f | 246 | } |
sefyou | 2:c3d7b44e116f | 247 | |
sefyou | 2:c3d7b44e116f | 248 | } |
sefyou | 2:c3d7b44e116f | 249 | |
sefyou | 2:c3d7b44e116f | 250 | void SSegSRDriver_visiteur::bus_visiteur_3(unsigned char Val) { // Val= les segments a éclairer |
sefyou | 2:c3d7b44e116f | 251 | |
sefyou | 2:c3d7b44e116f | 252 | if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 |
sefyou | 2:c3d7b44e116f | 253 | _srLatch = 0; |
sefyou | 2:c3d7b44e116f | 254 | for (int i=7;i>=0;i--) { // on parcours l'octet |
sefyou | 2:c3d7b44e116f | 255 | _srClock = 0; |
sefyou | 2:c3d7b44e116f | 256 | _srData = (Val & (1<<i)); //décoposition de l'octet en bit |
sefyou | 2:c3d7b44e116f | 257 | _srClock = 1; |
sefyou | 2:c3d7b44e116f | 258 | } |
sefyou | 2:c3d7b44e116f | 259 | _srLatch = 1; |
sefyou | 2:c3d7b44e116f | 260 | _srData = 0; |
sefyou | 2:c3d7b44e116f | 261 | } |
sefyou | 2:c3d7b44e116f | 262 | |
sefyou | 2:c3d7b44e116f | 263 | } |
sefyou | 2:c3d7b44e116f | 264 |