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); } }
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); } }
// process a single INI file static int IniFProc(LPTSTR fname, INIFILE *InitData, unsigned int fIgnoreSection) { LPTSTR arg; unsigned int line_num, SecFound = 0, CurrentSec = 0; int fh, nReturn = 0; TCHAR szBuffer[2048]; LPTSTR errmsg; if ( ++nNestLevel > MAX_INI_NEST ) { ini_error( E_NEST, InitData, fname, 1, NULLSTR ); nReturn = -1; goto IFProcExit; } // force ignore of sections that aren't ours fIgnoreSection |= 0x100; // open the INI file if ((fh = _sopen(fname, (O_RDONLY | O_BINARY), SH_DENYWR)) < 0) { nReturn = -1; goto IFProcExit; } // loop to process each line for ( line_num = 1; ( getline( fh, szBuffer, 2047, 0 ) > 0 ); line_num++ ) { // skip line if empty or all comment arg = skipspace( szBuffer ); if ((*arg == _TEXT('\0')) || (*arg == _TEXT(';'))) continue; // query if it was requested if ( InitData->INIQuery != 0 ) { WriteTTY(szBuffer); WriteTTY(INI_QUERY); query_prompt: switch (GetKeystroke(EDIT_BIOS_KEY | EDIT_ECHO | EDIT_ECHO_CRLF | EDIT_UC_SHIFT)) { case YES_CHAR: break; case NO_CHAR: continue; case INI_QUIT_CHAR: goto ini_done; case REST_CHAR: InitData->INIQuery = 0; break; case INI_EDIT_CHAR: egets( szBuffer, 2047, EDIT_BIOS_KEY | EDIT_ECHO ); break; default: qputc( STDOUT, BS ); honk(); goto query_prompt; } } // process the line, holler if any error if ((nReturn = IniLine(szBuffer, InitData, (fIgnoreSection & CurrentSec), 0, &errmsg)) > 0) ini_error( errmsg, InitData, fname, line_num , szBuffer ); // if no error, see if we have an included file to process else if (nReturn == -1) { // call ourselves recursively to process the included file if ( is_file( szBuffer )) (void)IniFProc( szBuffer, InitData, fIgnoreSection); else ini_error( E_INCL, InitData, fname, line_num, szBuffer ); // if no error, see if we found a section name } else if (nReturn < 0) { CurrentSec = -nReturn; // save section bit if section is one of ours if (CurrentSec & 0xFF) SecFound |= CurrentSec; } } ini_done: InitData->SecFlag = SecFound; // save sections found _close(fh); nReturn = 0; IFProcExit: --nNestLevel; return nReturn; }
// print the file on the default printer void ListPrintFile( void ) { register int i, n; int c, nRows, nBytesPrinted, nFH; long lTemp; POPWINDOWPTR wn; TCHAR szBuffer[MAXLISTLINE+1]; int fKBHit; // disable ^C / ^BREAK handling HoldSignals(); wn = wOpen( 2, 1, 4, strlen( LIST_PRINTING ) + 8, nInverse, LIST_PRINT_TITLE, NULL ); wn->nAttrib = nNormal; wClear(); sprintf( szBuffer, LIST_QUERY_PRINT, LIST_PRINT_FILE_CHAR, LIST_PRINT_PAGE_CHAR ); wWriteListStr( 0, 1, wn, szBuffer ); if ((( c = GetKeystroke( EDIT_ECHO | EDIT_UC_SHIFT | EDIT_BIOS_KEY )) == LIST_PRINT_FILE_CHAR ) || ( c == LIST_PRINT_PAGE_CHAR )) { // save start position lTemp = LFile.lViewPtr; // display "Printing ..." wWriteListStr( 0, 1, wn, LIST_PRINTING ); if (( nFH = _sopen((( gpIniptr->Printer != INI_EMPTYSTR ) ? gpIniptr->StrData + gpIniptr->Printer : _TEXT("LPT1") ), (_O_BINARY | _O_WRONLY | _O_CREAT), _SH_DENYNO, _S_IWRITE | _S_IREAD )) >= 0 ) { if ( setjmp( cv.env ) == -1 ) { _close( nFH ); return; } // reset to beginning of file if ( c == LIST_PRINT_FILE_CHAR ) ListSetCurrent( 0L ); else { nRows = GetScrRows(); ListSetCurrent( LFile.lViewPtr ); } // print the header (filename, date & time) qprintf( nFH, _TEXT("%s %s %s\r\n\r\n"), LFile.szName, gdate( 0 ), gtime( gaCountryInfo.fsTimeFmt ) ); do { // abort printing if a key is hit // kbhit() in DOS tries to read from STDIN, which screws // up a LIST /S pipe _asm { mov ah, 1 int 16h mov fKBHit, 1 jnz KBHDone mov fKBHit, 0 KBHDone: } if ( fKBHit && ( GetKeystroke( EDIT_NO_ECHO | EDIT_BIOS_KEY ) == ESC )) break; i = FormatLine( szBuffer, MAXLISTLINE, LFile.lViewPtr, &nBytesPrinted, TRUE ); LFile.lViewPtr += 16; // replace 0-31 with "." if ( lListFlags & LIST_HEX ) { for ( n = 0; ( n < i ); n++ ) { if ( szBuffer[n] < 32 ) szBuffer[n] = _TEXT('.'); } } if (( c == LIST_PRINT_PAGE_CHAR ) && ( nRows-- <= 0 )) break; } while (( nBytesPrinted > 0 ) && ( qprintf( nFH, _TEXT("%.*s\r\n"), i, szBuffer ) > 0 )); // print a formfeed qputc( nFH, _TEXT('\014') ); _close( nFH ); // restore start position LFile.lViewPtr = lTemp; ListSetCurrent( LFile.lViewPtr ); } else honk(); } wRemove( wn ); // enable ^C / ^BREAK handling EnableSignals(); }