4*3 matrix button program

Publisher:创意梦者Latest update time:2012-08-15 Source: 51heiKeywords:4*3 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Click to browse the next page
/******************************************************** * * 4*3 matrix key read and write function * ********************************************************/ //Button reading and writing program //Row 1 P65 //Row 2 P62 //Row 3 P51 //Row 4 P67 P5:1 P6:257 //Column 1 P63 //Column 2 P64 //Column 3 P66 //Key decoding //Row 4: 0,1,2;Row 1: 3,4,5;Row 3: 6,7,8;Row 2: 9,10,11; //*0# 123 789 456 const uchar key_rel[]={0x0a,0x00,0x0b,0x01,0x02, 0x03,0x07,0x08,0x09,0x04,0x05,0x06}; void scan_key(void) { fly i; keybuf=0xff; get_bit=0; /*Method 1: row output, column input, affects AT24C02, LED flashes //The port direction of sleep wake-up, undervoltage detection, and sound and light indication does not need to be changed //Line output 0 //P5CR&=0x0d; //0000 1101 initialize P5 to all output ports P5CR=0xf0; P6CR&=0x5b;//0101 1011 // Column input 1 P6CR|=0x58;//0101 1000/ //Method 2: Column output, row input, column 1 string 10K, if low level cannot be output, it may not be recognized // Will not affect AT24C02, LED indication, other operations require redefining the port direction //Output column 0 P6CR&=0xa7;//1010 0111 //Line input 1 P5CR|=0x02;//0000 0010 P6CR|=0xa4;//1010 1000*/ /*Method 3: Use method 2 to scan the columns first, and then read and write column 1 separately //Column 1 reading and writing experiment P5CR=0xf0; P6CR&=0x5b;//0101 1011 // Column input 1 P6CR|=0x58;//0101 1000/ KH1=0;KH2=0;KH3=0;KH4=0; if(KL1==0)keybuf=0x01;//A key is pressed in column 1 while(KL1==0); // Column 23, read and write */ // Final version of the key reading and writing program, low level scan line 2, all lines are pulled low //Line output 0 P6CR&=0x5b;//0101 1011 // Column input 1 P6CR|=0x58;//0101 1000/ for(i=0;i<4;i++) {switch(i) {//No AT24C02 operation, try not to open KH4 to power AT24C02 case 0:KH1=1;KH2=1;KH3=1;KH4=0;break;//Scan line 4 case 1:KH1=0;KH2=1;KH3=1;KH4=0;break;//Scan line 1 case 2:KH1=1;KH2=1;KH3=0;KH4=0;break;//Scan line 3 //Finally scan the red and green LED common terminals, pull them all low, and no LED lights up during full scan case 3:KH1=0;KH2=0;KH3=0;KH4=0;break;//Scan line 2 } delay(200); if(KL1==0){keybuf=0x00;get_bit=1;break;} if(KL2==0){keybuf=0x01;get_bit=1;break;} if(KL3==0){keybuf=0x02;get_bit=1;break;} } if(get_bit==1) //Get the key value {get_bit=0; //Delay to remove jitter //delay(250);// //The scan status has been saved switch(keybuf) {case 0x00:if(KL1==0)get_bit=1;;break; case 0x01:if(KL2==0)get_bit=1;;break; case 0x02:if(KL3==0)get_bit=1;;break; default:keybuf=0xff; } if(get_bit==1) {keybuf=i+i+i+keybuf; //decode key i=key_rel[keybuf];//decode key keybuf=i; //Get the key value //Button sound and light indication buzzer(); //Wait for the button to pop up KH1=0;KH2=0;KH3=0;KH4=0; delay(80); while((KL1&&KL2&&KL3)==0); } else keybuf=0xff; } else keybuf=0xff;//Invalid key //Line 2 invalid reading and writing analysis //TCC pin CONT instruction 0x0* } /******************************************************** * * END key_scan * ********************************************************/
Keywords:4*3 Reference address:4*3 matrix button program

Previous article:A large collection of microcontroller LED running lights and flashing lights programs
Next article:TLC5620 generates frequency-adjustable three-phase sinusoidal signals

Recommended ReadingLatest update time:2024-11-16 15:57

Ambarella launches AI domain controller CV3 series SoC, a single chip can achieve ADAS and L4 autonomous driving
The CV3 series of automotive-specific SoCs use a 5nm ultra-low-power process to achieve an unprecedented single-chip 500 eTOPS AI computing power, while supporting high-resolution cameras, millimeter-wave radars, lidars, and ultrasonic radars. SANTA CLARA, Calif., USA – Ambarella (NASDAQ: AMBA), a semicondu
[Automotive Electronics]
Ambarella launches AI domain controller CV3 series SoC, a single chip can achieve ADAS and L4 autonomous driving
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号