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 pos,index;
while(1)
{
index = keyboard_scan();
if(index != 0)
{
for(volatile long i = 0;i<40000;i++)
{
*portc = 0xfe;
*porta =0x3f;
*porta = 0x00;
*portc = 0xfd;
*porta = val[index];
*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;
}