貌似没有那么麻烦,给你一个我之前写的按键中断你看看。
BF518上的。
#include <cdefBF518.h>
#include <sys\exception.h>
#include <ccblkfn.h>
#include <stdio.h>
#define pDEVICE_OE (volatile unsigned short *)0x20320000
#define pLED_DAT (volatile unsigned short *)0x20340000
#define IOSCLK PH4
#define IOMISO PH5
#define IOCS PH6
EX_INTERRUPT_HANDLER(Pushbutton_ISR);
void Set_PLL(unsigned int pmsel,unsigned int pssel)
{
unsigned int new_PLL_CTL;
*pPLL_DIV = pssel;
asm("ssync;");
new_PLL_CTL = (pmsel & 0x3f) << 9;
*pSIC_IWR |= 0xffffffff;
if (new_PLL_CTL != *pPLL_CTL)
{
*pPLL_CTL = new_PLL_CTL;
asm("ssync;");
asm("idle;");
}
}
void Init_EBIU(void)
{
*pEBIU_AMBCTL0 = 0x7bb07bb0;
*pEBIU_AMBCTL1 = 0xffc07bb0;
*pEBIU_AMGCTL = 0x000f;
}
void Init_SDRAM(void)
{
*pEBIU_SDRRC = 0x00000817;
*pEBIU_SDBCTL = 0x00000013;
*pEBIU_SDGCTL = 0x0091998d;
ssync();
}
delay(int count)
{
int i;
for(i=0;i<count;i++);
}
init_port()
{
int iar5 = *pSIC_IAR5;
int imask1 = *pSIC_IMASK0;
*pPORTG_FER &= (~(PG6 | PG7 | PG8| PG9)); //PH4 时钟 PH5 数据 PH6 片选
*pPORTGIO_DIR &= (~(PG6 | PG7 | PG8| PG9));
*pPORTGIO_INEN |= PG6 | PG7 | PG8| PG9;
*pPORTGIO_EDGE |= PG6 | PG7 | PG8| PG9;; /* edge sensitive */
*pPORTGIO_POLAR &= (~(PG6 | PG7 | PG8| PG9)); /* rising edge */
*pPORTGIO_MASKA_SET |= PG6 | PG7 | PG8| PG9;/* enable pbs */
/* port H interrupt A is bits 20-23 of IAR3, setup for IVG11 */
iar5 |= 0x00000004;
iar5 &= 0xfffffff4;
*pSIC_IAR5 = iar5;
/* register ISR and enable port H interrupt A */
register_handler(ik_ivg11, Pushbutton_ISR);
imask1 = *pSIC_IMASK1;
imask1 |= 0x00000100;
*pSIC_IMASK1 = imask1;
}
EX_INTERRUPT_HANDLER(Pushbutton_ISR)
{
int pb_status = *pPORTGIO;
/* if PB1 pushed */
if ( 0x0040 == (pb_status & PG6) )
{
*pPORTGIO_CLEAR = PG6;
printf("PB is PG6!\n");
}
if ( 0x0080 == (pb_status & PG7) )
{
*pPORTGIO_CLEAR = PG7;
printf("PB is PG7!\n");
}
if ( 0x0100 == (pb_status & PG8) )
{
*pPORTGIO_CLEAR = PG8;
printf("PB is PG8!\n");
}
if ( 0x0200 == (pb_status & PG9) )
{
*pPORTGIO_CLEAR = PG9;
printf("PB is PG9!\n");
}
}
/****************************************************************************
* 名称 : main
* 功能 : LED测试主函数
* 入口参数 :无
* 出口参数 :无
****************************************************************************/
void main(void)
{
unsigned short data;
Set_PLL(16,4);
Init_EBIU();
Init_SDRAM();
init_port();
while(1);
}