Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:95172f59262a
- Parent:
- 0:531f33a2550d
- Child:
- 2:447ff720dee3
--- a/main.cpp Sat Jan 12 00:43:50 2019 +0000
+++ b/main.cpp Tue Jan 15 15:55:11 2019 +0000
@@ -1,11 +1,12 @@
/*************************************/
-// YNCREA ISEN CSI3
-// Electronique Numérique
+// YNCREA ISEN Nîmes
+// CSI3 Electronique Numérique
//
// Cours : Systèmes à microcontrôleur
// Prof : Frédéric Giamarchi
//
-// Exo 2.2 : Clignotemment de plusieurs Dels
+// Date : 15 janv 2019
+// Test TP 01 : Controle de 8 Dels par 2 Boutons poussoir
/*************************************/
#include "mbed.h"
@@ -18,7 +19,12 @@
DigitalOut L6(PB_14);
DigitalOut L7(PB_15);
-uint8_t L[8] = {L0, L1, L2, L3, L4, L5, L6, L7};
+DigitalIn BTN3(PC_6);
+DigitalIn BTN4(PC_5);
+
+//DigitalOut BZ(PC_7);
+
+//uint8_t L[8] = {L0, L1, L2, L3, L4, L5, L6, L7};
void set_8Dels(uint8_t position)
{
@@ -30,31 +36,110 @@
L5 = position & 0x20;
L6 = position & 0x40;
L7 = position & 0x80;
-
-// L[!position] = 0;
-// L[position] = 1;
}
-uint8_t compteur = 1;
-uint8_t sens = 0;
-
+uint8_t ptr_3 = 0;
+uint8_t ptr_4 = 0;
+uint8_t pointeur = 1;
+uint8_t compteur = 0;
+uint8_t etat_del = 0;
+/***********************************************/
+// Fonction Appui_BTN3
+// Renvoie l'état actif ou relaché du bouton poussoir BTN3
+uint8_t Appui_BTN3(void)
+{
+uint8_t etat_BTN3 = 0; // variable état BTN3 à 0 par défaut
+
+ if(!BTN3) // Test appui sur BTN3
+ {
+ wait(0.2); // tempo d'anti rebond
+ etat_BTN3 = 1; // variable à 1
+ }
+ return etat_BTN3; // La fonction renvoie la valeur 0 ou 1
+}
+/***********************************************/
+// Fonction Appui_BTN4
+// Renvoie l'état actif ou relaché du bouton poussoir BTN4
+uint8_t Appui_BTN4(void)
+{
+uint8_t etat_BTN4 = 0;
+
+ if(!BTN4)
+ {
+ wait(0.2);
+ etat_BTN4 = 1;
+ }
+ return etat_BTN4;
+}
+/***********************************************/
int main()
-{
+{
while(1)
{
- wait(0.2); // 200 ms
- if(!sens)
+/******** Question 1 ****************/
+/*
+ L0 = Appui_BTN3(); // Contrôle L0 par BTN3
+*/
+/******** Question 2 ****************/
+/*
+ if(Appui_BTN3())
{
- compteur<<=1; // décalage d'un bit vers la gauche
- if(compteur == 0x80)
- sens = 1;
+ pointeur <<=1; // Décalage vers la gauche
+ if(pointeur == 0) // Test Limite gauche
+ pointeur = 0x80; // Blocage
+ set_8Dels(pointeur); // Affichage
+ }
+*/
+/******** Question 3 ****************/
+/*
+ if(Appui_BTN4())
+ {
+ pointeur >>=1; // Décalage vers la droite
+ if(pointeur == 0) // Test Limite droite
+ pointeur = 1; // Blocage
+ set_8Dels(pointeur);
+ }
+*/
+/******** Question 4 ****************/
+
+ wait_ms(10); // Execution toutes les 10 ms
+ compteur++; // Incrémente un compteur temps
+
+ if(Appui_BTN3())
+ {
+ ptr_3++; // incrémente un pointeur
+ compteur = 0; // RAZ compteur temps
}
- else
+/******** Question 5 ****************/
+
+ if(Appui_BTN4())
+ {
+ ptr_4++;
+ compteur = 0;
+ }
+/******** Question 4 et 5 ****************/
+
+ if(compteur == 100) // Est-ce que cela fait 1 sec
{
- compteur>>=1; // décalage d'un bit vers la droite
- if(compteur == 0x01)
- sens = 0;
- }
- set_8Dels(compteur);
- }
-}
\ No newline at end of file
+ if(ptr_3 != 0) // Test pointeur 3 -> Question 4
+ {
+ // Masque OU logique avec etat_Del
+ // Le masque est un décalage vers la gauche d'un 1 logique
+ // Le nombre de décalage est défini par le pointeur
+ etat_del = etat_del | 1<<(ptr_3 - 1);
+ ptr_3 = 0; // Pointeur à 0
+ }
+ if(ptr_4 != 0) // Test pointeur 4 -> Question 5
+ // Masque ET logique avec etat_Del
+ // Le masque est un décalage vers la gauche d'un 1 logique
+ // Le nombre de décalage est défini par le pointeur
+ // Ensuite le résultat du masque est inversé
+ etat_del = etat_del & ~(1<<ptr_4 - 1);
+ ptr_4 = 0;
+
+ set_8Dels(etat_del);
+ }
+/***********************************************/
+ } // Fin du while(1)
+} // Fin du main()
+/***********************************************/
\ No newline at end of file