Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * main.c
- *
- * Created on: 01-04-2013
- * 15:05:56
- * Author: miszczo
- */
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #define TIME 10
- volatile uint8_t R = 0;
- volatile uint8_t G = 0;
- volatile uint8_t B = 0;
- int main(void)
- {
- //wyłączenie komparatora
- ADCSRB |= (1<<ACME);
- // wyłączenie adc;
- PRR |= (1<<PRADC);
- // ustawienia portow
- DDRB |= (1<<PB0) | (1<<PB1) | (1<<PB2) ;
- //konfiguracja timera
- TCCR0B |= (1<<CS00); //preskaler 1
- TIMSK0 |= (1<<TOIE0); //zezwolenie na przerwanie przy przepelnieniu
- sei();
- char kanter = 1;
- while(1)
- {
- char i;
- for(i=0;i<255;i++)
- {
- if(kanter == 1)
- {
- //R = 0
- //G = 0
- B = i;
- }
- if(kanter == 2)
- {
- //R = 0
- G = i;
- //B = 255
- }
- if(kanter == 3)
- {
- //R = 0
- //G =255
- B = 255 - i;
- }
- if(kanter == 4)
- {
- R = i;
- //G = 255
- //B = 0
- }
- if(kanter == 5)
- {
- //R = 255
- //G = 255
- B = i;
- }
- if(kanter == 6)
- {
- //R = 255
- G = 255-i;
- //B = 255
- }
- if(kanter == 7)
- {
- //R = 255
- //G = 0
- B = 255-i;
- }
- if(kanter == 8)
- {
- R = 255-i;
- //G = 0
- //B = 0
- }
- _delay_ms(TIME);
- }
- kanter++;
- if(kanter == 9) kanter = 1;
- }
- }
- ISR ( TIM0_OVF_vect )
- {
- static uint8_t licznik;
- if(licznik>=R) PORTB |= (1<<PB0); else PORTB &= ~(1<<PB0);
- if(licznik>=G) PORTB |= (1<<PB1); else PORTB &= ~(1<<PB1);
- if(licznik>=B) PORTB |= (1<<PB2); else PORTB &= ~(1<<PB2);
- licznik++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement