您的位置: OpenADSP社区论坛 -> Blackfin专区 -> 新手上路 -> BF592技术支持专区 -> BF592处理器应用设计7.2-4个独立按键控制LE... 
本帖共有878个阅读者
发表帖子 发表投票 回复主题
BF592处理器应用设计7.2-4个独立按键控制LED状态(中断法)
尊贵身份标志
OpenADSP(管理员)
OpenADSP
头衔:社区公民
帮派:无帮无派
帖数:5187
金钱:34761
积分:6369
注册时间:2011/6/7
楼主信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线
BF592处理器应用设计7.2-4个独立按键控制LED状态(中断法)

程序功能

这个例子程序主要是学习,如何初始化BF592的GPIO口为输入口,如何配置GPIO中断。



杜邦线连接( BF592 GPIO         功能模块 )

BF592 GPIO

功能模块

杜邦线数量

功能

PF0~PF3

J11

4

独立按键

PG0~PG7

J18

8

LED


我是OP...
等级:管理员 参考IP地址:*.*.*.*
2012/8/15 10:00:35
尊贵身份标志
OpenADSP(管理员)
OpenADSP
头衔:社区公民
帮派:无帮无派
帖数:5187
金钱:34761
积分:6369
注册时间:2011/6/7
1信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线

程序说明:

上传的图片
  20128151022385.jpg [ 10.67 KB 507×311 ] (缩略时请点击查看原图)

 

上传的图片
  20128151023385.jpg [ 19.49 KB 584×418 ] (缩略时请点击查看原图)

 


我是OP...
等级:管理员 参考IP地址:*.*.*.*
2012/8/15 10:02:47
尊贵身份标志
OpenADSP(管理员)
OpenADSP
头衔:社区公民
帮派:无帮无派
帖数:5187
金钱:34761
积分:6369
注册时间:2011/6/7
2信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线

实验结果:

下载程序后,按下独立按键中的S1,连接到PG0~PG7接口的LED灯中的第1、3、5、7个灯会亮,按下独立按键中的S2, LED灯中的第1、3、5、7个灯灭,第2、4、6、8个灯亮,按下独立按键中的S3, LED灯中的所有的灯都会亮,按下独立按键中的S4, LED灯中所有的灯都会灭。

知识要点及提问:

1.s_num = *pPORTFIO&0x00ff;

     在GPIO中断中,如果接口被配置成了中断接口,那么在没有按键按下的时候读的IO状态是0,当有按键按下后,对应的IO口读出来的值是1,就如例子中那样。


我是OP...
等级:管理员 参考IP地址:*.*.*.*
2012/8/15 10:03:00
congra(论坛新手)
congra
头衔:社区公民
帮派:无帮无派
帖数:9
金钱:147
积分:9
注册时间:2012/9/19
3信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线

把核心板(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;
}
;
}



这家伙很懒,什么也没有留下!
等级:论坛新手 参考IP地址:*.*.*.*
2012/9/27 0:55:12
尊贵身份标志
夜色飘摇(论坛版主)
夜色飘摇
头衔:社区公民
帮派:无帮无派
帖数:350
金钱:1773
积分:332
注册时间:2011/6/8
4信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线
顶。

我要成为勇敢的海上战士!
等级:论坛版主 参考IP地址:*.*.*.*
2012/9/28 10:16:09
(论坛新手)
千
头衔:社区公民
帮派:无帮无派
帖数:1
金钱:105
积分:1
注册时间:2018/10/18
5信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线
需要按键消抖吗


这家伙很懒,什么也没有留下!
等级:论坛新手 参考IP地址:*.*.*.*
2018/12/18 11:16:16
Powered by OpenADSP Copyright © 2010 www.Openadsp.com. All rights reserved.154119 Call, 1 Queries, Processed in 0.031250 second(s),