// //write a code to blink leds on port a when any push nutton in port b pressed
// #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 delay(void){
// for(volatile uint32_t i=0;i<50000;i++);
// }
// int main(void){
// DDRA = 0xFF;
// DDRB = 0x00;
// while(1){
// if((PINB & 0x01) == 0x01){
// PORTA = 0xFF;
// delay();
// PORTA = 0x00;
// delay();
// } else {
// PORTA = 0x00;
// }
// }
// }
//write a code to blink leds corresponding 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<<i);
delay1sec();
PORTA = 0x00;
delay1sec();
}
}
}
else {
PORTA = 0x00;
}
}
}