The timer is started through the interrupt of port P1, and then the timer interrupt is used to continuously scan the corresponding port status to determine the key
//Timer settings
void TimerA1Init()
{
_UINT data = 0 ;
TA1CTL = data;//clear all,diaable interrupt,claer ifg
TA1CTL |= TASSEL__ACLK | ID_0 | TACLR ; // ACLK, stop mode, ,div:1 ,clear TAR
//TA0CTL |= MC__UP ; //Start timer
TA1CCTL0 = CCIE ; //ccr0 compare interrupt enable
TA1CCR0 = 327; //ccr0 compare mode, ie disable, ifg clear
}
//P1 port interrupt program
#pragma vector = PORT1_VECTOR
__interrupt void Port1ADISR(void)
{
P1IFG &= 0x0f;
switch(P1IFG)
{
case Key_Sel:
TA1CTL |= MC__UP; //Start the timer
Key_Tmp = Key_Sel;
break;
case Key_Menu:
TA1CTL |= MC__UP; //Start the timer
Key_Tmp = Key_Menu;
break;
}
P1IFG &= 0x00;
}
/****************************************************** **********
Function name: __interrupt void Timer_A1_Count (void)
Function:
Entry parameters: None
Export parameters: None
Remark:
*************************************************** *********/
#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer_A1_Count(void)
{
static _UINT i = 0;
_UBYTE P1_Value;
P1_Value = P1IN;
P1_Value &= 0x06;
switch(Key_Tmp)
{
case Key_Menu:
{
if( (P1_Value & BIT2) == 0) //Button pressed
{
i++;
if(i >= 300) // Constant key processing
{
BUZZER_ON;
i = 0;
//Timer stop
TimerA1_Stop;
}
}
else if((P1_Value & BIT2) != 0)//button release
{
if( (i >= 5) && (i < 300) ) // short key
{
LCD_B1_RT_ON;
TimerA1_Stop;
i= 0;
}
else
{
i = 0; //Otherwise it is considered as jitter;
}
}
break;
}
case Key_Sel:
{
if( (P1_Value & BIT1) == 0) //Button pressed
{
i++;
}
else if( (P1_Value & BIT1) != 0) //Button released
{
if(i > 5) // short key processing
{
LCD_B1_RT_OFF;
TimerA1_Stop;
i = 0;
}
else
{
i = 0; //Otherwise it is considered as jitter;
}
}
break;
}
}
}
Previous article:MSP430 MCU Theory Review Knowledge Points
Next article:msp430f149 microcontroller serial port C program
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Giant microbit (giga:bit)
- Renesas CPK-RA6M4 Development Board Review + Unboxing and Building Environment
- Has anyone used the ionizing radiation sensor module? Discuss some technical issues
- RS-485 communication interface encoder
- FPGA Implementation of Fully Parallel FFT
- RT-Thread has been ported to W600
- MakeCode now supports STM103
- Please help me with the trip zone configuration of TI's 28034!!!
- Is the threshold for electromagnetic wave and antenna major getting lower and lower? Is the reliance on simulation software getting higher and higher?
- The input capture of stm8s cannot enter the interrupt. Please help? ? Thank you!!!