+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Full Member level 4
    Points: 1,882, Level: 10

    Join Date
    Jan 2013
    Posts
    199
    Helped
    1 / 1
    Points
    1,882
    Level
    10

    matrix keyboard not working with pic16f877a ??

    i tried to connect the matrix keyboard with pic16f877a .but its not working i dont know the mistakes in it.i used the internal pull up of pic ,but no use .can any one guide me in that

    //4 * 4 MATRIX CONNECTION FOR 4* 3 SWITCHES
    //starting from on- 1 to 12





    #include
    #define _XTAL_FREQ 20000000
    #define SEND_SER(data) TXREG=data+48;while(!TRMT);
    uartinit();
    int flag;

    void main()
    {
    TRISB=0XF0; // 4 lsb output and 4 msb inpt
    PORTB=0X0F;//4 lsb outputs hgh and msb inputs low
    //nRBPU=0;
    TRISD=0X00;
    PORTD=0X00;
    uartinit();
    while(1)
    {
    PORTB=0XF7;//for checking switch 1 2 3
    if(RB4==0)

    {
    __delay_ms(100);
    while(RB4==0);
    __delay_ms(100);
    PORTB=0XFF;
    SEND_SER(1);

    }
    if(RB5==0)
    { __delay_ms(150);
    SEND_SER(2);
    PORTD=0X00;
    }
    else if(RB6==0)

    {
    __delay_ms(150);
    SEND_SER(3);
    }
    PORTB=0XFB;//for checking switch 4 5 6

    if(RB4==0)
    {
    __delay_ms(150);
    PORTD=0X00;
    SEND_SER(4);

    }
    if(RB5==0)
    {

    __delay_ms(150);
    PORTD=0X00;
    SEND_SER(5);

    }
    if(RB6==0)
    {
    __delay_ms(150);
    SEND_SER(6)
    }
    PORTB=0XFD;//for checking switch 7 8 9
    if(RB4==0)
    {
    __delay_ms(150);
    SEND_SER(7)
    }
    if(RB5==0)
    {
    __delay_ms(150);
    SEND_SER(8)
    }
    if(RB6==0)
    {
    __delay_ms(150);
    SEND_SER(9)
    }
    PORTB=0XFE;//for checking switch 10 11 12
    if(RB4==0)
    {__delay_ms(150);
    SEND_SER(0)
    }
    if(RB5==0)
    {
    __delay_ms(150);
    SEND_SER('a'-48)
    }
    if(RB6==0)
    {__delay_ms(150);
    SEND_SER('b'-48)
    }


    }

    }
    uartinit()
    {
    SPBRG=129;
    BRGH=1;
    SYNC=0;
    SPEN=1;
    TXEN=1;
    }

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 29,643, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,863
    Helped
    1115 / 1115
    Points
    29,643
    Level
    41
    Blog Entries
    9

    Re: matrix keyboard not working with pic16f877a ??

    The algorithm above is not the usual one commonly used to scan matrix keyboards.
    Take a look on options bellow:


    http://search.edaboard.com/4x4-keyboard.html
    http://search.edaboard.com/pic16f877-4x4.html







    +++
    Last edited by andre_teprom; 16th December 2013 at 18:49.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



--[[ ]]--