You are on page 1of 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