rangerskm
Full Member level 4
- Joined
- Jan 23, 2013
- Messages
- 199
- Helped
- 0
- Reputation
- 2
- Reaction score
- 0
- Trophy points
- 1,296
- Activity points
- 2,663
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<pic.h>
#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;
}
//4 * 4 MATRIX CONNECTION FOR 4* 3 SWITCHES
//starting from on- 1 to 12
#include<pic.h>
#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;
}