SE4Binome2024-5
Aller à la navigation
Aller à la recherche
git : https://gitea.plil.fr/ktouron/se4-djadja-touron_pico.git
Carte fille clavier "matrice de touches"
Hardware
Reçu carte vierge
Carte après soudure des composants
Software
Allumage de LEDS sur Programmateur AVR
Avant de programmer directement sur le shield, nous avons allumé des LED pour tester la carte.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(1, HIGH);
digitalWrite(4, HIGH);
digitalWrite(7, HIGH);
digitalWrite(A0, HIGH);
digitalWrite(A3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(1, LOW);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
digitalWrite(A0, LOW);
digitalWrite(A3, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Objectifs ordonnanceur 7 oct.
Allumer la LED broche PB5 avec Timer1 ISR
#define CTC1 WGM12 // Meilleur nom pour le bit
#define PERIODE 20
void init_minuteur(int diviseur,long periode){
TCCR1A=0; // Le mode choisi n'utilise pas ce registre
TCCR1B=(1<<CTC1); // Réinitialisation du minuteur sur expiration
switch(diviseur){
case 8: TCCR1B |= (1<<CS11); break;
case 64: TCCR1B |= (1<<CS11 | 11<<CS10); break;
case 256: TCCR1B |= (1<<CS12); break;
case 1024: TCCR1B |= (1<<CS12 | 1<<CS10); break;
}
// Un cycle prend 1/F_CPU secondes.
// Un pas de compteur prend diviseur/F_CPU secondes.
// Pour une periode en millisecondes, il faut (periode/1000)/(diviseur/F_CPU) pas
// soit (periode*F_CPU)/(1000*diviseur)
OCR1A=F_CPU/1000*periode/diviseur; // Calcul du pas
TCNT1=0; // Compteur initialisé
TIMSK1=(1<<OCIE1A); // Comparaison du compteur avec OCR1A
}
ISR(TIMER1_COMPA_vect/*, ISR_NAKED*/) // Procédure d'interruption
{
PORTB ^= (1 << PB5);
}
int main(void){
DDRB |= (1 << PB5);
init_minuteur(256,PERIODE);
sei();
while(1);
}
Macros de sauvegarde et restauration des registres
#define portSAVE_REGISTERS() \
asm volatile ( \
"push r0 \n\t" \
"in r0, __SREG__ \n\t"\
"cli \n\t" \
"push r0 \n\t"\
"push r1 \n\t" \
"clr r1 \n\t" \
"push r2 \n\t"\
"push r3 \n\t"\
"push r4 \n\t"\
"push r5 \n\t"\
"push r6 \n\t"\
"push r7 \n\t"\
"push r8 \n\t"\
"push r9 \n\t"\
"push r10 \n\t"\
"push r11 \n\t"\
"push r12 \n\t"\
"push r13 \n\t"\
"push r14 \n\t"\
"push r15 \n\t"\
"push r16 \n\t"\
"push r17 \n\t" \
"push r18 \n\t"\
"push r19 \n\t"\
"push r20 \n\t" \
"push r21 \n\t"\
"push r22 \n\t"\
"push r23 \n\t"\
"push r24 \n\t"\
"push r25 \n\t"\
"push r26 \n\t"\
"push r27 \n\t"\
"push r28 \n\t"\
"push r29 \n\t"\
"push r30 \n\t"\
"push r31 \n\t"\
);
#define portRESTORE_REGISTERS() \
asm volatile (\
"pop r31 \n\t" \
"pop r30 \n\t"\
"pop r29 \n\t" \
"pop r28 \n\t" \
"pop r27 \n\t" \
"pop r26 \n\t" \
"pop r25 \n\t"\
"pop r24 \n\t" \
"pop r23 \n\t" \
"pop r22 \n\t" \
"pop r21 \n\t" \
"pop r20 \n\t" \
"pop r19 \n\t" \
"pop r18 \n\t" \
"pop r17 \n\t" \
"pop r16 \n\t" \
"pop r15 \n\t" \
"pop r14 \n\t" \
"pop r13 \n\t" \
"pop r12 \n\t" \
"pop r11 \n\t" \
"pop r10 \n\t"\
"pop r9 \n\t" \
"pop r8 \n\t" \
"pop r7 \n\t" \
"pop r6 \n\t" \
"pop r5 \n\t" \
"pop r4 \n\t" \
"pop r3 \n\t" \
"pop r2 \n\t" \
"pop r1 \n\t" \
"pop r0 \n\t" \
"out __SREG__, r0 \n\t"\
"pop r0 \n\t" \
);
Coder le tableau des structures des processus
typedef struct {
uint16_t adresseDepart; //adresse de la fonction de départ
uint16_t adressePile; //adresse de la pile d'exécution
bool etat; //état du processus (1 ou 0)
} Process;
Process table_process[MAXPROCESS];