Single Chip Microcomputer keyboard response C code

Source: Internet
Author: User
/* -- This code segment is common, after modification, you can complete the general keyboard setting operation response -- flystone 2006-02 -- repost and retain this information */# define scankey_t 40 # define delay_t 6 # define true 1 # define false 0 # define key_add 0x0e // (00001110) # define key_enter 0x0b // (00001011) # define key_mover 0x0d // (00001101) # define key_pw 0x07 // (00000111) these four keys are modified according to the keyboard definition // ------------------------------------------------------------------------- void scankey (void) {static unsigned char key; static Bit key_sta, key_down; static int delay_t; If (! Key_sta) {key = getkey (); If (Key = key_pw | key = key_enter | key = key_mover | key = key_add) key_sta = true ;} else {If (! Key_down) {If (Key = getkey () {key_down = true; currentkey = key; delay_t = 0;} else key_sta = false;} else {If (getkey () = 0x00) {key = 0x00; key_down = false; key_sta = false;} else {If (getkey () = Key) {delay_t + = 1; if (delay_t> = delay_t) {delay_t = 0; currentkey = Key ;}}}}// ------------------ custom timer -------------------------------- void intt2 () interrupt 7 // 1 ms {scankey ++; // 80 ms scan keyboard if (scankey >=scankey_t) {scankey = 0; scankey ();}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.