0% found this document useful (0 votes)
45 views

F - Cpu F - Cpu: #Ifndef #Define #Endif #Include #Include #Include #Include #Include #Include

This document defines constants and variables for an embedded system with an 8 MHz clock and includes header files for I/O, interrupts, and delays. It initializes a counter, timer, and port directions. The main function blinks LEDs in a loop while waiting for interrupts from a pin change to increment the counter, which is divided by 2 and displayed on the LEDs.

Uploaded by

SrinuIndia
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)
45 views

F - Cpu F - Cpu: #Ifndef #Define #Endif #Include #Include #Include #Include #Include #Include

This document defines constants and variables for an embedded system with an 8 MHz clock and includes header files for I/O, interrupts, and delays. It initializes a counter, timer, and port directions. The main function blinks LEDs in a loop while waiting for interrupts from a pin change to increment the counter, which is divided by 2 and displayed on the LEDs.

Uploaded by

SrinuIndia
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/ 2

#ifndef F_CPU

#define F_CPU 8000000UL // 8 MHz clock speed


#endif
#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <math.h>
//#include "LCD_driver.h"
#include <util/delay.h>
// Declare Global Variables
volatile int counter;
volatile float timer;
volatile int divider;
volatile char str[100];
int main(void)
{
void delay_ms(int d)
{
_delay_ms(d);
}
counter = 0;// Initialize counter
timer = 0;// Initialize Timer
DDRD = 0x1F;//Port D has 8 Leds as outputs
DDRB = 0;// Port B all inputs
PORTB |= (1<<0);// Set Pull up resistor
PCMSK1 |= (1<<PINB0);// Pin Change Interrupt 1 Mask
EIMSK |= (1<<INT0);// Enable PCINT1
//LCD_Init();// Initialize LCD
PORTD = 0x10;
sei();// Set Interrupt Flag
while(1)
{
// Wait For Interrupts and Update LCD
//sprintf(str, "%dCOUNT", divider);// Write count to string
//LCD_puts(str);
PORTD = 0x10;
delay_ms(500);
PORTD = 0x00;
delay_ms(500);
//DDRB = 0x00;
PORTD = counter;
}
return 0;

}
// Pin Change Interrupt on Port B Bit 0
ISR(INT0_vect)
{
counter++;// Increment counter when pin changes
divider = counter/2;// Divide by 2, since pin changes twice
}

You might also like