int main(void) { WDT_DISABLE; BC1MSET; USCIAB0RX_ISR_callbacks = rx_callbacks; uart_init(UART0, 1000000, 9600); uart_XLED_enable(UART0); uart_interrupt_enable(UART0); P1DIR &= ~BUTTON; P1REN |= BUTTON; P1OUT |= BUTTON; qputs(UART0, "Inited.\n"); json_handle a; while (1){ p = text; wait = 1; _BIS_SR(CPUOFF + GIE); wait = 0; *p = '\0'; if (P1IN & BUTTON) {// Key not pressed a = objTest(); } else { pos = 0; a = json_createObjectObj("root", json_createStringObj("response","cleared"), NULL); } json_dump(text, a); json_free_rude(a); // int i; // qputh(_uart1, 0xff & (pos >> 8)); // qputh(_uart1, 0xff & (pos)); // qputc(_uart1,'\n'); // for (i=0;i<PERIOD_LENGTH/2;i++){ // // //qputs(_uart1, " 0x"); // qputh(_uart1, 0xff & (data[pos+i] >> 8)); // qputh(_uart1, 0xff & data[pos+i]); // } // qputs(_uart1, "\n============\n"); // base64enc(text, &data[pos], PERIOD_LENGTH); qputs(UART0, text); qputc(UART0, '\n'); //__delay_cycles(800000); } }
void main(){ WDT_DISABLE; // ucs_DCOFreq_set(1100000); uart_init(UART1, 1100000, 9600); uart_XLED_enable(UART1); i2c_XLED_enable(I2C0); i2c_slave_addr_setter(I2C0, 0x51); //PCF8563 RTC HW addr i2c_init(I2C0, 1100000, 400000, 1); //@400kHz qprintf(UART1, "Inited!\n"); while (1){ /* 1. get data by read register from i2c device with no delay */ char sec = i2c_reg8_read8(I2C0, 0x02); qputc(UART1, sec & 0x7f); // MSb = VL> see PCF8563 datasheet qputc(UART1,'\n'); /* 2. read multiple data with uncertain length */ char x[10] = {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x00}; x[0] = 0x02; i2c_write( I2C0, x, 1); // write 1 byte starting from x[0] char *s = i2c_read(I2C0, x, 2); // read 2 byte with LSB = x[0] qputs(UART1, s); // normally s = &x[1] __delay_cycles(100000); } }
// create or display environment variables or aliases int set_cmd( int argc, char **argv ) { char *arg; long fSet; PCH feptr, pchList; char szBuffer[CMDBUFSIZ]; init_page_size(); // set the pointer to either the environment or the alias list if ( _stricmp( gpInternalName, SET_COMMAND ) == 0 ) { pchList = 0L; } else pchList = glpAliasList; // strip leading switches if (( GetSwitches( argv[1], "AMPR", &fSet, 1 ) != 0) || (( fSet & SET_READ ) && ( first_arg( argv[1] ) == NULL ))) return ( usage(( pchList == glpAliasList ) ? ALIAS_USAGE : SET_USAGE )); // check for master environment set if (( pchList == 0L ) && ( fSet & SET_MASTER )) pchList = glpMasterEnvironment; // read environment or alias file(s) if ( fSet & SET_READ ) return ( SetFromFile( argv[1], pchList, 0 )); // pause after each page if ( fSet & SET_PAUSE ) { gnPageLength = GetScrRows(); } if ( first_arg( argv[1] ) == NULL ) { if ( pchList == 0L ) pchList = glpEnvironment; // print all the variables or aliases for ( feptr = pchList; ( *feptr != '\0' ); feptr = next_env( feptr ) ) { more_page( feptr, 0 ); } if ( pchList == glpEnvironment ) { if (( arg = get_list( BEGINLIBPATH, pchList )) != 0L ) { sprintf( szBuffer, FMT_TWO_EQUAL_STR, BEGINLIBPATH, arg ); more_page( szBuffer, 0 ); } if (( arg = get_list( ENDLIBPATH, pchList )) != 0L ) { sprintf( szBuffer, FMT_TWO_EQUAL_STR, ENDLIBPATH, arg ); more_page( szBuffer, 0 ); } } // return an error message if no aliases exist // just return if no environment variables exist return (( feptr == glpAliasList ) ? error( ERROR_4DOS_NO_ALIASES, NULL ) : 0 ); } if ( fSet & SET_EXPRESSION ) { if (( arg = strchr( argv[1], '=' )) != NULL ) arg = skipspace( ++arg ); else arg = argv[1]; evaluate( arg ); if ( cv.bn < 0 ) qputs( arg ); // create/modify/delete a variable return (( arg == argv[1] ) ? 0 : add_list( argv[1], pchList )); } // display the current variable or alias argument? // (setting environment vars requires a '='; it's optional with aliases) if ((( arg = strchr( argv[1], '=' )) == NULL ) && (( pchList == 0L ) || ( ntharg( argv[1], 1 ) == NULL ))) { if (( feptr = get_list( argv[1], pchList )) == 0L ) { return ( error((( pchList == glpAliasList ) ? ERROR_4DOS_NOT_ALIAS : ERROR_4DOS_NOT_IN_ENVIRONMENT),argv[1])); } printf( FMT_FAR_STR_CRLF, feptr ); return 0; } // create/modify/delete a variable or alias return ( add_list( argv[1], pchList )); }
// create or display environment variables or aliases static int _fastcall __Set( LPTSTR pszCmdLine, TCHAR _far * pchList ) { LPTSTR pszArg; long fSet = 0L; TCHAR _far *lpszVars; init_page_size(); // set the pointer to the environment, alias, or function list // strip leading switches if (( pszCmdLine != NULL ) && ( *pszCmdLine == gpIniptr->SwChr )) { if ( GetSwitches( pszCmdLine, "AMPR", &fSet, 1 ) != 0 ) return USAGE_ERR; } // check for master environment set if (( pchList == glpEnvironment ) && ( fSet & SET_MASTER )) pchList = glpMasterEnvironment; // read environment or alias file(s) if ( fSet & SET_READ ) return ( SetFromFile( pszCmdLine, pchList, fSet & ( SET_DEFAULT | SET_SYSTEM | SET_USER | SET_VOLATILE ))); if ( setjmp( cv.env ) == -1 ) return CTRLC; // pause after each page if ( fSet & SET_PAUSE ) { gnPageLength = GetScrRows(); } if (( pszCmdLine == NULL ) || ( *(pszCmdLine = skipspace( pszCmdLine )) == _TEXT('\0'))) { // print all the variables or aliases for ( lpszVars = pchList; ( *lpszVars != _TEXT('\0') ); lpszVars = next_env( lpszVars ) ) { more_page( lpszVars, 0 ); } // return an error if no entries exist return (( lpszVars == pchList ) ? ERROR_LIST_EMPTY : 0 ); } if ( fSet & SET_EXPRESSION ) { if (( pszArg = strchr( pszCmdLine, _TEXT('=') )) != NULL ) { if (( pszArg > pszCmdLine ) && ( strchr( _TEXT("+-*/%&^|><"), pszArg[-1] ) != NULL )) { TCHAR szBuf[256]; // it's an assignment operator ("set /a test+=2") sscanf( pszCmdLine, _TEXT(" %[^ +-*/%&^|><=]"), szBuf ); strcpy( pszArg, pszArg+1 ); strins( pszCmdLine, _TEXT("=") ); strins( pszCmdLine, szBuf ); pszArg = pszCmdLine + strlen( szBuf ) + 1; } else pszArg = skipspace( pszArg+1 ); } else pszArg = pszCmdLine; StripQuotes( pszArg ); evaluate( pszArg ); if ( cv.bn < 0 ) { qputs( pszArg ); crlf(); } // create/modify/delete a variable return (( pszArg == pszCmdLine ) ? 0 : add_list( pszCmdLine, pchList )); } // display the current variable or alias argument? // (setting environment vars requires a '='; it's optional with aliases) if ((( pszArg = strchr( pszCmdLine, _TEXT('=') )) == NULL ) && (( pchList == 0L ) || ( ntharg( pszCmdLine, 0x8001 ) == NULL ))) { if (( lpszVars = get_list( pszCmdLine, pchList )) == 0L ) { return ERROR_NOT_IN_LIST; } printf( FMT_FAR_STR_CRLF, lpszVars ); return 0; } // create/modify/delete a variable or alias return ( add_list( pszCmdLine, pchList )); }