|
#include unsigned char w,i,r_data[5],st,mi,ml; void SPI (void) interrupt 7 void read (unsigned char regr) void write (unsigned char regw,unsigned char f,unsigned char s,unsigned char d) //Основная программа
E-mail:
info@telesys.ru
{
i++;
if (w==0) r_data[i]=SPIDAT;
if (i==3) SPIDAT=ml;
if (i==2) SPIDAT=mi;
if (i==1) SPIDAT=st;
}
{
w=0;
i=0;
st=255;
mi=255;
ml=255;
SPIDAT=regr; //write Register name
IE2=1; //enable SPI interrupt (прерывание от ISPI)
while (i!=4);
IE2=0; //disable SPI interrupt (прерывание от ISPI)
}
{
w=1;
i=0;
st=f;
mi=s;
ml=d;
SPIDAT=regw+64; //write Register name + Write flag
delay (1);
IE2=1; //enable SPI interrupt (прерывание от ISPI)
while (i!=4);
IE2=0; //disable SPI interrupt (прерывание от ISPI)
}
void main (void)
{
//Конфигурирование порта вывода
SPICON = 0x33; //configure SPI port for Fosc/xx, CPHA=0, CPOL=0, master
EA = 1; //разрешить прерывания
Ответы