Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Nom: compteur 32 bits
- * Copyright (C) 2005 Matthew Khouzam
- * License http://www.gnu.org/copyleft/gpl.html GNU/GPL
- * Description: Ceci est un exemple simple de programme
- * Version: 1.1
- */
- #define F_CPU 8000000
- #include <util/delay.h>
- #include <avr/io.h>
- enum Etat {Init, ON1, OFF1, ON2, OFF2, ON3};
- bool boutonVerifier();
- int main ()
- {
- DDRA = 0xff; // PORT A est en mode sortie
- DDRB = 0xff; // PORT B est en mode sortie
- DDRC = 0xff; // PORT C est en mode sortie
- DDRD = 0x00; // PORT D est en mode sortie et
- Etat etat = Init;
- for(;;){
- etat = Init;
- switch (etat)
- {
- case Init : {
- PORTB = 0x01;
- do{
- if (boutonVerifier)
- {
- etat = ON1;
- }
- }while (!(PIND & 0x04));
- }
- case ON1 : {
- do
- {
- PORTB = 0x01;
- _delay_ms (3);
- PORTB = 0x02;
- _delay_ms (1);
- }while(PIND & 0x04);
- etat = OFF1;
- }
- case OFF1 : {
- do
- {
- PORTB = 0x02;
- }while (!(PIND & 0x04));
- etat = ON2;
- }
- case ON2 : {
- if (boutonVerifier)
- {
- do
- {
- PORTB = 0x01;
- }while(PIND & 0x04);
- etat = OFF2;
- }
- }
- case OFF2 : {
- do
- {
- PORTB = 0x00;
- }while (!(PIND & 0x04));
- etat = ON3;
- }
- case ON3 : {
- if (boutonVerifier)
- {
- do
- {
- PORTB = 0x02;;
- }while(PIND & 0x04);
- }
- break;
- }
- }
- }
- return 0;
- }
- bool boutonVerifier()
- {
- bool verifier = false;
- if (PIND & 0x04)
- {
- _delay_ms (10);
- if (PIND & 0x04 )
- {
- verifier = true;
- }
- }
- return verifier;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement