//write a code to blink leds for button 0-7 and 1-6, 2-5 soon push buton reading
//hardware is same as 1st exp
#include <stdint.h>
#define PINA (*(volatile uint8_t*)0x20)
#define DDRA (*(volatile uint8_t*)0x21)
#define PORTA (*(volatile uint8_t*)0x22)
#define PINB (*(volatile uint8_t*)0x23)
#define DDRB (*(volatile uint8_t*)0x24)
#define PORTB (*(volatile uint8_t*)0x25)
void delay1sec(void){
TCNT1 = 0;
TCCR1A = 0x00;
TCCR1B = 0x05;
while (TCNT1 < 15625);
TCCR1B = 0x00;
}
int main(void){
DDRA = 0xFF; // LEDs output
DDRB = 0x00; // Buttons input
while(1){
uint8_t btn = PINB;
if(btn !=0x00){
for(uint8_t i=0; i<8; i++){
if(btn == (1<<i)){
PORTA = (1 << (7 - i));
delay1sec();
PORTA = 0x00;
delay1sec();
}
}
}
else {
PORTA = 0x00;
}
}
}