Research on the first two columns of CT107D development board matrix keys do not work

The schematic diagram of CT107D development board matrix key is as follows:

The 1-pin and 2-pin of CON3 are connected to form matrix keyboard.

//Classical matrix key processing function
unsigned char keyProcess(void)
{
    unsigned char keyTemp = 0;
    unsigned char keyValue = 0;
    unsigned char P3_Value = 0;

    P3 = 0xf0;
    if(P3 != 0xf0)
    {
        Delay15ms();
        if(P3 != 0xf0)
        {
            P3_Value = P3;
            switch(P3_Value)
            {
                case 0xe0:
                {
                    keyTemp = 1;
                }break;
                case 0xb0:
                {
                    keyTemp = 2;
                }break;
                case 0xd0:
                {
                    keyTemp = 3;
                }break;
                case 0x70:
                {
                    keyTemp = 4;
                }break;
            }
        }
    }

    P3 = 0x0f;
    if(P3 != 0x0f)
    {
        Delay15ms();
        if(P3 != 0x0f)
        {
            P3_Value = P3;
            switch(P3_Value)
            {
                case 0x0e:
                {
                    keyValue = keyTemp;
                }break;
                case 0x0b:
                {
                    keyValue = 4 + keyTemp;
                }break;
                case 0x0d:
                {
                    keyValue = 8 + keyTemp;
                }break;
                case 0x07:
                {
                    keyValue = 12 + keyTemp;
                }break;
            }
        }
    } 
    return keyValue;
}

When writing the key drive by the above-mentioned classic matrix keyboard scanning function, it is found that the two columns of keys controlled by P3^6 and P3^7 pins will not produce any effect no matter how you press them. Some people may think that this is the development board is broken. In fact, the development board is not broken, but P3^6 and P3^7 do not actually control the two columns of keys.
If you use the following code to write the matrix keyboard drive code, you can fully realize the function, the code is as follows:

sfr P4 = 0xC0;

sbit r1=P3^0;  
sbit r2=P3^1;
sbit r3=P3^2;
sbit r4=P3^3;

sbit c1=P4^4;
sbit c2=P4^2;
sbit c3=P3^5;
sbit c4=P3^4;

unsigned char keyProcess(void)
{
    unsigned char key_value;

    r1=0;
    r2=r3=r4=1;
    c1=c2=c3=c4=1;

    if(!c1) 
    {
        key_value=0;
    }
    else if(!c2) 
    {
        key_value=1;
    }
    else if(!c3) 
    {
        key_value=2;
    }
    else if(!c4) 
    {
        key_value=3;
    }

    r2=0;
    r1=r3=r4=1;
    c1=c2=c3=c4=1;

    if(!c1) 
    {
        key_value=4;
    }
    else if(!c2) 
    {
        key_value=5;
    }
    else if(!c3) 
    {
        key_value=6;
    }
    else if(!c4) 
    {
        key_value=7;
    }

    r3=0;
    r2=r1=r4=1;
    c1=c2=c3=c4=1;

    if(!c1) 
    {
        key_value=8;
    }
    else if(!c2) 
    {
        key_value=9;
    }
    else if(!c3) 
    {
        key_value=10;
    }
    else if(!c4) 
    {
        key_value=11;
    }

    r4=0;
    r2=r3=r1=1;
    c1=c2=c3=c4=1;

    if(!c1) 
    {
        key_value=12;
    }
    else if(!c2) 
    {
        key_value=13;
    }
    else if(!c3) 
    {
        key_value=14;
    }
    else if(!c4) 
    {
        key_value=15;
    }

    return key_value;
}

Surprisingly, the first and second columns of matrix keyboard are controlled by P4^4 pin and P4^2 pin. Why?
The matrix keyboard circuit connection of the Blue Bridge Cup development board is the same as that of the common development board. It uses P3 port, but the Blue Bridge Cup competition requires IAP15F2k61s2 chip which is transferred by IAP transfer board. This single chip has crystal oscillator built in and runs fast. Because it does not have p36 and P37 ports, p42 and p44 ports of the chip are used to replace it on the transfer board. Therefore, we need to change the address of the control pin during development.
Download address of final test program reference code:
http://download.csdn.net/download/qq_34706280/10260248

Tags: P4

Posted on Wed, 01 Apr 2020 05:33:22 -0700 by SmoshySmosh