/***************************************************************************** ** Main Function main() ******************************************************************************/ int main (void) { /*** The main Function is an endless loop ****/ // Configure WDT to run from internal WD oscillator at about 8 kHz WDTInit(); init_timer16( 0, TIME_INTERVALmS * 10 ); enable_timer16( 0 ); /* Set LED pin to output and make sure it is off */ GPIOSetDir( LED_PORT, LED_BIT, 1 ); GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); // Check reset status for watchdog reset- if found, blink quickly if ((LPC_SYSCON->SYSRSTSTAT & 0x4) == 0x4) { LPC_SYSCON->SYSRSTSTAT |= 0x4; while( 1 ) { /* I/O configuration and LED setting pending. */ if ( (timer16_0_counter > 0) && (timer16_0_counter <= FAST_LED_TOGGLE_TICKS/2) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); } if ( (timer16_0_counter > FAST_LED_TOGGLE_TICKS/2) && (timer16_0_counter <= FAST_LED_TOGGLE_TICKS) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_ON ); } else if ( timer16_0_counter > FAST_LED_TOGGLE_TICKS ) { timer16_0_counter = 0; } } } else { // No watchdog reset- lets blink slowly while( 1 ) { /* I/O configuration and LED setting pending. */ if ( (timer16_0_counter > 0) && (timer16_0_counter <= LED_TOGGLE_TICKS/2) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); } if ( (timer16_0_counter > LED_TOGGLE_TICKS/2) && (timer16_0_counter <= LED_TOGGLE_TICKS) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_ON ); } else if ( timer16_0_counter > LED_TOGGLE_TICKS ) { timer16_0_counter = 0; } } } }
int main(void) { // variables char cmd[10]; int count = 0; // Initial LED_Init(); lcd_init(); lcd_clear(); init_serial(); while(1) { //reset values iTimeReset = -1; h = 0; m = 0; s = 0; for(i = 0;i<10;i++) cmd[i] = NULL; iNumber = getkey() - 48; // get number of characters lcd_clear(); // get command name to cmd while(1) { i = getkey(); c = i; cmd[count] = c; count++; if (count == 6 && isEqualString(cmd,"reset ")) { i = getkey(); // get time for reset iTimeReset = i - 48; c = i; cmd[count] = c; count++; } if (count == 7 && isEqualString(cmd,"gettime")) { // hour i = getkey() - 48; h += i*10; i = getkey() - 48; h += i; // minute i = getkey() - 48; m += i*10; i = getkey() - 48; m += i; // second i = getkey() - 48; s += i*10; i = getkey() - 48; s += i; } if (count == iNumber) { lcd_print(&cmd[0]); count = 0; break; } } if(iTimeReset != -1) { sendString("\r\nReseting..."); WDTInit(iTimeReset); } else if(isEqualString(cmd,"gettime")) { RTCInit(); UpdateTimer(h,m,s); } else if(isEqualString(cmd,"song")) { InitplaySong(); } else if(isEqualString(cmd,"0812090")) { sendString("\r\nChao ban Quang Dung"); } else if(isEqualString(cmd,"0812076")) { sendString("\r\nChao ban Ngoc Duy"); } } return 0; }