School of computing and informatics
Department: - Computer Science
Program weekend year 4 Term 1
Course Name: Real Time and Embedded
System
Lab Assignment GROUP TWO
Name
ID
MIKAEL GEMECHU…………………………………………….SCIE/023/2013
NETSANET GIRMA……………………………………………… SCIE/0 /2013
FIKADU SHAZ…………………………………………….…….. SCIE/0 /2013
BIREHANU HABTAMU………………………………………….. SCIE/0 /2013
Submission date 02/13/2016 E,C
1.
#include <avr/io.h>
#include <util/delay.h>
#define BUTTON_PIN PD2
#define LED_PIN PB0
void setup() {
// Set LED pin as output
DDRB |= (1 << LED_PIN);
// Set BUTTON_PIN as input and enable pull-up resistor
DDRD &= ~(1 << BUTTON_PIN); // Set BUTTON_PIN as input
PORTD |= (1 << BUTTON_PIN); // Enable pull-up resistor on BUTTON_PIN
void loop() {
// Read the state of the button
if (!(PIND & (1 << BUTTON_PIN))) { // Check if the button is pressed (active low)
PORTB |= (1 << LED_PIN); // Turn on LED
} else {
PORTB &= ~(1 << LED_PIN); // Turn off LED
_delay_ms(50); // Debounce delay
}
int main(void) {
setup();
while (1) {
loop();
return 0;