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