int keyboard_scan();
volatile char *dir,*porta,*portc,*portf,*portk;
void setup() {
// put your setup code here, to run once:
dir = 0x21;
*dir = 0xff;
dir = 0x27;
*dir = 0xff;
dir = 0x30;
*dir = 0x00;
dir = 0x107;
*dir = 0x0f;
porta = 0x22;
portc = 0x28;
portf = 0x2f;
portk = 0x108;
char val[] = {0x00,0x06,0x5b,0x4f,0x00,0x66,0x6d,0x7d,0x00,0x07,0x7f,0x6f,0x00,0x00,0x3f,0x00,0x00};
char indxs[4];
char pos,index,flag = 0;
while(1)
{
index = keyboard_scan();
if(index != 0)
{
indxs[flag] = index;
flag++;
delay(200);
}
if(flag == 4)
{
while(1)
{
for(volatile long i = 0;i < 4;i++)
{
*portc = ~(1 << i);
*porta =val[indxs[i]];
*porta = 0x00;
}
}
}
// delay(1000);
}
}
int keyboard_scan()
{
for(char j = 0 ;j < 4;j++)
{
*portk = 1 << j;
if((*portf & 0x0f) != 0)
{
if((*portf & 0x0f) == 0x01)
return j * 4 + 1;
else if((*portf & 0x0f) == 0x02)
return j * 4 + 2;
else if((*portf & 0x0f) == 0x04)
return j * 4 + 3;
else if(*portf & 0x0f == 0x08)
return j * 4 + 4;
}
}
return 0;
}