ارتباط Master با Slaves با SPI AVR

#include <mega16.h>
#include <delay.h>
#include <spi.h>
interrupt [EXT_INT0] void ext_int0_isr(void)
{
char a;
a = PIND.0 + PIND.1 * 2;
if(a == 1)
{
PORTB.0 = 0;
PORTB.1 = PORTB.2 = 1;
}
else if(a == 2)
{
PORTB.1 = 0;
PORTB.0 = PORTB.2 = 1;
}
else if(a == 3)
{
PORTB.2 = 0;
PORTB.1 = PORTB.0 = 1;
}
spi(PINC);
}
void main(void)
{
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0xBF;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
GICR|=0x40;
MCUCR=0x02;
MCUCSR=0x00;
GIFR=0x40;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
SPCR=0x53;
SPSR=0x00;
#asm("sei")
while (1)
{
// Place your code here
}
}
/ 0 نظر / 25 بازدید