Code:
#include "REGX51.h"
#include "stdio.h"
#define zise 4
unsigned char count=0,scancode=0;
void delay60us(unsigned char temp1)//60us*25
{
while(temp1--)
{
TR0=1;
while(!TF0);
TR0=0;
TF0=0;
}
}
void inter_external(void) interrupt 0
{
scancode=scancode<<=1;
scancode|=P3_4;
count++;
}
unsigned char cover_to_ASCII(unsigned char temp)
{
unsigned char meg_scancode[36]={
0x45,0x16,0x1E,0x26,0x25,0x2E,0x36,0x3D,0x3E,0x46,
0x1C,0x32,0x21,0x23,0x24,0x2B,0x34,0x33,0x43,0x3B,
0x42,0x4B,0x3A,0x31,0x44,0x4D,0x15,0x2D,0x1B,0x2C,
0x3C,0x2A,0x1D,0x22,0x35,0x1A
},
meg_ASCII[36]={
48,49,50,51,52,53,54,55,56,57,
65,66,67,68,69,70,71,72,73,74,
75,76,77,78,79,80,81,82,83,84,
85,86,87,88,89,90
};
unsigned char i,test;
for(i=0;i<36;i++)
{
if(temp==meg_scancode[i])
{
test=1;
break;
}
else
test=0;
}
if(test)
return(meg_ASCII[i]);
else
return(32);
}
void main(void)
{
unsigned char meg_ABC[zise],temp2=0;
TMOD=0x02;
TH0=196;
TL0=0;
P2_1=1;//data
P3_2=1;//clock
P2_0=1;
while(1)
{
while(P2_0)
{
while(count<10)
{
EA=1;
EX0=1;
IT0=1;
}
EA=0;
meg_ABC[temp2]=cover_to_ASCII(scancode);
temp2++;
delay60us(25);
count=0;
}
//khoi hien thi
}
}
cảm ơn!

Comment