/* Przykladowy program w jezyku C, odczytujacy klawiature i wyswietlajacy jej stan na wyswietlaczu LCD. */ #define loopdelay 2000 #define ucvp(i) (unsigned char volatile *const)(i) extern void print(const char*); unsigned char volatile *const PGC = ucvp (0x00c00003); unsigned char volatile *const PAC = ucvp (0x00c0001b); unsigned char volatile *const PBC = ucvp (0x00c0001f); unsigned char volatile *const PADD = ucvp (0x00c0000B); unsigned char volatile *const PBDD = ucvp (0x00c0000F); unsigned char volatile *const PCDD = ucvp (0x00c00013); unsigned char volatile *const PAD = ucvp (0x00c00023); unsigned char volatile *const PBD = ucvp (0x00c00027); unsigned char volatile *const PCD = ucvp (0x00c00033); unsigned char volatile *const PBA = ucvp (0x00c0002f); char * spr (unsigned char value) { static char buffer[5]; int v = (value >> 4) & 0xf; if (v > 9) v += 'a' - '0' - 10; buffer[0] = v + '0'; v = (value) & 0xf; if (v > 9) v += 'a' - '0' - 10; buffer[1] = v + '0'; buffer[2] = 0; return buffer; }; void dispins (unsigned char data) { int i; *PBD = 0xC0 | 0x20; *PAD = data; for (i = 0; i < loopdelay; i++); *PBD = 0xC0 | 0x00; }; void dispdata (unsigned char data) { int i; *PBD = 0xC0 | 0x30; *PAD = data; for (i = 0; i < loopdelay; i++); *PBD = 0xC0 | 0x00; }; void dispstring (char *string) { int i; dispins (0x80 | 0); for (i = 0; i < 8; i++) dispdata (string[i]); dispins (0x80 | 0x40); for (i = 8; i < 16; i++) dispdata (string[i]); }; int main () { int val, i, j; char kbstate[17]; kbstate[16] = 0; *PGC = 0x00; *PAC = 0x00; *PBC = 0x80; *PADD = 0xFF; *PBDD = 0xF0; *PCDD = 0x03; *PBD = 0xC0; *PCD = 0xFE; i = 0; /* display init*/ /* set 8-bit mode */ dispins (0x30 | 0x08); for (i = 0; i < loopdelay * 32; i++); dispins (0x30 | 0x08); for (i = 0; i < loopdelay * 32; i++); dispins (0x30 | 0x08); for (i = 0; i < loopdelay * 32; i++); dispins (0x01); dispins (0x0c); /*end of display init*/ dispstring ("12345678abcdefgh"); while (1) { for (val = 1, i = 0; val < 16; val <<= 1, i += 4) { *PAD = 0xf0 | ((~val) & 0xf); j = *PBA; kbstate[i + 0] = (j & 1) ? '0' : '1'; kbstate[i + 1] = (j & 2) ? '0' : '1'; kbstate[i + 2] = (j & 4) ? '0' : '1'; kbstate[i + 3] = (j & 8) ? '0' : '1'; } dispstring (kbstate); print ("\r"); print (kbstate); }; };