Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #define F_CPU 8000000UL
- #include <util/delay.h>
- #include <avr/interrupt.h>
- uint16_t i = 0,j = 0, n = 0;
- ISR(INT0_vect){
- PORTB = 0x00;
- for(j = 0; j < 2; j++){
- _delay_ms(500);
- PORTB ^= 0xff;//(1<<PORTB1) | (1<<PORTB2) |(1<<PORTB3) ;
- _delay_ms(500);
- }
- }
- int main(void)
- {
- DDRB = 0xFF;
- EIMSK = 0x01;
- EICRA = 0x02;
- sei();
- ADCSRA = (1 << ADEN) | (1 << ADIE) | (0 << ADPS0) | (1 << ADPS1) | (1 << ADPS2) | (1 << ADSC);
- ADMUX = (1 << ADLAR) ;
- while(1)
- {
- TCCR1A = 0x00;
- TCCR1B = 0x00;
- TCCR2A = 0x00;
- TCCR2B = 0x00;
- if(n <= 127){
- for(i = 0; i<2; i++){
- PORTB = 1<<PORTB1;
- _delay_ms(1000);
- PORTB = 1<<PORTB2;
- _delay_ms(1000);
- PORTB = 1<<PORTB3;
- _delay_ms(1000);
- }
- }
- else{
- for(i = 0; i<2; i++){
- PORTB = 1<<PORTB3;
- _delay_ms(1000);
- PORTB = 1<<PORTB2;
- _delay_ms(1000);
- PORTB = 1<<PORTB1;
- _delay_ms(1000);
- }
- }
- TCCR1A = (1<<COM1A1) | (1<<COM1B1 ) | (1<<WGM10);
- TCCR1B = (1<<WGM12) | (1 << CS10) ;
- TCCR2A = (1 << COM2A1) | (1 << WGM21) | (1 << WGM20);
- TCCR2B = (1 << CS20);
- for(i=0;i<255;i++){
- OCR1A = i;
- OCR1B = i;
- OCR2A = i;
- _delay_ms(20);
- }
- }
- }
- ISR(ADC_vect){
- n = ADCH;
- ADCSRA |= (1 << ADSC);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement