📄 button.c
字号:
/*****************************************************
www.hhcn.org
www.hhcn.com
author:michael.chen email:mingzhixx@gmail.com
time:2006.05.17
revision:1.0
******************************************************/
/*****************************************************
comment:sw2 by connected to IRQ4
sw3 by connected to IRQ5
sw4 by connected to IRQ6
sw5 by connected to IRQ7
button_value_current=0,表示没有建
button_value_current=X,表示有键按下,并把button_value_current=0,接收下一个按键。
******************************************************/
#include "common.h"
#include "src/drivers/led/led.h"
#include "button.h"
//#include <stdio.h>
vint32 button_value;//the value of button by pressed
vint32 button_flag;//the times of button by pressed
vuint8 button_value_current;//the value of button by pressed currently
__interrupt__
void sw2_interrupt(void)
{
uint32 i=0;
//disable interrupt
MCF_INTC_IMRL |= 0x00000010;
OS_ENTER_CRITICAL();
asm(
MOVEQ.L #0,D0
MOVE.B (OSIntNesting),D0
ADDQ.L #1,D0
MOVE.B D0,(OSIntNesting)
CMPI.L #1, d0
BNE _SkipSave
MOVE.L (OSTCBCur), A1
MOVE.L A7,(A1)
);
/***********************************************************************/
_SkipSave:
button_value += 1;
//deug
printf("sw2\n");
// fflush(stdout);
button_flag++;//the times of button by pressed has been added
button_value_current = 2;//the NO.2 button has been pressed
// MCF_EPORT_EPFR = 0x10; //clear the irq 4
led_display(button_value_current);
//hold channel for a while
for(i=0;i<=0x300000;i++);
nop();
OS_EXIT_CRITICAL();
OSIntExit();
MCF_EPORT_EPFR = 0x10; //clear the irq 4
//enable interrupt
MCF_INTC_IMRL &= ~0x00000010;
}
__interrupt__
void sw3_interrupt(void)
{
uint32 i=0;
//disable interrupt
MCF_INTC_IMRL |= 0x00000020;
OS_ENTER_CRITICAL();
asm(
MOVEQ.L #0,D0
MOVE.B (OSIntNesting),D0
ADDQ.L #1,D0
MOVE.B D0,(OSIntNesting)
CMPI.L #1, d0
BNE _SkipSave
MOVE.L (OSTCBCur), A1
MOVE.L A7,(A1)
);
/***********************************************************************/
_SkipSave:
button_value += 2;
//deug
printf("sw3\n");
// fflush(stdout);
button_flag++;//the times of button by pressed has been added
button_value_current = 3;//the NO.3 button has been pressed
led_display(button_value_current);
/*
//去抖动
for (j=0;j<1000;j++)
for (i = 0;i<5000;i++);
*/
//hold channel for a while
for(i=0;i<=0x300000;i++);
nop();
OS_EXIT_CRITICAL();
OSIntExit();
MCF_EPORT_EPFR = 0x20; //clear the irq 5
//enable interrupt
MCF_INTC_IMRL &= ~0x00000020;
}
__interrupt__
void sw4_interrupt(void)
{
uint32 i=0;
//disable interrupt
MCF_INTC_IMRL |= 0x00000040;
OS_ENTER_CRITICAL();
asm(
MOVEQ.L #0,D0
MOVE.B (OSIntNesting),D0
ADDQ.L #1,D0
MOVE.B D0,(OSIntNesting)
CMPI.L #1, d0
BNE _SkipSave
MOVE.L (OSTCBCur), A1
MOVE.L A7,(A1)
);
/***********************************************************************/
_SkipSave:
button_value += 4;
//deug
printf("sw4\n");
// fflush(stdout);
button_flag++;//the times of button by pressed has been added
button_value_current = 4;//the NO.4 button has been pressed
led_display(button_value_current);
//hold channel for a while
for(i=0;i<=0x300000;i++);
nop();
OS_EXIT_CRITICAL();
OSIntExit();
MCF_EPORT_EPFR = 0x40; //clear the irq 6
//enable interrupt
MCF_INTC_IMRL &= ~0x00000040;
}
__interrupt__
void sw5_interrupt(void)
{
uint32 i=0;
//关中断
MCF_INTC_IMRL |= 0x00000080;
OS_ENTER_CRITICAL();
asm(
MOVEQ.L #0,D0
MOVE.B (OSIntNesting),D0
ADDQ.L #1,D0
MOVE.B D0,(OSIntNesting)
CMPI.L #1, d0
BNE _SkipSave
MOVE.L (OSTCBCur), A1
MOVE.L A7,(A1)
);
/***********************************************************************/
_SkipSave:
button_value += 8;
//deug
printf("sw5\n");
// fflush(stdout);
button_flag++;//the times of button by pressed has been added
button_value_current = 5;//the NO.5 button has been pressed
led_display(button_value_current);
//hold channel for a while
for(i=0;i<=0x300000;i++);
nop();
//for debug
// printf("MCF_EPORT_EPFR=%x\n",MCF_EPORT_EPFR);
// printf("MCF_EPORT_EPPDR=%x\n",MCF_EPORT_EPPDR);
OS_EXIT_CRITICAL();
OSIntExit();
MCF_EPORT_EPFR = 0x80; //clear the irq 7
//enable interrupt
MCF_INTC_IMRL &= ~0x00000080;
}
//set interrupt severic router
//in ucos we should use OSVectSet()
//otherwise we use mcf5xxx_set_handler (int vector, void (*handler) (void)) .
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -