[go: up one dir, main page]

0% found this document useful (0 votes)
23 views4 pages

C Program AI

This document is a lab assignment for a Real Time and Embedded System course at the School of Computing and Informatics. It includes a C program for an AVR microcontroller that controls an LED based on the state of a button. The program sets up the necessary input and output pins and includes a debounce delay for the button press detection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

C Program AI

This document is a lab assignment for a Real Time and Embedded System course at the School of Computing and Informatics. It includes a C program for an AVR microcontroller that controls an LED based on the state of a button. The program sets up the necessary input and output pins and includes a debounce delay for the button press detection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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;

You might also like