HOLTEK MCU-4X4 keyboard using software scanning

Publisher:CuriousObserverLatest update time:2015-07-23 Source: 51heiKeywords:HOLTEK Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Function Description:

The 4X4 keyboard corresponds to 16 numbers from 0 to F. Pressing any key will display the corresponding number on the common anode seven-segment display.

Circuit Description:

        Circuit

 
 

        Port B of the HT46F49E is connected to a common anode seven segment display.

        Since a common anode seven-segment digital display is used, a resistor is connected in series to each pin of port B for voltage division. Because each segment of the seven-segment display can be regarded as a light-emitting diode, VCC is enough to burn out the segment, so a resistor should be connected in series to each segment to divide the voltage with the light-emitting diode to protect the seven-segment display.

        Port A of the HT46F49E is connected to a 4X4 keyboard. PA7-PA0 sends out a row scan code, one of the pins sends out 0, the rest send out 1, and PA7-PA4 send out 0 in turn. If a key is pressed, PA3-PA0 will receive the information of which key is pressed. Combining the row scan code of PA7-PA4 and the information of the key pressed by PA3-PA0 can determine which key is pressed.

      Complete program code download address: http://www.51hei.com/f/htjp.rar

program:

#include "HT46F49E.H"

const unsigned char number[]={

0x81,0xcf,0x92,0x86,

0xcc,0xa4,0xa0,0x8f,

0x80,0x84,0x88,0xe0,

0xb1,0xc2,0xb0,0xb8};

unsigned int key_code;

void scan_keypressed()

{

    unsigned int i,scan_code;

    scan_code=0xef;

    key_code=0;

    for(i=0;i<4;i++)

    {

        _pa=scan_code;

        if(_pa0==0)

            key_code=i*4+1;

        if(_pa1==0)

            key_code=i*4+2;

        if(_pa2==0)

            key_code=i*4+3;

        if(_pa3==0)

            key_code=i*4+4;

        _rl(&scan_code);

    }  

}

void scan_keyeleased()

{

    switch(key_code%4)

    {

        case 1:while(!_pa0);

            break;

        case 2:while(!_pa1);

            break;

        case 3:while(!_pa2);

            break;

        case 0:while(!_pa3);

            break;  

    }  

}

void main()

{

    unsigned int key_old,led;

    _pcc=0x00;

    _pbc=0x00;

    _pac=0x0f;

    led=0;

    _pb=number[0];

    while(1)

    {

        scan_keypressed();

        if(key_code>0)

        {

            key_old=key_code;

            _delay(20000);

            scan_keypressed();

            if(key_old==key_code)

            {

                scan_keyeleased();

                led=key_code-1;

                _pb=number[led];

            }

        }

    }

}
Keywords:HOLTEK Reference address:HOLTEK MCU-4X4 keyboard using software scanning

Previous article:HOLTEK MCU-Stopwatch
Next article:HOLTEK MCU-8LED Thunderbolt Light

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号