MSP430 Keyboard Program

Publisher:yuehuiLatest update time:2016-08-23 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
// This sample program uses interrupt mode to get the keyboard key value and store it in the queue keybuff[10]

// 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();   
}

Keywords:MSP430 Reference address:MSP430 Keyboard Program

Previous article:MSP430 MCU matrix keyboard test program
Next article:MSP430 LCD048

Recommended ReadingLatest update time:2024-11-15 19:40

Based on MSP430F149 microcontroller serial port program, interrupt query method
Based on MSP430F149 microcontroller serial port program, interrupt query method #include msp430x14x.h #define uint unsigned int #define uchar unsigned char #define RXF BIT7//p2 #define TXF BIT6 #define Read BIT4//p3 #define Write BIT5//p3 uchar static usb_flag=0; void int_clk() {     uchar i;     BCSCTL1
[Microcontroller]
Temperature measurement system design based on msp430 microcontroller
  This article introduces a method of measuring temperature using the msp430 microcontroller to replace the relatively backward experimental method of combining thermistors with ammeters in traditional teaching.   1 Temperature measurement part   There are many kinds of temperature sensitive elements used to measure
[Microcontroller]
Temperature measurement system design based on msp430 microcontroller
MSP430 Learning—CPU and Instructions
MSP430 uses a unified address space allocation;   Word type can only be located at an even address, the even address stores the low byte, and the high byte is located at the address plus 1; Eg. If a byte array is defined and a byte address is assigned to a Word type variable, an error will occur. For example, the
[Microcontroller]
A temperature and humidity detection system based on MSP430F1232
Introduction With the development of social economy and the continuous progress of science and technology, the temperature and humidity of the environment need to be limited in many cases. Therefore, temperature and humidity alarms must be installed in certain specific environments for monitoring. To this end, this pa
[Microcontroller]
A temperature and humidity detection system based on MSP430F1232
Definition of MSP430 interrupt service function
//In order to ensure that the code can be compiled correctly in any version of the IAR compiler, the following conditional compilation is performed. #ifdef __IAR_SYSTEMS_ICC__                           //If the compiler is IAR, then the following will be compiled.  #if __VER__ = 200 #pragma vector=USART0RX_VEC
[Microcontroller]
MSP430 common program architecture
1. Low power consumption + interruption Main function { Disable watchdog Setting the system clock Initialize peripheral devices such as display Initialization settings of internal resources such as timers Enable global interrupt Enter low power } Interrupt function 1 {}; Interrupt function 2 {} File
[Microcontroller]
MSP430F5438 clock system
1 Overview   Unified clock system (ucs) unified clock system. MSP430F5438 has 5 clock sources: XT1, XT2, REFCLO, VLCLO, DCO. External LF (XT1 is usually 32.768K) ​​can be connected to a clock crystal or an external clock source of 4M-32M. XT1 can be used as a reference clock source for the frequency-locked loop. HF (X
[Microcontroller]
msp430 accurately measures low frequency
//****************************************************************************** // Date: 2009.8.16 // Author: xurafreedom // Email: freedomxura@gmail.com / mxh20999@163.com // Blog: http://xurafreedom.cublog.cn // Basic principle: 1s timing, count the number of rising edges of the captured signal during this time
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号