// This sample program does not display,
// Pressing a key on the keyboard triggers the interrupt service routine of port P1, gets the key value of the keyboard, and saves it to the key value queue.
// In other interrupt service routines, the data in the key value queue guides the program flow.
#include
unsigned char keybuff[10];
unsigned char keypoint=0;
void delay(int v)
{
while(v!=0)v--;
}
unsigned char key(void)
{
unsigned char x=0xff;
P1DIR=0X0F;
P1OUT=0X01; //Scan the first line
if((P1IN&0X70)==0X10)
x=0;
else
if((P1IN&0X70)==0X20)
x=1;
else
if((P1IN&0X70)==0x40)
x=2;
else
{
P1OUT=0X2; //Scan the second lineif
((P1IN&0X70)==0X10)
x=3;
else
if((P1IN&0X70)==0X20)
x=4;
else
if((P1IN&0X70)==0x40)
x=5;
else
{
P1OUT=0X4; //Scan the third lineif
((P1IN&0X70)==0X10)
x=6;
else
if((P1IN&0X70)==0X20)
x=7;
else
if((P1IN&0X70)==0x40)
x=8;
else
{ P1OUT=8; //Scan the fourth lineif
((P1IN&0X70)==0X10)
x=9;
else
if((P1IN&0X70)==0X20)
x=10;
else
if((P1IN&0X70)==0x40)
x=11;
}
}
}
return(x);
}
unsigned char keyj(void)
{unsigned char x;
P1DIR=0x0f;
P1OUT=0x0f; //Keyboard hardware: P10--P13 are row lines, the top one is P10
x=(P1IN&0X70); // P14--P16 are column lines, the leftmost one is P14, column lines are pulled down
return(x); // No key pressed, return 0?; Key pressed returns non-0
}
interrupt[PORT1_VECTOR] void port1key(void)
{
if(keyj()!=0X00)
{
delay(300); //Debounce
if(keyj()!=0X0)
{
keybuff[keypoint]=key(); //Key press, see key value, save to queue
keypoint++; //
if(keypoint==10)
keypoint=0;
}
}
P1OUT=0X0F;
P1IFG=0X0; //Clear interrupt flag
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; /* // Stop WDT */
P1DIR=0XF;
P1OUT=0XF;
P1IES=0X0;
P1IE=0X70; //Column line rising edge enables P1 interrupt
_EINT(); /*/ Enable interrupts */
while(1)
{
LPM0;
_NOP();
}
Previous article:MSP430 MCU matrix keyboard test program
Next article:MSP430 LCD048
Recommended ReadingLatest update time:2024-11-15 19:40
- Popular Resources
- Popular amplifiers
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
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Sandia Labs develops battery failure early warning technology to detect battery failures faster
- MSP430F5438A serial port
- Making a CPU out of a bunch of switches?
- MSP430G2553-PC communication protocol
- Problems with TINA-TI Applications
- ST Motor_by yang_alex
- Japanese 0X-01 oxygen detector in-depth disassembly
- The area cannot be covered with copper and cannot have electrical wiring
- The xcl file of MSP430FR6972 cannot change the heap DATA16_HEAP starting address
- [Flower carving DIY] Interesting and fun music visualization series project (24) - infinite LED mirror light
- A contactless power supply circuit suitable for wireless mouse