把核心板(ADSP-BF592-CORE)带的bf592_key和bf592_led综合了一下,供需要的朋友参考,前两天有个地方写错了,居然胆大包天的怀疑起内核了,嘻嘻。见笑了!
刚入门,学习中。
/********************************************************
*
* 北京四维卓信电子有限公司
* http://www.openadsp.com
*
* 【OpenADSP开源社区】
* http://www.openadsp.com/bbs/
*
********************************************************/
#include <sys\exception.h>
#include <cdefBF592-A.h>
#include <ccblkfn.h>
int LEDON ;
bool isSttsChged = 0;
EX_INTERRUPT_HANDLER(Pushbutton_ISR);
void Set_PLL(int pmsel,int pssel)
{
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_led(void)
{
*pPORTG_FER &= (~(PG8 | PG9 | PG10|PG11)); //设置端口PG8~PG11功能为IO接口
*pPORTGIO_DIR |= (PG8 | PG9 | PG10|PG11); //设置端口PG8~PG11的方向为输出
*pPORTGIO_CLEAR = (PG8 | PG9 | PG10|PG11); //设置端口PG8~PG11的默认输出电平为0
}
void ledall_on(void)
{
*pPORTGIO_CLEAR =( PG8 | PG9 | PG10 | PG11 );//0x0f00;
}
void led1_on(void)
{
*pPORTGIO_SET = ( PG8 | PG9 | PG10 | PG11 );//0x0f00;
*pPORTGIO_CLEAR = PG8;//0x0100;
}
void led2_on(void)
{
*pPORTGIO_SET = ( PG8 | PG9 | PG10 | PG11 );//0x0f00;
*pPORTGIO_CLEAR = PG9;//0x0200;
}
void led3_on(void)
{
*pPORTGIO_SET = ( PG8 | PG9 | PG10 | PG11 );//0x0f00;
*pPORTGIO_CLEAR = PG10;//0x0400;
}
void led4_on(void)
{
*pPORTGIO_SET = ( PG8 | PG9 | PG10 | PG11 );//0x0f00;
*pPORTGIO_CLEAR = PG11;//0x0800;
}
void ledall_off(void)
{
*pPORTGIO_SET = ( PG8 | PG9 | PG10 | PG11 );//0x0f00;
}
void led1_off(void)
{
*pPORTGIO_SET |= PG8;//0x0100;
}
void led2_off(void)
{
*pPORTGIO_SET |= PG9;//0x0100<<1;
}
void led3_off(void)
{
*pPORTGIO_SET |= PG10;//0x0100<<2;
}
void led4_off(void)
{
*pPORTGIO_SET |= PG11;//0x0100<<3;
}
int mdelay(int count)
{
int i,j;
for(i=0;i<count;i++)
{
for(j=0;j<10000;j++);
if(isSttsChged) return 0;
}
return 0;
}
void Init_PushButtons(void)
{
*pPORTG_FER &= (~(PG12 | PG13 | PG14 | PG15)); //设置端口PG12~PG15的功能为IO功能
*pPORTGIO_INEN |= (PG12 | PG13 | PG14 | PG15); //设置端口PG12~PG15的输入使能功能
*pPORTGIO_DIR &= (~(PG12 | PG13 | PG14 | PG15)); //设置端口PG12~PG15的方向为输入
*pPORTGIO_EDGE |= (PG12 | PG13 | PG14 | PG15); //设置端口PG12~PG15的触发方式为沿触发
*pPORTGIO_POLAR &= (~(PG12 | PG13 | PG14 | PG15)); //设置端口PG12~PG15的触发方式为下降沿触发
*pPORTGIO_MASKA_SET |= (PG12 | PG13 | PG14 | PG15); //打开端口PG12~PG15的中断屏蔽
*pSIC_IAR2 = 0xf5ffffff; //打开中断源 Port G Interrupt A,优先等级参数设置为5
register_handler(ik_ivg12, Pushbutton_ISR); //对应中断优先等级为ik_ivg12,使用中断标识符Pushbutton_ISR
*pSIC_IMASK0 |= 0x00400000; //使能中断 Port G Interrupt A
}
EX_INTERRUPT_HANDLER(Pushbutton_ISR) //中断函数
{
int pb_status = *pPORTGIO; //读取当前IO状态
if((pb_status & 0xF000) == 0x1000) //判断按键中断
{
//printf("key is KEY1!(%d)\n",pb_status);
LEDON = 1;
isSttsChged = 1;
}
else if((pb_status & 0xF000) == 0x2000)
{
// printf("key is KEY2!\(%d)\n",pb_status);
LEDON = 2;
isSttsChged = 1;
}
else if((pb_status & 0xF000) == 0x4000)
{
// printf("key is KEY3!(%d)\n",pb_status);
LEDON = 4;
isSttsChged = 1;
}
else if((pb_status & 0xF000) == 0x8000)
{
// printf("key is KEY4!\(%d)\n",pb_status);
LEDON = 8;
isSttsChged = 1;
}
else ;// printf("key value is %x\n",pb_status);
*pPORTGIO_CLEAR = pb_status & 0xF000; //清除中断数据
}
void LedFlow(void)
{
{
led1_on();
mdelay(1000);
led2_on();
mdelay(1000);
led3_on();
mdelay(1000);
led4_on();
mdelay(1000);
led4_on();
mdelay(1000);
led3_on();
mdelay(1000);
led2_on();
mdelay(1000);
led1_on();
mdelay(1000);
}
}
int LedFlash(int n)
{
{
led1_on();
mdelay(n);
if(isSttsChged) return 0;
led2_on();
mdelay(n);
if(isSttsChged) return 0;
led3_on();
mdelay(n);
if(isSttsChged) return 0;
led4_on();
mdelay(n);
if(isSttsChged) return 0;
led3_on();
mdelay(n);
if(isSttsChged) return 0;
led2_on();
mdelay(n);
if(isSttsChged) return 0;
}
return 0;
}
int main(void)
{
Set_PLL(16,4);
Init_PushButtons();
init_led();
LEDON = 0;
LedFlow();
while(1)
{//
switch( LEDON )
{
case 1: LedFlash(200);break;
case 2: LedFlash(400);break;
case 4: LedFlash(800);break;
case 8: LedFlash(1600);break;
default:
LedFlow();
}
isSttsChged = 0;
}
;
}