Đề tài quét phím hiển thị lên LED:
#include <regx51.h>
#define PortRow P2
#define PortCol P3
#define LED P0
unsigned char PinRow[] = {0xE,0xD,0xB,0x7};
unsigned char Led7[] = {0x1,0x4f,0x12,0x6,0x4C,0x24,0x20,0xF,0x0,0x4,0x1} ;
//unsigned char PinCol[] = {0x4,0x2,0x1};
void delay1(int time)
{
int i,j;
for(i = 0; i<time;i++)
for(j = 0; j<time;j++)
{
;
}
}
unsigned char keyinput(){
if(P3_0 ==0) {return 0;}
if(P3_1 ==0 ) return 1;
if(P3_2 == 0) return 2;
if(P3_3 == 0) return 3;
else return 5;
}
/*Ham quet ban phim */
unsigned char keyscan(unsigned char numberrow,unsigned char numbercol)
{
unsigned char row,col;
for(row = 0;row < numberrow; row++)
{
P2 = PinRow[row];
#if 1
for(col= 0;col < numbercol; col++)
{
if(col == keyinput())
return(row*numbercol+ col);
else {
continue;
}
}
#endif
// delay1(200);
}
return 11;
}
void main(){
int i,key;
P3 = 0x0F;
P0 = 0;
P2 = 0;
LED = Led7[0];
while(1){
// for(i = 0;i<10;i++){
// LED = Led7[i];
// delay1(200);
// }
key = keyscan(4,3);
if(key != 11)
LED = Led7[key +1];
}
}
#include <regx51.h>
#define PortRow P2
#define PortCol P3
#define LED P0
unsigned char PinRow[] = {0xE,0xD,0xB,0x7};
unsigned char Led7[] = {0x1,0x4f,0x12,0x6,0x4C,0x24,0x20,0xF,0x0,0x4,0x1} ;
//unsigned char PinCol[] = {0x4,0x2,0x1};
void delay1(int time)
{
int i,j;
for(i = 0; i<time;i++)
for(j = 0; j<time;j++)
{
;
}
}
unsigned char keyinput(){
if(P3_0 ==0) {return 0;}
if(P3_1 ==0 ) return 1;
if(P3_2 == 0) return 2;
if(P3_3 == 0) return 3;
else return 5;
}
/*Ham quet ban phim */
unsigned char keyscan(unsigned char numberrow,unsigned char numbercol)
{
unsigned char row,col;
for(row = 0;row < numberrow; row++)
{
P2 = PinRow[row];
#if 1
for(col= 0;col < numbercol; col++)
{
if(col == keyinput())
return(row*numbercol+ col);
else {
continue;
}
}
#endif
// delay1(200);
}
return 11;
}
void main(){
int i,key;
P3 = 0x0F;
P0 = 0;
P2 = 0;
LED = Led7[0];
while(1){
// for(i = 0;i<10;i++){
// LED = Led7[i];
// delay1(200);
// }
key = keyscan(4,3);
if(key != 11)
LED = Led7[key +1];
}
}
Comment