Skip to content

Instantly share code, notes, and snippets.

@ypelletier
Last active September 29, 2019 10:16
Troisième sketch pour tester le compteur 74LS193N: utiilsation des broches CO et BO pour être alertés lors d'un débordement.
/*
Troisième sketch pour tester le compteur 74LS193N: cette
fois, nous utilisons les broches CO et BO pour être alertés
lorsque le compteur retourne à zéro après avoir atteint sa limite.
Plus d'infos:
https://electroniqueamateur.blogspot.com/2019/06/etude-de-ci-le-compteur-binaire-74ls193.html
*/
// définition des broches utilisées
const int brocheQA = 2;
const int brocheQB = 3;
const int brocheQC = 4;
const int brocheQD = 5;
const int brocheUP = 6;
const int brocheDOWN = 7;
const int brocheLOAD = 8;
const int brocheA = 9;
const int brocheB = 10;
const int brocheC = 11;
const int brocheD = 12;
const int brocheCO = A0;
const int brocheBO = A1;
void setup() {
// deux sorties pour contrôler l'entrée du 74LS193
pinMode(brocheUP, OUTPUT);
digitalWrite(brocheUP, HIGH);
pinMode(brocheDOWN, OUTPUT);
digitalWrite(brocheDOWN, HIGH);
// 4 entrées pour lire les sorties du 74LS193.
pinMode(brocheQA, INPUT);
pinMode(brocheQB, INPUT);
pinMode(brocheQC, INPUT);
pinMode(brocheQD, INPUT);
// 5 entrées pour régler la valeur du compteur
pinMode(brocheLOAD, OUTPUT);
digitalWrite(brocheLOAD, HIGH);
pinMode(brocheA, OUTPUT);
pinMode(brocheB, OUTPUT);
pinMode(brocheC, OUTPUT);
pinMode(brocheD, OUTPUT);
// détection des débordements
pinMode(brocheBO, INPUT);
pinMode(brocheCO, INPUT);
// affichage au moniteur série
Serial.begin(9600);
Serial.println("Test du compteur SN74LS193N");
Serial.println("");
}
void loop() {
// on effectue 25 additions
Serial.println("25 sadditions");
for (int i = 0; i <= 24; i++) {
digitalWrite(brocheUP, LOW);
if (!digitalRead(brocheCO)) {
Serial.println("Ca deborde!");
}
digitalWrite(brocheUP, HIGH);
affichage();
delay(1000);
}
// on effectue 25 soustractions
Serial.println("25 soustractions");
for (int i = 0; i <= 24; i++) {
digitalWrite(brocheDOWN, LOW);
if (!digitalRead(brocheBO)) {
Serial.println("Ca deborde!");
}
digitalWrite(brocheDOWN, HIGH);
affichage();
delay(1000);
}
}
void affichage()
{
Serial.print("QD: ");
Serial.print(digitalRead(brocheQD));
Serial.print(" QC: ");
Serial.print(digitalRead(brocheQC));
Serial.print(" QB: ");
Serial.print(digitalRead(brocheQB));
Serial.print(" QA: ");
Serial.println(digitalRead(brocheQA));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment