thecall
Junior Member level 2
i wrote this prog for scanning key pad and displaying no on 7 seg display.i am using 2 rows and 2 col key pad. connected to RB4,RB5,RB6,RB7
and 7SEG connected to RA2,RA3,RA4,RB0,RB1,RB2,RB3
Now the problem is that how to on 7 seg like it s hlfly connected to port a and portb.
here is the prog
#define ROW1 portB.F6
#define ROW2 portB.F7
#define COL PORTB.F5
#define COL2 PORTB.F4
unsigned char scankeypad()
{
ROW1=0;
if(COL==0)
return 0x00;
else if (COL2==0)
return 0x01;
else;
ROW2=0;
if(COL==0)
return 0x04;
else if(COL2==0)
return 0x05;
else;
return 255;
}
void main()
{
unsigned char n[]={0x01,0x02,0x04,0x05} ;
TRISB.F4=1;
TRISB.F5=1;
TRISB.F6=1;
TRISB.F7=1;
TRISB.F1=0;
TRISB.F2=0;
TRISB.F3=0;
TRISA.F2=0;
TRISA.F3=0;
TRISA.F4=0;
unsigned char key=0;
key=scankeypad();
if (key==255)
{
continue;
}
else{
PORTB=n[key];
break;
}
}
and 7SEG connected to RA2,RA3,RA4,RB0,RB1,RB2,RB3
Now the problem is that how to on 7 seg like it s hlfly connected to port a and portb.
here is the prog
#define ROW1 portB.F6
#define ROW2 portB.F7
#define COL PORTB.F5
#define COL2 PORTB.F4
unsigned char scankeypad()
{
ROW1=0;
if(COL==0)
return 0x00;
else if (COL2==0)
return 0x01;
else;
ROW2=0;
if(COL==0)
return 0x04;
else if(COL2==0)
return 0x05;
else;
return 255;
}
void main()
{
unsigned char n[]={0x01,0x02,0x04,0x05} ;
TRISB.F4=1;
TRISB.F5=1;
TRISB.F6=1;
TRISB.F7=1;
TRISB.F1=0;
TRISB.F2=0;
TRISB.F3=0;
TRISA.F2=0;
TRISA.F3=0;
TRISA.F4=0;
unsigned char key=0;
key=scankeypad();
if (key==255)
{
continue;
}
else{
PORTB=n[key];
break;
}
}