Anda di halaman 1dari 1

<----- Header section ------------->

#include <avr/io.h>
#include <avr/interrupt.h>
#include<stdlib.h>
#include<compat/deprecated.h>
#include <util/delay.h>

#define datapin 0x01 // Value of data port when the data pin is high
#define dataport PINB // Enter the data port here

<--------Global Declarations-------------->
static unsigned int count=0;
static unsigned char data=0x00;

<-------Main Code ------------------------->


int main(void)
{
DDRB=0xfa; // Port initialisations
PORTB=0x00;
DDRA=0xff;
PORTA=0xaa;
DDRC=0xff;
PORTC=0x00;
DDRD=0xff;
PORTD=0x00;

cbi(GICR,5); // Setting up INT2 (edge triggered


interrupt)
cbi(MCUCSR,6); // to be triggered on the falling edge
cbi(MCUCSR,6);
sbi(GIFR,5);
sbi(GICR,5);
sei(); // Enable global interrupts

while(1) // Do nothing. Can be used to run other


code when integrating
{ // other functionality
}

ISR(INT2_vect) // Interrupt Service Routine to detect


and act on the
{ // interrupts received
count++;
if (count > 1 && count < 10) // Read the data bits,neglecting the start bit
and the stop and parity bits
{
data = (data >> 1); // LSB first
if(dataport & datapin) {data = data | 0x80; } // Store a '1'. Here, the Pin0 of
PORTB is used as input
}
PORTA=data; // Display received data on Port A.
}

Anda mungkin juga menyukai