Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 1000000L
- #include <avr/io.h>
- #include <util/delay.h>
- #define diody_0 (1<<PA0)
- #define diody_1 (1<<PA1)
- #define diody_2 (1<<PA2)
- #define diody_3 (1<<PA3)
- #define diody_4 (1<<PA4)
- #define diody_5 (1<<PA5)
- #define diody_6 (1<<PA6)
- #define diody_7 (1<<PA7)
- //tablica diod
- int diody[8] = {diody_0, diody_1, diody_2, diody_3,
- diody_4, diody_5, diody_6, diody_7};
- int main(void)
- {
- DDRA |= diody[0] | diody[1] | diody[2] | diody[3] |
- diody[4] | diody[5] | diody[6] | diody[7];
- //czas pomiędzy "przeskakiwaniem" diod
- int czas = 100;
- //przycisk SW_1
- DDRB &= ~(1<<PB0);
- PORTB |= (1<<PB0);
- //przycisk SW_2
- DDRB &= ~(1<<PB1);
- PORTB |= (1<<PB1);
- while(1)
- {
- //zmiana stanu diody (po wciśnięciu klawisza 1)
- if(!((PINB)&(1<<PB0)))
- {
- _delay_ms(50);
- //zmiana stanu PIN PA7
- PORTA ^= diody_7;
- //czy przycisk został puszczony
- while(!((PINB)&(1<<PB0)))
- {
- _delay_ms(50);
- }
- }
- //przycisk 2 - 2 diody
- if(!((PINB)&(1<<PB1)))
- {
- //czterokrotne wykonanie pętli
- for(int i=0; i<4; i++)
- {
- //dioda pierwsza
- for(int j=0; j<7; j++)
- {
- PORTA |= diody[j];
- _delay_ms(czas);
- }
- //dioda druga
- for(int j=1; j<8; j++)
- {
- PORTA &= ~(diody[j]);
- _delay_ms(czas);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement