/* DM&P Mity SoC Example Copyright (C) 2002 by DM&P. This example is from our GPIO example. It will show you how to write output to GPIO and read data from GPIO. We also use watchdog timer on M6117D. You can press button S1-S4 on development board to test reading function. */ #include #include /* Function to easily set GPIO */ void SetGpio(unsigned char index, unsigned char data) { outportb(0x22, index); outportb(0x23, data); } /* Function to easily read data from GPIO */ unsigned char GetGpio(unsigned char index) { outportb(0x22, index); return inportb(0x23); } /* Enable watchdog timer */ void EnableWatchdogTimer() { unsigned char c; unsigned long lTime; /* Initialize watchdog timer */ c = GetGpio(0x37); SetGpio(0x37, c & 0xbf); /* 4 seconds */ lTime = 0x8000L * 4; SetGpio(0x3b, (lTime >> 16) & 0xff); SetGpio(0x3a, (lTime >> 8) & 0xff); SetGpio(0x39, (lTime >> 0) & 0xff); /* System reset */ c = GetGpio(0x38); c &= 0x0f; c |= 0xd0; SetGpio(0x38, c); /* Enable watchdog timer */ c = GetGpio(0x37); c |= 0x40; SetGpio(0x37, c); } /* Disable watchdog timer */ void DisableWatchdogTimer() { unsigned char c = GetGpio(0x37); c &= ~(0x40); SetGpio(0x37, c); } /* Trigger watchdog timer */ void TriggerWatchdogTiemr() { unsigned char c = GetGpio(0x3c); SetGpio(0x3c, c | 0x40); } void main() { int i; /* unlock GPIO register for re-programming */ SetGpio(0x13, 0xc5); /* Enable watchdog timer */ EnableWatchdogTimer(); /* Set GPIO 15-0 as output */ SetGpio(0x4e, 0xff); SetGpio(0x4f, 0xff); while(1) { for(i = 0; i < 8; i++) { /* Trigger watchdog timer */ TriggerWatchdogTiemr(); /* Drive GPIO LEDs */ SetGpio(0x47, (1 << i)); SetGpio(0x4d, ~(1 << i)); /* Dump i, debug information */ outportb(0x80, i); delay(250); /* Set GPIO 15-12 as input to read key message */ SetGpio(0x4f, 0x0f); /* Check S1-S4 */ if((GetGpio(0x4c) & 0x80) == 0) printf("S4 pressed.\n"); else if((GetGpio(0x4c) & 0x40) == 0) printf("S3 pressed.\n"); else if((GetGpio(0x4c) & 0x20) == 0) printf("S2 pressed.\n"); else if((GetGpio(0x4c) & 0x10) == 0) printf("S1 pressed.\n"); /* Restore default setting */ SetGpio(0x4f, 0xff); } /* Press any key to quit program */ if(kbhit()) break; } /* Disable watchdog timer */ DisableWatchdogTimer(); /* lock GPIO register for end of programming */ SetGpio(0x13, 0x0); }