📄 button.c
字号:
/*********************************************************************************************
* File: button.c
* Author: Embest z.j.zheng
* Desc: button test
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "Board.h"
/*------------------------------------------------------------------------------------------*/
/* Global variables */
/*------------------------------------------------------------------------------------------*/
int status_irq = 0 ;
/* 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};
/*------------------------------------------------------------------------------------------*/
/* constant definition */
/*------------------------------------------------------------------------------------------*/
#define IRQ0_INTERRUPT_LEVEL 2
/*********************************************************************************************
* 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 interrupt
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(void)
{
int i;
AT91PS_AIC pAic;
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
AT91F_SPI_CfgPIO();
AT91F_SPI_CfgPMC();
SPI_init();
//configure PIO (connect to the buttons) in input mode
AT91F_PIO_CfgInput( AT91C_BASE_PIOA, SW_MASK );
do {
i= AT91F_PIO_GetInput(AT91C_BASE_PIOA); //get the input value of the button
if((i&SW1) == 0) spi_send(~Symbol[1]); //detect which is push down
else if((i&SW2) == 0) spi_send(~Symbol[2]);
else if((i&SW3) == 0) spi_send(~Symbol[3]);
else if((i&SW4) == 0) spi_send(~Symbol[4]);
} while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -