Ms80c51 Keyboard Scan

Source: Internet
Author: User

// Ms80c51 <br/> // 4*4 Keyboard Scan <br/> // P2 ^ 1 ~ P2 ^ 3 connect to the keyboard row <br/> // P2 ^ 4 ~ P2 ^ 7 keyboard column <br/> // led_scan.h is the custom header file required for LED display <br/> # include "led_scan.h" <br/> # include <reg51.h> <br/> # define unchar unsigned char <br/> // returns the number of digits of special data 1 <br/> // If 00001000, 4 is returned, if 00000100 returns 3 <br/> unchar getlocation (unchar value) <br/>{< br/> unchar location = 0; <br/> If (value! = 0) <br/>{< br/> while (value) <br/>{< br/> location ++; <br/> value = value> 1; <br/>}< br/> return location; <br/>}< br/> void delay () <br/>{< br/> unsigned char a, B; <br/> for (a = 0; A <50; A ++) <br/> for (B = 0; B <100; B ++); <br/>}< br/> void main () <br/>{< br/> unchar ROW = 0; <br/> unchar column = 0; </P> <p> P2 = 0x0f; // 00001111 <br/> while (1) <br/>{< br/> If (P2! = 0x0f) <br/>{< br/> ROW = getlocation (~ (P2 | 0xf0); // locate the row of the pressed key <br/> P2 = 0xf0; // 11110000 <br/> If (P2! = 0xf0) <br/>{< br/> column = getlocation (~ (P2> 4) | 0xf0 )); // locate the column of the key to be pressed <br/>}< br/> else <br/>{< br/> ROW = 0; <br/> column = 0; <br/>}< br/> delay (); <br/> ledstore (row, column ); // load <br/> ledscan (); // LED display <br/> ROW = 0; <br/> column = 0; <br/> P2 = 0x0f; <br/>}< br/>}

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.