// if we press PB1 1,DELAY 2 DELAY ,5 DELAY ,6
// if we press PB2 3,1,7,4
//if we press PB3 0,1,5,6
// if we press PB7 0,1,4,7
// LLY PB4 7632
//PB5 3,5,7,6
// PB1 AND PB7 ONE AFTER ANOTHER TO GLOW 5TH LED FOR 2 SEC
//PB1,PB4,PB7,PB6 == 7YH LED
// PRESS 1479 TO GLOW 5TH LED AND PRESS 1543 TP GLOW 3RD LED
//TOTAL WE HAVE 9 PROGRAMS TO EXECUTE
// HERE WE CAN MAKE USE OF lut ot execute this operations
// // if we press PB1 1,DELAY 2 DELAY ,5 DELAY ,6
// #include <stdint.h>
// #define DDRA (*(volatile uint8_t*)0x21)
// #define PORTA (*(volatile uint8_t*)0x22)
// #define PINB (*(volatile uint8_t*)0x23)
// #define DDRB (*(volatile uint8_t*)0x24)
// 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){
// if (PINB & (1 << 1)) { // PB1 pressed
// PORTA = (1 << 1); // LED 1
// delay1sec();
// PORTA = 0x00;
// delay1sec();
// PORTA = (1 << 2); // LED 2
// delay1sec();
// PORTA = 0x00;
// delay1sec();
// PORTA = (1 << 5); // LED 5
// delay1sec();
// PORTA = 0x00;
// delay1sec();
// PORTA = (1 << 6); // LED 6
// delay1sec();
// PORTA = 0x00;
// delay1sec();
// }
// else {
// PORTA = 0x00;
// }
// }
// }
// =================================================================================
/*
Problem Statement:
Write a program to blink LEDs in the sequence 3, 1, 7, 4
when push button PB2 is pressed.
Hardware:
- LEDs connected to PORT A (PA0–PA7)
- Push buttons connected to PORT B (PB0–PB7)
- External pull-down resistors used for push buttons
*/
#include <stdint.h>
#define DDRA (*(volatile uint8_t*)0x21)
#define PORTA (*(volatile uint8_t*)0x22)
#define PINB (*(volatile uint8_t*)0x23)
#define DDRB (*(volatile uint8_t*)0x24)
void delay1sec(void){
TCNT1 = 0;
TCCR1A = 0x00;
TCCR1B = 0x05;
while (TCNT1 < 15625);
TCCR1B = 0x00;
}
int main(void){
DDRA = 0xFF; // PORT A as output (LEDs)
DDRB = 0x00; // PORT B as input (Buttons)
while(1){
if (PINB & (1 << 2)) { // PB2 pressed
PORTA = (1 << 3); // LED 3
delay1sec();
PORTA = 0x00;
delay1sec();
PORTA = (1 << 1); // LED 1
delay1sec();
PORTA = 0x00;
delay1sec();
PORTA = (1 << 7); // LED 7
delay1sec();
PORTA = 0x00;
delay1sec();
PORTA = (1 << 4); // LED 4
delay1sec();
PORTA = 0x00;
delay1sec();
}
else {
PORTA = 0x00;
}
}
}
================================================================================
/*
Problem Statement:
Write a program to blink LEDs in the sequence 0, 1, 5, 6
when push button PB3 is pressed.
Hardware:
- LEDs connected to PORT A (PA0–PA7)
- Push buttons connected to PORT B (PB0–PB7)
- External pull-down resistors are used for push buttons
*/
#include <stdint.h>
#define DDRA (*(volatile uint8_t*)0x21)
#define PORTA (*(volatile uint8_t*)0x22)
#define PINB (*(volatile uint8_t*)0x23)
#define DDRB (*(volatile uint8_t*)0x24)
void delay1sec(void){
TCNT1 = 0;
TCCR1A = 0x00;
TCCR1B = 0x05; // prescaler 1024
while (TCNT1 < 15625); // ~1 second delay
TCCR1B = 0x00;
}
int main(void){
DDRA = 0xFF; // PORT A as output (LEDs)
DDRB = 0x00; // PORT B as input (Buttons)
while(1){
if (PINB & (1 << 3)) { // PB3 pressed
PORTA = (1 << 0); // LED 0
delay1sec();
PORTA = 0x00;
delay1sec();
PORTA = (1 << 1); // LED 1
delay1sec();
PORTA = 0x00;
delay1sec();
PORTA = (1 << 5); // LED 5
delay1sec();
PORTA = 0x00;
delay1sec();
PORTA = (1 << 6); // LED 6
delay1sec();
PORTA = 0x00;
delay1sec();
}
else {
PORTA = 0x00;
}
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
Problem Statement:
Write a program to blink LEDs in the sequence 0, 1, 5, 6
when push button PB3 is pressed.
Hardware:
- LEDs connected to PORT A (PA0–PA7)
- Push buttons connected to PORT B (PB0–PB7)
- External pull-down resistors are used for push buttons
*/
#include <stdint.h>
#define DDRA (*(volatile uint8_t*)0x21)
#define PORTA (*(volatile uint8_t*)0x22)
#define PINB (*(volatile uint8_t*)0x23)
#define DDRB (*(volatile uint8_t*)0x24)
void delay1sec(void){
TCNT1 = 0;
TCCR1A = 0x00;
TCCR1B = 0x05; // prescaler 1024
while (TCNT1 < 15625); // ~1 second delay
TCCR1B = 0x00;
}
int main(void){
DDRA = 0xFF; // PORT A as output (LEDs)
DDRB = 0x00; // PORT B as input (Buttons)
while(1){
if (PINB & (1 << 3)) { // PB3 pressed
PORTA = (1 << 0); // LED 0
delay1sec();
PORTA = 0x00;
delay1sec();
PORTA = (1 << 1); // LED 1
delay1sec();
PORTA = 0x00;
delay1sec();
PORTA = (1 << 5); // LED 5
delay1sec();
PORTA = 0x00;
delay1sec();
PORTA = (1 << 6); // LED 6
delay1sec();
PORTA = 0x00;
delay1sec();
}
else {
PORTA = 0x00;
}
}
}
/*
Problem Statement:
Blink LEDs in the sequence 3, 5, 7, 6 when push button PB5 is pressed.
*/
#include <stdint.h>
#define DDRA (*(volatile uint8_t*)0x21)
#define PORTA (*(volatile uint8_t*)0x22)
#define PINB (*(volatile uint8_t*)0x23)
#define DDRB (*(volatile uint8_t*)0x24)
void delay1sec(void){
TCNT1=0; TCCR1A=0; TCCR1B=0x05;
while(TCNT1<15625); TCCR1B=0;
}
int main(void){
DDRA=0xFF; DDRB=0x00;
while(1){
if(PINB & (1<<5)){
PORTA=(1<<3); delay1sec(); PORTA=0; delay1sec();
PORTA=(1<<5); delay1sec(); PORTA=0; delay1sec();
PORTA=(1<<7); delay1sec(); PORTA=0; delay1sec();
PORTA=(1<<6); delay1sec(); PORTA=0; delay1sec();
}
}
}
/*
Problem Statement:
Blink LEDs in the sequence 0, 1, 4, 7 when push button PB7 is pressed.
*/
#include <stdint.h>
#define DDRA (*(volatile uint8_t*)0x21)
#define PORTA (*(volatile uint8_t*)0x22)
#define PINB (*(volatile uint8_t*)0x23)
#define DDRB (*(volatile uint8_t*)0x24)
void delay1sec(void){
TCNT1=0; TCCR1A=0; TCCR1B=0x05;
while(TCNT1<15625); TCCR1B=0;
}
int main(void){
DDRA=0xFF; DDRB=0x00;
while(1){
if(PINB & (1<<7)){
PORTA=(1<<0); delay1sec(); PORTA=0; delay1sec();
PORTA=(1<<1); delay1sec(); PORTA=0; delay1sec();
PORTA=(1<<4); delay1sec(); PORTA=0; delay1sec();
PORTA=(1<<7); delay1sec(); PORTA=0; delay1sec();
}
}
}