📄 ints.c
字号:
/*
* Copyright (c) 2002, Jan Szymanski.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Jan Szymanski.
* 4. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*********************************************************/
/* */
/* Module : Ints.C */
/* Language used : C */
/* Microprocessor : MSP430F149 */
/* */
/* Function : Interrupt Service Routines */
/* */
/* Revision History : */
/* Author Date Reason */
/* J.Szymanski December 2001 Initial Design */
/* */
/*********************************************************/
//#define PORT2_VECTOR 2 /* 0xFFE2 Port 2 */
//#define UART1TX_VECTOR 4 /* 0xFFE4 UART 1 Transmit */
//#define UART1RX_VECTOR 6 /* 0xFFE6 UART 1 Receive */
//#define PORT1_VECTOR 8 /* 0xFFE8 Port 1 */
//#define TIMERA1_VECTOR 10 /* 0xFFEA Timer A CC1-2, TA */
//#define TIMERA0_VECTOR 12 /* 0xFFEC Timer A CC0 */
//#define ADC_VECTOR 14 /* 0xFFEE ADC */
//#define UART0TX_VECTOR 16 /* 0xFFF0 UART 0 Transmit */
//#define UART0RX_VECTOR 18 /* 0xFFF2 UART 0 Receive */
//#define WDT_VECTOR 20 /* 0xFFF4 Watchdog Timer */
//#define COMPARATORA_VECTOR 22 /* 0xFFF6 Comparator A */
//#define TIMERB1_VECTOR 24 /* 0xFFF8 Timer B 1-7 */
//#define TIMERB0_VECTOR 26 /* 0xFFFA Timer B 0 */
//#define NMI_VECTOR 28 /* 0xFFFC Non-maskable */
/*********************************************************/
/* Name : Port2_ISR */
/* Parameters : none */
/* Returns : none */
/* Scope : */
/* Function : Port2 change from key ISR */
/* will exit the current LPM */
/*-------------------------------------------------------*/
interrupt(PORT2_VECTOR) wakeup Port2_ISR(void)
{
P2IFG=0x00;
}
/*-------------------------------------------------------*/
/* End of Function: Port2_ISR */
/*********************************************************/
/*********************************************************/
/* Name : TimerA1_ISR */
/* Parameters : none */
/* Returns : none */
/* Scope : */
/* Function : periodical timer ISR */
/* will exit the current LPM */
/*-------------------------------------------------------*/
interrupt(TIMERA1_VECTOR) wakeup TimerA1_ISR(void)
{
unsigned int temp;
unsigned char temp1;
// we are here every 10 ms
//putchar_uart0('%');
t10ms_1++; // increment software timer
TACTL &= 0xfffe; /* reset the flag */
free10ms++;
if(free10ms==10) // we are here every 100ms
{
free10ms=0;
freep1s++;
// for keys
inP2t5=inP2t4;
inP2t4=inP2t3;
inP2t3=inP2t2;
inP2t2=inP2t1;
inP2t1=inP2t0;
inP2t0=(P2IN&0x7f);
temp1=0;
if(inP2t1!=inP2t0)temp1++;
// if(inP2t2!=inP2t0)temp1++;
// if(inP2t3!=inP2t0)temp1++;
// if(inP2t4!=inP2t0)temp1++;
if(temp1==0)
{
inP2deb=inP2t0;
keystate=inP2deb;
if((oldkeystate==0x00)&&(keystate!=0x00))
{
validkey=1;
hexout_uart0(keystate);
switch(keystate)
{
case 0x01:
key='1';//play/stop
break;
case 0x02:
key='2';//pause
break;
case 0x04:
key='3';//previous
break;
case 0x08:
key='4';//next
break;
case 0x10:
key='5';//F1
break;
case 0x20:
key='6';//up
break;
case 0x40:
key='7';//down
break;
}//end of switch
}
oldkeystate=keystate; //reload
}//end of if(temp1==0)
// end of for keys
// for blinking LED1
temp=Red_LED_state;
Red_LED_state>>=1; // rotate one position
if((temp&0x0001)==0x0001) // LED on
{
Red_LED_state+=0x8000;
P3OUT &= 0xfe; // P3.0=0
}else
P3OUT |= 0x01; // P3.0=1
// for blinking LED2
temp=Green_LED_state;
Green_LED_state>>=1; // rotate one position
if((temp&0x0001)==0x0001) // LED on
{
Green_LED_state+=0x8000;
P3OUT &= 0xf7; // P3.3=0
}else
P3OUT |= 0x08; // P3.3=1
/* end of LEDs blinking */
// see for 1s tasks
if (freep1s==10) // we are here every 1s
{
freep1s=0;
freesec++;
t1s_1++;
}
}
}
/*-------------------------------------------------------*/
/* End of Function: TimerA1_ISR */
/*********************************************************/
/*********************************************************/
/* Name : Uart0Rx_ISR */
/* Parameters : none */
/* Returns : none */
/* Scope : */
/* Function : UART0 receive character ISR */
/* will exit the current LPM */
/*-------------------------------------------------------*/
interrupt(UART0RX_VECTOR) wakeup Uart0Rx_ISR(void)
{
unsigned char c;
c=U0RXBUF;
if((U0RCTL&0x01)==0x01)
U0RCTL&=0xf1; /* reset errors */
else
{
c=U0RXBUF; /* read character */
*pwr_uart0++ = c; /* and put into a buffer*/
/* adjust pointer if necessary */
if (pwr_uart0 >= &buffer_rxuart0[sizeb0])
pwr_uart0 = buffer_rxuart0;
}
}
/*-------------------------------------------------------*/
/* End of Function: Uart0Rx_ISR */
/*********************************************************/
/*********************************************************/
/* END OF FILE Ints.c */
/*********************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -