Advertisement
Guest User

Embedded Systems (Betty)

a guest
Oct 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <avr/io.h>
  2. #define F_CPU 8000000UL
  3. #include <util/delay.h>
  4. #include <avr/interrupt.h>
  5.  
  6. uint16_t i = 0,j = 0, n = 0;
  7.  
  8. ISR(INT0_vect){
  9.         PORTB = 0x00;
  10.     for(j = 0; j < 2; j++){
  11.         _delay_ms(500);
  12.         PORTB ^=  0xff;//(1<<PORTB1) | (1<<PORTB2) |(1<<PORTB3) ;
  13.         _delay_ms(500);
  14.     }
  15. }
  16.  
  17. int main(void)
  18. {
  19.     DDRB = 0xFF;
  20.     EIMSK = 0x01;
  21.     EICRA = 0x02;
  22.     sei();
  23.     ADCSRA = (1 << ADEN) | (1 << ADIE) | (0 << ADPS0) | (1 << ADPS1) | (1 << ADPS2) | (1 << ADSC);
  24.     ADMUX = (1 << ADLAR) ;
  25.     while(1)
  26.     {      
  27.         TCCR1A = 0x00;
  28.         TCCR1B = 0x00;
  29.         TCCR2A = 0x00;
  30.         TCCR2B = 0x00;
  31.        
  32.        
  33.         if(n <= 127){
  34.             for(i = 0; i<2; i++){
  35.                 PORTB = 1<<PORTB1;
  36.                 _delay_ms(1000);
  37.                 PORTB = 1<<PORTB2;
  38.                 _delay_ms(1000);
  39.                 PORTB = 1<<PORTB3;
  40.                 _delay_ms(1000);
  41.             }
  42.         }
  43.         else{
  44.             for(i = 0; i<2; i++){
  45.                 PORTB = 1<<PORTB3;
  46.                 _delay_ms(1000);
  47.                 PORTB = 1<<PORTB2;
  48.                 _delay_ms(1000);
  49.                 PORTB = 1<<PORTB1;
  50.                 _delay_ms(1000);
  51.             }
  52.         }
  53.         TCCR1A = (1<<COM1A1) | (1<<COM1B1 ) | (1<<WGM10);
  54.         TCCR1B = (1<<WGM12) | (1 << CS10) ;    
  55.         TCCR2A = (1 << COM2A1) | (1 << WGM21) | (1 << WGM20);
  56.         TCCR2B = (1 << CS20);      
  57.         for(i=0;i<255;i++){
  58.             OCR1A = i;
  59.             OCR1B = i;
  60.             OCR2A = i;
  61.             _delay_ms(20);
  62.         }
  63.     }
  64. }
  65.  
  66. ISR(ADC_vect){
  67.     n = ADCH;
  68.     ADCSRA |= (1 << ADSC);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement