Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- // *** Primitive wait() ***
- void wait(uint16_t time)
- {
- volatile uint16_t i;
- for(i=0;i<2000;i++)
- _delay_loop_2(time);
- }
- int main(void)
- {
- volatile uint8_t i;
- DDRB = 0xFF; // suunta ulos
- DDRD = 0x00;
- PORTD = 0xff; //yl�sveto
- while(1)
- {
- if (~PIND & 0x01) //testataan onko alin bitti nolla
- {
- wait(10);
- while (~PIND & 0x01);
- PORTB = PORTB ^0x03;
- }
- if (~PIND & 0x02) //PIND2 painamalla syttyvät/sammuvat ledit 3 & 4
- {
- wait(10);
- while (~PIND & 0x02);
- PORTB = PORTB ^0x0C;
- }
- if (~PIND & 0x04) //PIND3 painamalla syttyvät/sammuvat ledit 5 & 6
- {
- wait(10);
- while (~PIND & 0x04);
- PORTB = PORTB ^0x30;
- }
- if (~PIND & 0x08) //PIND3 painamalla syttyvät/sammuvat ledit 7 & 8
- {
- wait(10);
- while (~PIND & 0x08);
- PORTB = PORTB ^0xC0;
- }
- if (~PIND & 0x10) //PIND4 painamalla sammuvat kaikki ledit
- {
- wait(10);
- while (~PIND & 0x10);
- PORTB = 0xff;
- }
- if (~PIND & 0x20) //PIND5 painamalla pohjassa, vilkkuvat kaikki ledit portissa B
- {
- wait(10);
- while(~PIND & 0x20){
- PORTB = PORTB ^0xFF;
- wait(350);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement