📄 spi_test.c
字号:
#define LPCEB2000_I
/*********************************************************************************************
* File: spi_test.c
* Author: Embest w.h.xie
* Desc: test spi bus
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "target.h"
/*------------------------------------------------------------------------------------------*/
/* define */
/*------------------------------------------------------------------------------------------*/
#define SPI_Client P20
/*********************************************************************************************
* name: time_dly
* func: display code
* para: dly --in, delay value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void time_dly(uint32 dly)
{
uint32 i;
for(; dly>0; dly--)
for(i=0; i<500; i++);
}
/*********************************************************************************************
* name: sys_init
* func: init the sys
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void sys_init()
{
// allow PLL
PLLCON = 1;
VPBDIV = PLL_VPBDIV;
PLLCFG = PLL_CFG;
PLLFEED = 0xaa;
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0);
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
// set MAM 2 CCLK
MAMCR = 0;
MAMTIM = MAM_TIM;
MAMCR = 2;
// init all interrupt
VICIntEnClr = 0xffffffff;
VICVectAddr = 0;
VICIntSelect = 0;
}
/*********************************************************************************************
* name: spi_send
* func: spi bus send byte
* para: chr --in, send value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void spi_send(uint8 chr)
{
IOCLR0 = SPI_Client;
// send
SPI0_SPDR = chr;
while( 0==(SPI0_SPSR & 0x80) );
IOSET0 = SPI_Client;
}
/*********************************************************************************************
* name: Main
* func: main fun
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int main(void)
{
uint8 i, j;
// init GPIO , open SPI bus
PINSEL0 = 0x00005500;
PINSEL1 = 0x00000000;
sys_init();
IODIR0 = SPI_Client;
// set master send
SPI0_SPCCR = 0x80;
SPI0_SPCR = 0x30;
// send data
do {
for (i=0; i<14 ; i++) {
j = i;
if (i>7) {
j = 14 - i;
}
spi_send(~(1 << j));
time_dly(700);
}
} while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -