Horloge rotative a LED

Fermé
alinoz2017 Messages postés 1 Date d'inscription samedi 25 novembre 2017 Statut Membre Dernière intervention 25 novembre 2017 - 25 nov. 2017 à 19:59
Bonjour Chers membres,
Je suis présentement entrain de travailler sur mon projet qui est une horloge à leds rotatives et j'éprouve des difficultés pour programmer les leds .
il ya au total 60 leds qui representent des secondes.
mon probleme est de faire afficher un metronome avec 32 leds. C'est un multiplexage de 8 leds, j'utilise 4 lignes et 8 colonnes. Chaque ligne partge les memes 8 colonnes.
voici mon code ci-dessous
Merci de votre aide



#include <asf.h>
#include "conf_example.h"
#include <time.h>
int set_anodes(uint32_t); // déclaration des prototypes pour anodes et pour l'emplissement de l,ecran
void blanck(void);
void init_mes_pins(void);

//noms des entrées du signal par ligne et définition des pins
#define LIGNE_1 PIN_PA07
#define LIGNE_2 PIN_PA08
#define LIGNE_3 PIN_PA09
#define LIGNE_4 PIN_PA10
#define LIGNE_5 PIN_PA11
#define LIGNE_6 PIN_PA12
#define LIGNE_7 PIN_PA13
#define LIGNE_8 PIN_PA14


//noms des entrées du signal par colonne et définition des pins6
#define COLONNE_1 PIN_PB04
#define COLONNE_2 PIN_PB05
#define COLONNE_3 PIN_PB06
#define COLONNE_4 PIN_PB07
#define COLONNE_5 PIN_PB08
#define COLONNE_6 PIN_PB09
#define COLONNE_7 PIN_PB10
#define COLONNE_8 PIN_PB11


/*noms des entrées du signal à la gachette des drivers niveau bas
de l'afficheur sept segment et définition des pins*/
#define DRIVER_LOW_1 PIN_PB00
#define DRIVER_LOW_2 PIN_PB01
#define DRIVER_LOW_3 PIN_PB02
#define DRIVER_LOW_4 PIN_PB03


/*noms des entrées du signal à la gachtette des drivers niveau
haut de l'afficheur sept segment et définition des pins*/
#define DRIVER_HIGH_SIDE_A PIN_PA15
#define DRIVER_HIGH_SIDE_B PIN_PA16
#define DRIVER_HIGH_SIDE_C PIN_PA17
#define DRIVER_HIGH_SIDE_D PIN_PA18
#define DRIVER_HIGH_SIDE_E PIN_PA19
#define DRIVER_HIGH_SIDE_F PIN_PA20
#define DRIVER_HIGH_SIDE_G PIN_PA21
#define DRIVER_HIGH_SIDE_DP PIN_PA22

//noms des boutons utilisateurs et la correspondance des commutateurs
#define USER_BUTTON_1 SW1
#define USER_BUTTON_2 SW2
#define USER_BUTTON_3 SW3


//noms des commutateurs et définitions des pins
#define SW1 PIN_PC24
#define SW2 PIN_PC00
#define SW3 PIN_PC01


#define NOMBRE_DE_DIGITS 4
#define ESPACE 10
#define TEMPS_REP 250

bool affichage_actif= false; //variable permettant de faire afficher les caracteres sur le display
int digit_actif=0; // cette variable donne l'etat d'un segment qui est soit allume ou eteint

volatile int digits[NOMBRE_DE_DIGITS];

/* Global ul_ms_ticks in milliseconds since start of application */
volatile uint32_t ul_ms_ticks = 0;

int volatile minutes= 0;
int volatile heure=0;
int volatile temps_presse=0;
bool volatile changements; //variable qui indique qu'un changement a eu lieu sur l'affichage
bool volatile rotation = 0;
//bool volatile oscillation= 32;
bool volatile phase;


void init_mes_pins(){

/* Set output direction on the given LED IOPORTs */

/*Initialisation de la direction des drivers sur les lignes */
ioport_set_pin_dir(LIGNE_1, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LIGNE_2, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LIGNE_3, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LIGNE_4, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LIGNE_5, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LIGNE_6, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LIGNE_7, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(LIGNE_8, IOPORT_DIR_OUTPUT);

/*Initialisation de la direction des drivers sur les colonnes */
ioport_set_pin_dir(COLONNE_1, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(COLONNE_2, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(COLONNE_3, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(COLONNE_4, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(COLONNE_5, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(COLONNE_6, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(COLONNE_7, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(COLONNE_8, IOPORT_DIR_OUTPUT);

/*Initialisation de la direction des drivers sur l'afficheur 7 segments */
ioport_set_pin_dir(DRIVER_HIGH_SIDE_A, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_HIGH_SIDE_B, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_HIGH_SIDE_C, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_HIGH_SIDE_D, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_HIGH_SIDE_E, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_HIGH_SIDE_F, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_HIGH_SIDE_G, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_HIGH_SIDE_DP, IOPORT_DIR_OUTPUT);

/*Initialisation de la direction des drivers sur l'afficheur 7 segments */
ioport_set_pin_dir(DRIVER_LOW_1, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_LOW_2, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_LOW_3, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(DRIVER_LOW_4, IOPORT_DIR_OUTPUT);

/* Set direction and pullup on the given button IOPORT */
/*Initialisation de des commandes des butons*/
ioport_set_pin_dir(SW1, IOPORT_DIR_INPUT);
ioport_set_pin_dir(SW2, IOPORT_DIR_INPUT);
ioport_set_pin_dir(SW3, IOPORT_DIR_INPUT);

ioport_set_pin_mode(SW1, IOPORT_MODE_PULLUP);
ioport_set_pin_mode(SW2, IOPORT_MODE_PULLUP);
ioport_set_pin_mode(SW3, IOPORT_MODE_PULLUP);

/*Initialisation du niveau des drivers de l'afficheur 7 segments */
ioport_set_pin_level(DRIVER_HIGH_SIDE_A, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(DRIVER_HIGH_SIDE_B, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(DRIVER_HIGH_SIDE_C, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(DRIVER_HIGH_SIDE_D, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(DRIVER_HIGH_SIDE_E, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(DRIVER_HIGH_SIDE_F, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(DRIVER_HIGH_SIDE_G, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(DRIVER_HIGH_SIDE_DP, IOPORT_PIN_LEVEL_HIGH);

/*Initialisation de la direction des drivers sur l'afficheur 7 segments */

ioport_set_pin_level(DRIVER_LOW_1, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(DRIVER_LOW_2, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(DRIVER_LOW_3, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(DRIVER_LOW_4, IOPORT_PIN_LEVEL_LOW);

/*Initialisation du niveau des drivers sur les lignes tous éteints*/
ioport_set_pin_level(LIGNE_1, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(LIGNE_2, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(LIGNE_3, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(LIGNE_4, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(LIGNE_5, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(LIGNE_6, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(LIGNE_7, IOPORT_PIN_LEVEL_HIGH);
ioport_set_pin_level(LIGNE_8, IOPORT_PIN_LEVEL_HIGH);

/*Initialisation du niveau des drivers sur les colonnes tous éteints*/
ioport_set_pin_level(COLONNE_1, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_2, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_3, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_4, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_5, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_6, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_7, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_8, IOPORT_PIN_LEVEL_LOW);
}


void SysTick_Handler(void)
{
ul_ms_ticks++;
changements=0;
if(!(ioport_get_pin_level(SW1)) && (ul_ms_ticks-temps_presse)>TEMPS_REP){
minutes++;
changements=1;
temps_presse=ul_ms_ticks;
}

if(!(ioport_get_pin_level(SW2)) && (ul_ms_ticks-temps_presse)>TEMPS_REP){
heure++;
changements=1;
temps_presse=ul_ms_ticks;
}


if((ioport_get_pin_level(SW3)) && (ul_ms_ticks-temps_presse)>TEMPS_REP){
rotation=0;
temps_presse=ul_ms_ticks;
}

else if(!(ioport_get_pin_level(SW3)) && (ul_ms_ticks-temps_presse)>TEMPS_REP){
rotation=1;
temps_presse=ul_ms_ticks;
}




//if(!(ul_ms_ticks%10)){
// ioport_set_pin_level(LIGNE_2, IOPORT_PIN_LEVEL_LOW);
// ioport_set_pin_level(COLONNE_1, IOPORT_PIN_LEVEL_HIGH);
// ioport_set_pin_level(COLONNE_2, IOPORT_PIN_LEVEL_HIGH);
// }
//if(!((ul_ms_ticks+2)%10)){
// ioport_set_pin_level(LIGNE_2, IOPORT_PIN_LEVEL_HIGH);
// ioport_set_pin_level(COLONNE_1, IOPORT_PIN_LEVEL_LOW);
//}



if(affichage_actif && ul_ms_ticks%2){ // 500hz si le tick est regle a 1000hz et seulement si c'est actif

switch(digit_actif){
case 0:
ioport_set_pin_level(DRIVER_LOW_1, IOPORT_PIN_LEVEL_LOW); //etat ferme des drivers
break;
case 1:
ioport_set_pin_level(DRIVER_LOW_2, IOPORT_PIN_LEVEL_LOW);
break;
case 2:
ioport_set_pin_level(DRIVER_LOW_3, IOPORT_PIN_LEVEL_LOW);
break;
case 3:
ioport_set_pin_level(DRIVER_LOW_4, IOPORT_PIN_LEVEL_LOW);
break;
default:
//on a un vrai probleme
//blanck();
break;
}
digit_actif++;
if(digit_actif>=NOMBRE_DE_DIGITS)
digit_actif=0;
set_anodes(digits[digit_actif]);


switch(digit_actif){
case 0:
ioport_set_pin_level(DRIVER_LOW_1, IOPORT_PIN_LEVEL_HIGH); //etat ouvert des drivers
break;
case 1:
ioport_set_pin_level(DRIVER_LOW_2, IOPORT_PIN_LEVEL_HIGH);
break;
case 2:
ioport_set_pin_level(DRIVER_LOW_3, IOPORT_PIN_LEVEL_HIGH);
break;
case 3:
ioport_set_pin_level(DRIVER_LOW_4, IOPORT_PIN_LEVEL_HIGH);
break;
default:
//on a un vrai probleme
// blanck();
break;
}


}

if(changements){

digits[1]=minutes%100/10; //affiche les minutes de 10 a 59
digits[0]=minutes%10; //affiche les minutes de 0 a 9
digits[2]=heure%10; //affiche les heure de 0 a 9
digits[3]=heure/10; //affiche les heure de 10 a 23


}


}

//Fonction qui constituant les chiffres qui seront affiche sur le display
int set_anodes(uint32_t le_chiffre)
{
int anodes[16][8]={0,0,0,0,0,0,1,1, // 0 zero
1,0,0,1,1,1,1,1, // 1 un
0,0,1,0,0,1,0,1, // 2 deux
0,0,0,0,1,1,0,1, // 3 trois
1,0,0,1,1,0,0,1, // 4 quatre
0,1,0,0,1,0,0,1, // 5 cinq
0,1,0,0,0,0,0,1, // 6 six
0,0,0,1,1,1,1,1, // 7 sept
0,0,0,0,0,0,0,1, // 8 huit
0,0,0,0,1,0,0,1, // 9 neuf
1,1,1,1,1,1,1,1, // 10 espace
};

if(le_chiffre<0 || le_chiffre >10)
return 1; // le code 1 signifie qu'on demande un chiffre inexistant

ioport_set_pin_level(DRIVER_HIGH_SIDE_A,anodes[le_chiffre][0]);
ioport_set_pin_level(DRIVER_HIGH_SIDE_B,anodes[le_chiffre][1]);
ioport_set_pin_level(DRIVER_HIGH_SIDE_C,anodes[le_chiffre][2]);
ioport_set_pin_level(DRIVER_HIGH_SIDE_D,anodes[le_chiffre][3]);
ioport_set_pin_level(DRIVER_HIGH_SIDE_E,anodes[le_chiffre][4]);
ioport_set_pin_level(DRIVER_HIGH_SIDE_F,anodes[le_chiffre][5]);
ioport_set_pin_level(DRIVER_HIGH_SIDE_G,anodes[le_chiffre][6]);
ioport_set_pin_level(DRIVER_HIGH_SIDE_DP,anodes[le_chiffre][7]);

return 0;

}



/* fonction qui emplit la memoire de l'ecran de caracteres blanc (pas d'affichage)*/
void blanck(void){
int i;
for(i=0;i<4;i++)
digits[i]=ESPACE;
}


static void mdelay(uint32_t ul_dly_ticks)
{
uint32_t ul_cur_ticks;

ul_cur_ticks = ul_ms_ticks;
while ((ul_ms_ticks - ul_cur_ticks) < ul_dly_ticks) {
}
}


int main(void)
{
int nled;
int nline=0;
int ncolone=0;
sysclk_init();
board_init();
ioport_init();
init_mes_pins();


// Setup SysTick Timer for 1 usec interrupts
//---->>> mdelay(1) = 1 micro seconde
if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
while (1) { /* Capture error */
}
}


affichage_actif=true;


//la grande boucle qui se repette continuellement
while (1)
{

//if(!(rotation))
//{
//
////boucle qui fait le balayage de tous les LEDs qui seront allumees et eteintes , affichage
for (nled=0;nled<4;nled++)
{
digits[1]=minutes%100/10; //affiche les minutes de 10 a 59
digits[0]=minutes%10; //affiche les minutes de 0 a 9
digits[2]=heure%10; //affiche les heure de 0 a 9
digits[3]=heure/10; //affiche les heure de 10 a 23

minutes++;

//Boucle qui s'occupe de faire le balayage des 8 lignes


for(nline=0;nline<30;nline++){


ioport_set_pin_level(LIGNE_6, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_5, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_4, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_3, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_1, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_2, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_3, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_4, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_5, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_6, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_7, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_8, IOPORT_PIN_LEVEL_LOW);
//mdelay(100);

ioport_set_pin_level(LIGNE_6, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_5, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_4, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_3, IOPORT_PIN_LEVEL_LOW);

ioport_set_pin_level(COLONNE_8, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_7, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_6, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_5, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_4, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_3, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_2, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_1, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);

ioport_set_pin_level(LIGNE_6, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_5, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_4, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_3, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_1, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_2, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_3, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_4, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_5, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_6, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_7, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(COLONNE_8, IOPORT_PIN_LEVEL_LOW);
//mdelay(100);

ioport_set_pin_level(LIGNE_3, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_4, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_5, IOPORT_PIN_LEVEL_LOW);
ioport_set_pin_level(LIGNE_6, IOPORT_PIN_LEVEL_LOW);

ioport_set_pin_level(COLONNE_1, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_2, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_3, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_4, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_5, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_6, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_7, IOPORT_PIN_LEVEL_HIGH);
mdelay(100);
ioport_set_pin_level(COLONNE_8, IOPORT_PIN_LEVEL_HIGH);
//mdelay(100);

}
mdelay(1000);

// minutes egal 60
if (minutes==60)
{
minutes=0;
heure++;
}

//heure egal a 24 donc 1 journee
if (heure>23)
{
minutes=0;
heure=0;
}


}


}
}