P1 端口中斷操作
* 功能 : P1.0用來控制LED的亮滅,軟件延時50000,來翻轉(zhuǎn)P1.0 *
* *
* MSP430F2274 *
* ----------------- VCC 3.0v *
* /| | XIN|- ___ *
* | | XOUT|- | *
* --|RST P1.2|-->LED-----| *
* +--key-->|P1.3 P1.1|-->LED-----| *
* |---key-->|P1.4 P1.0|-->LED-----| *
* | ------------------- *
* GND *
* 作者 : Singel *
* 時間 : 2008-10-11 16:36:00 *
* 調(diào)試環(huán)境 : IAR For MSP430 Embedded Workbench v3.42A *
********************************************************************************/
#include"msp430x22x4.h"
unsigned char keybuffer;
unsigned char scanflag;
unsigned char TEMP_KEY;
void Do_Without_PORT_Register( void )
{
P1IE = 0x00;
P1IFG = 0x00;
P1IE = 0x00;
}
void PORT_init( void )
{
P1DIR |= (BIT0+BIT1+BIT2);
P1OUT |= (BIT0+BIT1+BIT2);
P1DIR &=~ (BIT4+BIT3);
P1IES &=~ (BIT4+BIT3);
P1IE |= (BIT4+BIT3);
P1IFG &=~ (BIT4+BIT3);
}
void key_procss ( void )
{
TEMP_KEY = TEMP_KEY&0X18;
switch(TEMP_KEY)
{
case 0x10: P1OUT ^= BIT0+BIT1+BIT2;break;
case 0x08: P1OUT ^= BIT0+BIT1+BIT2;break;
}
P1IE |= (BIT4+BIT3);
}
void main( void )
{
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_12MHZ;
DCOCTL = CALBC1_12MHZ;
Do_Without_PORT_Register();
PORT_init();
_BIS_SR(GIE+LPM4_bits);
while(1)
{
if(scanflag)
{
scanflag = 0;
key_procss();
}
_BIS_SR(GIE + LPM4_bits);
}
}
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR ( void )
{
_BIC_SR_IRQ(LPM4_bits);
TEMP_KEY = P1IFG;
scanflag = 1;
P1IE &=~ (BIT4+BIT3);
P1IFG &=~ (BIT4+BIT3);
}
評論