?? spi_test.c
字號:
/*********************************************************************************************
* File: spi_test.c
* Author: Embest z,j,zheng
* Desc: test spi bus
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "Board.h"
/*------------------------------------------------------------------------------------------*/
/* Global variables */
/*------------------------------------------------------------------------------------------*/
/* Digit Symbol table*/
int Symbol[] = { DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7,
DIGIT_8, DIGIT_9, DIGIT_A, DIGIT_B, DIGIT_C, DIGIT_D, DIGIT_E, DIGIT_F};
/* LED segment table */
int Seg[] = { SEGMENT_A, SEGMENT_B, SEGMENT_C, SEGMENT_D, SEGMENT_E, SEGMENT_F, SEGMENT_G, SEGMENT_P};
/*********************************************************************************************
* name: sys_init
* func: init the sys
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void SPI_init()
{
AT91F_SPI_Open(0);
AT91F_SPI_CfgCs(AT91C_BASE_SPI,0,(AT91C_SPI_BITS_8 | AT91C_SPI_CSAAT | AT91C_SPI_NCPHA | AT91C_SPI_SCBR));
AT91F_SPI_CfgMode(AT91C_BASE_SPI,AT91C_SPI_MSTR);
AT91F_SPI_DisableIt(AT91C_BASE_SPI,0x3f); // Disable SPI
AT91F_SPI_Enable(AT91C_BASE_SPI); // Enable SPI
}
/*********************************************************************************************
* name: spi_send
* func: spi bus send byte
* para: chr --in, send value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void spi_send(char chr)
{
AT91F_SPI_PutChar(AT91C_BASE_SPI,chr,0); // send a byte
}
/*********************************************************************************************
* name: time_dly
* func: display code
* para: dly --in, delay value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void time_dly(int dly)
{
int i;
for(; dly>0; dly--)
for(i=0; i<500; i++);
}
/*********************************************************************************************
* name: Main
* func: main fun
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
int Main()
{//* Begin
int i;
// First, enable the clock of the PIO
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
AT91F_SPI_CfgPIO();
AT91F_SPI_CfgPMC();
SPI_init();
spi_send(0);
for (;;)
{
for(i=0;i<16;i++)
{spi_send(~Symbol[i]); // 8seg-led display number from 0 to f
time_dly(1000);
}
time_dly(4000);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -