Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * main.c
- *
- * Created on: 26-05-2013
- * Author: miszczo
- */
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #include <avr/pgmspace.h>
- #include <avr/eeprom.h>
- #define TIME 10
- #define FRTIME 200
- #define UP 1
- #define DOWN 0
- #define RED 2
- #define BLUE 0
- #define GREEN 1
- volatile uint8_t kolory[4];
- volatile uint8_t mode;
- void normal_sequence(void);
- void random_sequence(void);
- uint32_t get_random(void);
- void full_rand_seq(void);
- void bright (uint8_t kolor );
- const uint8_t pwm_val[256] PROGMEM = {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6,
- 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12,
- 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 19, 19, 20, 20,
- 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34,
- 35, 36, 37, 38, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 59,
- 60, 61, 63, 64, 65, 67, 68, 70, 71, 73, 75, 76, 78, 80, 82, 83, 85, 87, 89, 91, 93, 95, 97, 100,
- 102, 104, 106, 109, 111, 114, 116, 119, 122, 124, 127, 130, 133, 136, 139, 142, 145, 148, 152,
- 155, 158, 162, 166, 169, 173, 177, 181, 185, 189, 193, 197, 202, 206, 211, 216, 220, 225, 230,
- 236, 241, 246, 255, 255};
- int main(void)
- {
- // wybór kanału dla adc ADC3 = PB3
- ADMUX = (1<<MUX0) | (1<<MUX1);
- PORTB = 0x00;
- // 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();
- while(1)
- {
- mode = 2;
- if(mode == 0) full_rand_seq();
- else if(mode == 1) normal_sequence();
- else if(mode == 2) random_sequence();
- //normal_sequence();
- }
- }
- /**************tutaj będzie migac jak pojebana************************/
- void full_rand_seq(void)
- {
- uint32_t a;
- a = get_random();
- kolory[0] = a;
- kolory[1] = (a>>8);
- kolory[2] = (a>>16);
- _delay_ms(FRTIME);
- }
- /***********tu bedzie losowo w góre i w dol************************/
- void random_sequence(void)
- {
- uint8_t y;
- y = get_random();
- if(((y & 0x01) == 0) && (kolory[0] > 0)) kolory[0]--;
- if(((y & 0x01) == 1) && (kolory[0] < 255)) kolory[0]++;
- if((((y>>2) & 0x01) == 0) && (kolory[1] > 0)) kolory[1]--;
- if((((y>>2) & 0x01) == 1) && (kolory[1] < 255)) kolory[1]++;
- if((((y>>4) & 0x01) == 0) && (kolory[2] > 0)) kolory[2]--;
- if((((y>>4) & 0x01) == 1) && (kolory[2] < 255)) kolory[2]++;
- _delay_ms(TIME);
- }
- void second_random(void)
- {
- uint8_t a;
- a = get_random();
- }
- void normal_sequence(void)
- {
- kolory[0] = 0;
- kolory[1] = 0;
- kolory[2] = 0;
- bright(BLUE);
- bright(GREEN);
- bright(BLUE);
- bright(RED);
- bright(BLUE);
- bright(GREEN);
- bright(BLUE);
- bright(RED);
- }
- void bright(uint8_t kolor)
- {
- int z;
- if(kolory[kolor] == 0)
- {
- for(z = 0; z<255; z++)
- {
- kolory[kolor] = pgm_read_byte(&pwm_val[z]);
- _delay_ms(TIME);
- }
- }
- else if(kolory[kolor] == 255)
- {
- for(z = 0; z<255; z++)
- {
- kolory[kolor] = pgm_read_byte(&pwm_val[255-z]);
- _delay_ms(TIME);
- }
- }
- }
- uint32_t get_random(void)
- {
- uint32_t wartosc = 0 ;
- uint8_t i;
- for(i = 0;i<24;i++)
- {
- //ustawienia adc, adc enable , preskaler 64 , start conversion
- ADCSRA = (1<<ADEN) | (1<<ADPS0) | (1<<ADPS1) | (1<<ADSC);
- while(ADCSRA&(1<<ADSC)); //wait for end conversion
- wartosc = (wartosc<<1);
- wartosc |= (ADCW & 0x01);
- }
- return wartosc;
- }
- ISR ( TIM0_OVF_vect )
- {
- static uint8_t licznik;
- if(licznik>=kolory[0]) PORTB |= (1<<PB0); else PORTB &= ~(1<<PB0);
- if(licznik>=kolory[1]) PORTB |= (1<<PB1); else PORTB &= ~(1<<PB1);
- if(licznik>=kolory[2]) PORTB |= (1<<PB2); else PORTB &= ~(1<<PB2);
- licznik++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement