Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 7372800UL
- #include <avr/io.h>
- #include <util/delay.h>
- uint8_t state = 1;
- void blink(uint8_t cnt) {
- if (cnt <= 3) {
- PORTA = PORTA & ~_BV(4+cnt) & ~_BV(3-cnt);
- } else {
- cnt %= 4;
- PORTA = PORTA | _BV(cnt) | _BV(7-cnt);
- }
- }
- int main() {
- DDRA = 0xff;
- PORTA = 0xff;
- DDRB = _BV(0) | _BV(1);
- PORTB = _BV(0) | _BV(1);
- uint8_t cnt = 0;
- while (1) {
- if(bit_is_clear(PINB, 0)) {
- state = -1;
- } else if (bit_is_clear(PINB, 1)) {
- state = 1;
- }
- if(state == 1) {
- blink(cnt);
- cnt = (cnt+1) % 8;
- }
- _delay_ms(200);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement