FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups  Galerie PhotosGalerie Photos   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

BP et instruction switch



 
Post new topic   Reply to topic    forums.jelectronique.com Forum Index -> WinAVR-AVR GCC WinAVR-AVR GCC
View previous topic :: View next topic  
Author Message
Omsi
Guest





PostPosted: 21 Mar 2008 14:11    Post subject: BP et instruction switch BP et instruction switch Reply with quote

bonsoir,bonjour
eh oui encore moi,cette fois ci je veux faire le prog suivant:
je pousse une fois sur BP=>la led clignote 5 fois,je pousse deux fois sur BP=>10 fois
et je pousse trois fois sur Bp=> 20 fois
voilà l debut de mon code,j'aimerai un peu d'aide cette fois ci et merci d'avance Cool
Code:

#include <avr/io.h>
#include <avr/interrupt.h>

enum etat_led { IDLE,etat_5,etat_10,etat_20 };

volatile unsigned char etat_led, prev_etat_led,BP,count;


int main(void)
{
   DDRD |= (0 << PD2); //PD2 as input(INTO)
   DDRB |= (1 << PB0); //PB0 as output(led)
   PORTD |= (1 << PD2); //Pull-up on PD2
   
   MCUCR |= ((1 << ISC01) | (1 << ISC11)); //downfront 1/0
   GICR |= (1 << INT0); //enable INT0
   TCCR1A |= ((1 << COM1A1) | (1 << COM1A1)); //CTCmode TIM1 channel A
   TCCR1B |= ((1 << WGM12) | (1 << CS12)); //prescaler 256 & CTCmode
   OCR1A = 19531.25; //Compare value @ 0,5s for 10MHZ
   TIMSK |= ((1 << OCIE1A) | (1 << TOIE1)); //enable ovf & output compare A
   sei();
}

ISR(INT0_vect)
{

}

ISR(TIMER1_COMPA_vect)
{
   
   switch (etat_led)
   {
      case IDLE:
      

      break;
      
      case etat_5:
      
         
         count=5;
         if(count!=0)
         {
            PORTB ^=(1 << PB0);
            count--;
      
         }
         
      
      break;
      
      
      case etat_10:
   
      
         
         
      
      break;
      case etat_20:
      
      break;
      default:
      
      break;
      
   }
   
}
Back to top
Omsi
Guest





PostPosted: 25 Mar 2008 16:27    Post subject: BP et instruction switch RE Reply with quote

salut tout le monde,pour la suite de mon code,j'ai réussi à faire fonctionner le BP appuyé une seule fois seulement ,la seconde fois il ne se passe rien,donc j'apprécierai votre aide s'il vous plait.
Voici mon code non-fini:
Code:

#include <avr/io.h>
#include <avr/interrupt.h>

enum etat_led { IDLE,init_etat_5,etat_5,init_etat_10,etat_10,init_etat_20,etat_20 };

volatile unsigned char BP,count=0;


int main(void)
{

   DDRD |= (0 << PD2); //PD2 as input(INTO)
   DDRB |= (1 << PB0); //PB0 as output(led)
   PORTD |= (1 << PD2); //Pull-up on PD2
   
   MCUCR |= ((1 << ISC01) | (1 << ISC11)); //front descendant 1/0
   GICR |= (1 << INT0); //enable INT0
   TCCR1A |= ((1 << COM1A1) | (1 << COM1A1)); //CTCmode TIM1 channel A
   TCCR1B |= ((1 << WGM12) | (1 << CS12)); //prescaler 256 & CTCmode
   TIMSK |= ((1 << OCIE1A) | (1 << TOIE1)); //enable ovf & output compare A
   OCR1A = 19531.25; //Compare value @ 0,5s for 10MHZ
   sei();
   while(1);
   
}

ISR(INT0_vect)
{
      BP++;
   if(BP==3)
   {
      BP=0;
   }

   
}

ISR(TIMER1_COMPA_vect)
{
   switch (BP)
   {
      case IDLE:
         break;
      
      case etat_5:
         if(BP==1)
         {
            if(count<=10)
            {
               PORTB ^=(1 << PB0);
               count++;
            }
         }   
         break;
         BP=1;
         count=0;
      
      case etat_10:
         if(BP==2)
         {
            if(count<=20)
            {
               PORTB ^=(1 << PB0);
               count++;
            }
         }   
         break;
         BP=2;
         count=0;
      
      
      
   }
   
}

Back to top
Omsi
Guest





PostPosted: 26 Mar 2008 9:22    Post subject: BP et instruction switch Reply with quote

PS:
Il n'y a aucune erreur à corriger pour votre information,il me faut juste quelques idées pour l'aboutissement de ce code .
Merci.
Back to top
Omsi
Guest





PostPosted: 28 Mar 2008 13:34    Post subject: BP et instruction switch Hihi Reply with quote

bonjour,bonsoir
ben voilà comme d'habitude je fini par y arriver seul, donc le code est fini si quelqu'un est interessé faites moi signe (h)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    forums.jelectronique.com Forum Index -> WinAVR-AVR GCC All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group