CLIGNOTEMENT LED : main.
C
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/cfg/global.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <driverlib.h>
/* Board Header file */
#include "main.h"
//********************************************************
// Prototype de fonction
//********************************************************
void Init_GPIO(void);
void Blink_GREEN(UArg arg0, UArg arg1);
void Blink_RED(UArg arg0, UArg arg1);
//********************************************************
/*
* ======== main ========
*/
//********************************************************
int main(void)
{
WDT_A_hold(WDT_A_BASE); //Stop WDT
PM5CTL0 &= ~LOCKLPM5;
Init_GPIO();
/* Start BIOS */
BIOS_start();
return (0);
}
//********************************************************
// Init GPIO
//********************************************************
void Init_GPIO(void)
{
// PORT1
GPIO_setAsOutputPin(GPIO_PORT_P1, LED_ROUGE);
GPIO_setOutputLowOnPin(GPIO_PORT_P1, LED_ROUGE);
// PORT9
GPIO_setAsOutputPin(GPIO_PORT_P9, LED_VERTE);
GPIO_setOutputLowOnPin(GPIO_PORT_P9, LED_VERTE);
}
//********************************************************
// Mise à jour de la fonction de clignotement pour la LED verte
//********************************************************
void Blink_GREEN(UArg arg0, UArg arg1)
{
while (1)
{
Task_sleep(300); // 0,3 seconde
GPIO_toggleOutputOnPin(GPIO_PORT_P9, LED_VERTE);
}
}
//********************************************************
// Mise à jour de la fonction de clignotement pour la LED rouge
//********************************************************
void Blink_RED(UArg arg0, UArg arg1)
{
while (1)
{
Task_sleep(500); // 0,5 seconde
GPIO_toggleOutputOnPin(GPIO_PORT_P1, LED_ROUGE);
}
}
main.h
#ifndef MAIN_H_
#define MAIN_H_
// PORT1
#define LED_ROUGE GPIO_PIN0
// PORT9
#define LED_VERTE GPIO_PIN7
#endif /* MAIN_H_ */
AFFICHAGE TEXTE EXAMEN 2022
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/cfg/global.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include "main.h"
void Display_Text(void);
int main(void)
{
WDT_A_hold(WDT_A_BASE); // Stop WDT
PM5CTL0 &= ~LOCKLPM5;
Display_Text(); // Appel de la fonction d'affichage
/* Start BIOS */
BIOS_start();
return (0);
}
void Display_Text(void)
{
while (1)
{
System_printf("EXAMEN 2022\n");
System_flush();
Task_sleep(1000); // Attente de 1 seconde entre les affichages
}
}
Main.h
#ifndef MAIN_H_
#define MAIN_H_
#endif /* MAIN_H_ */
BOU• Avec BTN1 -> à chaque appui, Basculer en mode: heure -> température -> affichage
<< SYSTEM RTOS » -> Possibilité d'entrer un texte Gauche -> Possibilité d'entrer un texte
Droit. (5 pts)
• Avec BTN2 -> En mode température, affichage de la
température en Celsius <-> Fahrenheit (5 pts)
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/cfg/global.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <driverlib.h>
#include "main.h"
#define BTN1_PRESSED (P1IN & BIT1) == 0
#define BTN2_PRESSED (P1IN & BIT2) == 0
enum Mode
{
MODE_HEURE,
MODE_TEMPERATURE,
MODE_SYSTEM_RTOS,
MODE_TEXTE_GAUCHE,
MODE_TEXTE_DROIT
};
enum Mode modeActuel = MODE_HEURE; // Mode initial
void Init_GPIO(void);
void Display_Text(void);
void Process_Input(void);
int main(void)
{
WDT_A_hold(WDT_A_BASE); // Stop WDT
PM5CTL0 &= ~LOCKLPM5;
Init_GPIO();
Display_Text(); // Appel de la fonction d'affichage
BIOS_start();
return (0);
}
void Init_GPIO(void)
{
// Initialisation des broches des boutons (assurez-vous que les broches sont correctes pour
votre carte)
GPIO_setAsInputPin(GPIO_PORT_P1, BTN1 | BTN2);
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, BTN1 | BTN2);
}
void Display_Text(void)
{
while (1)
{
System_printf("Mode actuel: ");
switch (modeActuel)
{
case MODE_HEURE:
System_printf("Heure\n");
break;
case MODE_TEMPERATURE:
System_printf("Température\n");
break;
case MODE_SYSTEM_RTOS:
System_printf("SYSTEM RTOS\n");
break;
case MODE_TEXTE_GAUCHE:
System_printf("Texte Gauche\n");
// Ajoutez ici la logique pour saisir le texte à gauche
break;
case MODE_TEXTE_DROIT:
System_printf("Texte Droit\n");
// Ajoutez ici la logique pour saisir le texte à droite
break;
default:
System_printf("Inconnu\n");
break;
}
System_flush();
Process_Input(); // Gérer les entrées des boutons
Task_sleep(1000); // Attente de 1 seconde entre les affichages
}
}
void Process_Input(void)
{
if (BTN1_PRESSED)
{
// Bouton 1 appuyé, changer de mode
modeActuel = (modeActuel + 1) % 5; // Il y a 5 modes
while (BTN1_PRESSED)
{
// Attendre que le bouton soit relâché
}
}
// Si vous avez un moyen de lire les entrées des boutons Gauche et Droit
// Vous pouvez gérer l'entrée ici et effectuer des actions en fonction du modeActuel
if (BTN2_PRESSED)
{
// Bouton 2 appuyé
switch (modeActuel)
{
case MODE_TEMPERATURE:
// Afficher la température en Celsius ou Fahrenheit
// Ajoutez ici la logique pour afficher la température
break;
default:
// Les autres modes ne nécessitent pas d'action pour BTN2
break;
}
while (BTN2_PRESSED)
{
// Attendre que le bouton soit relâché
}
}
}
Avec BTN2 -> En mode TEXTE, à chaque appui sur BTN2 -> affichage du texte : <<
INPUT1 » caractère par caractère vers la DROITE. (2.5 pts)
• Avec BTN2 -> En mode TEXTE, à chaque appui sur BTN2 -> affichage du texte : <<
INPUT1 » caractère par caractère vers la GAUCHE. (2.5 pts)
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/cfg/global.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <driverlib.h>
#include "main.h"
#define BTN1_PRESSED (P1IN & BIT1) == 0
#define BTN2_PRESSED (P1IN & BIT2) == 0
enum Mode
{
MODE_HEURE,
MODE_TEMPERATURE,
MODE_SYSTEM_RTOS,
MODE_TEXTE_GAUCHE,
MODE_TEXTE_DROIT
};
enum Mode modeActuel = MODE_HEURE; // Mode initial
char texteGauche[20] = "INPUT1"; // Texte initial à gauche
int positionCurseur = 0; // Position du curseur dans le texte
void Init_GPIO(void);
void Display_Text(void);
void Process_Input(void);
int main(void)
{
WDT_A_hold(WDT_A_BASE); // Stop WDT
PM5CTL0 &= ~LOCKLPM5;
Init_GPIO();
Display_Text(); // Appel de la fonction d'affichage
BIOS_start();
return (0);
}
void Init_GPIO(void)
{
// Initialisation des broches des boutons (assurez-vous que les broches sont correctes pour
votre carte)
GPIO_setAsInputPin(GPIO_PORT_P1, BTN1 | BTN2);
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, BTN1 | BTN2);
}
void Display_Text(void)
{
while (1)
{
System_printf("Mode actuel: ");
switch (modeActuel)
{
case MODE_HEURE:
System_printf("Heure\n");
break;
case MODE_TEMPERATURE:
System_printf("Température\n");
break;
case MODE_SYSTEM_RTOS:
System_printf("SYSTEM RTOS\n");
break;
case MODE_TEXTE_GAUCHE:
System_printf("Texte Gauche: %s\n", texteGauche);
break;
case MODE_TEXTE_DROIT:
System_printf("Texte Droit\n");
break;
default:
System_printf("Inconnu\n");
break;
}
System_flush();
Process_Input(); // Gérer les entrées des boutons
Task_sleep(1000); // Attente de 1 seconde entre les affichages
}
}
void Process_Input(void)
{
if (BTN1_PRESSED)
{
// Bouton 1 appuyé, changer de mode
modeActuel = (modeActuel + 1) % 5; // Il y a 5 modes
positionCurseur = 0; // Réinitialiser la position du curseur
while (BTN1_PRESSED)
{
// Attendre que le bouton soit relâché
}
}
if (BTN2_PRESSED)
{
switch (modeActuel)
{
case MODE_TEXTE_GAUCHE:
// Bouton 2 appuyé en mode TEXTE_GAUCHE
System_printf("Caractère ajouté vers la DROITE\n");
// Ajouter un caractère vers la DROITE dans le texteGauche
texteGauche[positionCurseur] = 'X'; // Remplacez 'X' par le caractère que vous
souhaitez ajouter
positionCurseur = (positionCurseur + 1) % (sizeof(texteGauche) - 1); // Boucler la
position du curseur
break;
case MODE_TEXTE_DROIT:
// Bouton 2 appuyé en mode TEXTE_DROIT
System_printf("Caractère ajouté vers la GAUCHE\n");
// Ajouter un caractère vers la GAUCHE dans le texteDroit (si nécessaire)
// Ajouter la logique nécessaire pour ajouter un caractère vers la GAUCHE dans le
texteDroit
break;
default:
// Les autres modes ne nécessitent pas d'action pour BTN2
break;
}
while (BTN2_PRESSED)
{
// Attendre que le bouton soit relâché
}
}
}
.h :
#ifndef MAIN_H_
#define MAIN_H_
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/* Définition des broches pour les LED et les boutons (à ajuster selon votre configuration) */
#define LED_ROUGE GPIO_PIN0
#define LED_VERTE GPIO_PIN7
#define BTN1 GPIO_PIN1
#define BTN2 GPIO_PIN2
/* Fonctions pour l'initialisation et l'affichage du texte */
void Init_GPIO(void);
void Display_Text(void);
void Process_Input(void);
#endif /* MAIN_H_ */