Advertisement
Guest User

TP3 - Exercice 1.1

a guest
Jan 27th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1.    
  2.  
  3.     /*
  4.      * Nom: compteur 32 bits
  5.      * Copyright (C) 2005 Matthew Khouzam
  6.      * License http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7.      * Description: Ceci est un exemple simple de programme
  8.      * Version: 1.1
  9.      */
  10.     #define F_CPU 8000000
  11.     #include <util/delay.h>
  12.     #include <avr/io.h>
  13.     enum Etat {Init, ON1, OFF1, ON2, OFF2, ON3};
  14.     bool boutonVerifier();
  15.    
  16.     int main ()
  17.     {
  18.       DDRA = 0xff; // PORT A est en mode sortie
  19.       DDRB = 0xff; // PORT B est en mode sortie
  20.       DDRC = 0xff; // PORT C est en mode sortie
  21.       DDRD = 0x00; // PORT D est en mode sortie et
  22.       Etat etat = Init;
  23.      
  24.      for(;;){
  25.          etat = Init;
  26.             switch (etat)
  27.             {
  28.            
  29.                 case Init : {
  30.                     PORTB = 0x01;
  31.                     do{
  32.                         if (boutonVerifier)
  33.                         {
  34.                             etat = ON1;
  35.                         }
  36.                     }while (!(PIND & 0x04));
  37.                 }
  38.                
  39.                 case ON1 : {
  40.                     do
  41.                         {
  42.                             PORTB = 0x01;
  43.                             _delay_ms (3);
  44.                             PORTB = 0x02;
  45.                              _delay_ms (1);
  46.                         }while(PIND & 0x04);
  47.                      etat = OFF1;
  48.                    
  49.                 }
  50.                    
  51.                 case OFF1 : {
  52.                     do
  53.                     {
  54.                         PORTB = 0x02;
  55.                     }while (!(PIND & 0x04));
  56.                     etat = ON2;
  57.                 }
  58.                    
  59.                    
  60.                 case ON2 : {
  61.                     if (boutonVerifier)
  62.                     {
  63.                         do
  64.                         {
  65.                             PORTB = 0x01;
  66.                         }while(PIND & 0x04);
  67.                         etat = OFF2;
  68.                     }
  69.                 }
  70.                    
  71.                 case OFF2 : {
  72.                     do
  73.                     {
  74.                         PORTB = 0x00;
  75.                     }while (!(PIND & 0x04));
  76.                     etat = ON3;
  77.                 }
  78.                    
  79.                    
  80.                 case ON3 : {
  81.                     if (boutonVerifier)
  82.                     {
  83.                         do
  84.                         {
  85.                             PORTB = 0x02;;
  86.                         }while(PIND & 0x04);
  87.                     }
  88.                     break;
  89.                 }
  90.             }
  91.         }
  92.                    
  93.     return 0;
  94.     }
  95.  
  96. bool boutonVerifier()
  97. {
  98.     bool verifier = false;
  99.     if (PIND & 0x04)
  100.         {  
  101.  
  102.             _delay_ms (10);
  103.             if (PIND & 0x04 )
  104.             {
  105.                 verifier = true;
  106.             }
  107.         }
  108.     return verifier;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement