int USARTPrintf(const char *fmt, ...) { static char s[100]; int ret; va_list ap; va_start(ap, fmt); ret = vsprintf(s, fmt, ap); USARTPutString(s); va_end(ap); return ret; }
static void ProcessIO(void) { char i; char temp_buff[10]; int read_temp; float real_temp,temp_count; //Get raw data from DS1820 convert(temp_buff); //Convert raw data to degree C in accorance with datasheet read_temp=((temp_buff[1]<<8) | temp_buff[0]) >> 1; temp_count=(float)(temp_buff[7] - temp_buff[6])/(float)temp_buff[7]; real_temp = ((float)read_temp-0.25)+temp_count; sprintf(AN1String,"%2.2f",real_temp); USARTPutString((BYTE*)AN1String); USARTPut(0x0D); USARTPut(0x0a); }
static void DisplayIPValue(IP_ADDR *IPVal, BOOL bToLCD) { char IPDigit[8]; #if defined(APP_USE_LCD) if ( bToLCD ) { /* * Erase second line. */ XLCDGoto(1, 0); XLCDPutROMString(blankLCDLine); } #endif /* * Rewrite the second line. */ #if defined(APP_USE_LCD) XLCDGoto(1, 0); #endif itoa(IPVal->v[0], IPDigit); #if defined(APP_USE_LCD) if ( bToLCD ) { XLCDPutString(IPDigit); XLCDPut('.'); } else #endif { USARTPutString((BYTE*)IPDigit); USARTPut('.'); } itoa(IPVal->v[1], IPDigit); #if defined(APP_USE_LCD) if ( bToLCD ) { XLCDPutString(IPDigit); XLCDPut('.'); } else #endif { USARTPutString((BYTE*)IPDigit); USARTPut('.'); } itoa(IPVal->v[2], IPDigit); #if defined(APP_USE_LCD) if ( bToLCD ) { XLCDPutString(IPDigit); XLCDPut('.'); } else #endif { USARTPutString((BYTE*)IPDigit); USARTPut('.'); } itoa(IPVal->v[3], IPDigit); #if defined(APP_USE_LCD) if ( bToLCD ) XLCDPutString(IPDigit); else #endif { USARTPutString((BYTE*)IPDigit); } }
void ExecuteMenuChoice(MENU_CMD choice) { char response[MAX_USER_RESPONSE_LEN]; IP_ADDR tempIPValue; IP_ADDR *destIPValue; USARTPut('\r'); USARTPut('\n'); USARTPutROMString(menuCommandPrompt[choice-'0'-1]); switch(choice) { case MENU_CMD_SERIAL_NUMBER: itoa(AppConfig.SerialNumber.Val, response); USARTPutString((BYTE*)response); USARTPut(')'); USARTPut(':'); USARTPut(' '); if ( USARTGetString(response, sizeof(response)) ) { AppConfig.SerialNumber.Val = atoi(response); AppConfig.MyMACAddr.v[4] = AppConfig.SerialNumber.v[1]; AppConfig.MyMACAddr.v[5] = AppConfig.SerialNumber.v[0]; } else goto HandleInvalidInput; break; case MENU_CMD_IP_ADDRESS: destIPValue = &AppConfig.MyIPAddr; goto ReadIPConfig; case MENU_CMD_GATEWAY_ADDRESS: destIPValue = &AppConfig.MyGateway; goto ReadIPConfig; case MENU_CMD_SUBNET_MASK: destIPValue = &AppConfig.MyMask; ReadIPConfig: DisplayIPValue(destIPValue, FALSE); USARTPut(')'); USARTPut(':'); USARTPut(' '); USARTGetString(response, sizeof(response)); if ( !StringToIPAddress(response, &tempIPValue) ) { HandleInvalidInput: USARTPutROMString(InvalidInputMsg); while( !USARTIsGetReady() ); USARTGet(); } else { destIPValue->Val = tempIPValue.Val; } break; case MENU_CMD_ENABLE_AUTO_CONFIG: AppConfig.Flags.bIsDHCPEnabled = TRUE; break; case MENU_CMD_DISABLE_AUTO_CONFIG: AppConfig.Flags.bIsDHCPEnabled = FALSE; break; case MENU_CMD_DOWNLOAD_MPFS: #if defined(MPFS_USE_EEPROM) DownloadMPFS(); #endif break; case MENU_CMD_QUIT: #if defined(MPFS_USE_EEPROM) SaveAppConfig(); #endif break; } }