#include "config.h"
#define SALVE (1 << 29)
#define LED 0xff << 16
volatile uint8 RcvData;
volatile uint8 RcvFlag;
void DelayNS(uint32 dly)
{
uint32 i;
for(; dly>0; dly--)
for(i=0; i<50000; i++);
}
void __irq SPI_IRQ(void)
{
uint32 tmp;
tmp = SPSR;
RcvData = SPDR;
RcvFlag = 0x01;
SPINT = 0x01;
VICVectAddr = 0x00;
}
void SPI_Init(void)
{
S0PCR = (0 << 3) | (1 << 4) |
(0 << 5) |
(0 << 6) |
(1 << 7);
}
int main (void)
{
uint8 rcv_data;
PINSEL0 = (PINSEL0 | 0x00005500);
PINSEL2 = PINSEL2 & (~0x08); IO1DIR = LED;
IO0DIR = SALVE;
IOCLR= SALVE;
IRQEnable(); SPI_Init();
VICIntSelect = 0x00000000;
VICVectCntl0 = (0x20 | 10);
VICVectAddr0 = (int32)SPI_IRQ;
VICIntEnable = (1 << 10);
while(1)
{
if(RcvFlag != 0)
{
rcv_data = RcvData;
IO1CLR = rcv_data <<16 ;
DelayNS(200);
IO1SET = rcv_data <<16 ;
DelayNS(200);
}
}
return 0;
}
2210板上程序:
#include "config.h"
#define HC595_CS (1 << 29)
void DelayNS(uint32 dly)
{
uint32 i;
for(; dly>0; dly--)
for(i=0; i<50000; i++);
}
void MSPI_Init(void)
{
PINSEL0 = (PINSEL0 & (~(0xFF << 8))) | (0x55 << 8) ;
SPCCR = 0x52;
SPCR = (0 << 3) | (1 << 4) | (1 << 5) | (0 << 6) | (0 << 7);
}
uint8 MSPI_SendData(uint8 data)
{
IOCLR = HC595_CS;
SPI_SPDR = data;
while( 0 == (SPI_SPSR & 0x80));
IOSET = HC595_CS;
return(SPI_SPDR);
}
|