MSP430按键中断
#include
typedef unsigned char uchar;
typedef unsigned int uint;
#define keyin (P1IN & 0X0F)
#define wei_h P5OUT |= BIT5
#define wei_l P5OUT &= BIT5
#define duan_l P6OUT &= ~BIT6
#define duan_h P6OUT |= BIT6
uchar table[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar num = 0;
void delay(int z)
{
int i,j;
for(i=z;i>0;i--)
for(j=112;j>0;j--);
}
void display(uchar dat)
{
P4OUT = table[dat];
duan_h;
duan_l;
P4OUT = 0x00;
wei_h;
wei_l;
}
void main( void )
{
uchar temp,keyval;
// P1DIR = 0XFF;P1OUT = 0XFF;
P2DIR = 0XFF;P2OUT = 0XFF;
P3DIR = 0XFF;P3OUT = 0XFF;
P4DIR = 0XFF;P4OUT = 0XFF;
P5DIR = 0XFF;P5OUT = 0XFF;
P6DIR = 0XFF;P6OUT = 0XFF;
P1DIR = 0XF0;
int num = 0;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
while(1)
{
if(keyin != 0x0f)
{
delay(5);
if(keyin != 0x0f)
{
temp = keyin;
while(keyin != 0x0f);//松手检测
switch(temp)
{
/* 1case 0x0e: keyval = 1;display(keyval);break;
case 0x0d: keyval = 2;display(keyval);break;
case 0x0b: keyval = 3;display(keyval);break;
【MSP430按键中断】case 0x07: keyval = 4;display(keyval);break;
default: keyval = 8;display(keyval);break; */
/* 2case 0x0d: num++;if(num==16)num=0;display(num);break;
case 0x0b: num--;if(num==0)num=15;display(num);break;*/
}
}
}
}
}
推荐阅读
- STM8S 中断唤醒,定时唤醒,窗口看门狗
- ARM中断寄存器详解
- stm32_中断优先级详解
- 4×4矩阵式键盘_非中断源程序
- 2440-中断寄存器详解
- 怎样数s3c2410的interrupt controller中的中断源数量
- 外部中断、定时中断、串口中断C51程序
- 51单片机学习之路 —— 1.6 单片机的中断_2
- ARM 系列 -- FS2410 开发板上的中断编程
- 定时器中断实验