/* * main */ int main( void ) { uint8_t myDataToSend[100]; prvSetupHardware(); enableSerial0(); xSerialPortInitMinimal(0, 115200, 250 ); vSerialPutString(0, "Starting up LPC23xx with FreeRTOS\n\r", 50); SCS |= 1; //Configure FIO // Initialize I2C0 I2Cinit(I2C0); xTaskCreate( i2ceepromtask, ( signed portCHAR * ) "i2ceepromtask", I2CTEST_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL ); /* Start the scheduler. */ vTaskStartScheduler(); /* Will only get here if there was insufficient memory to create the idle task. */ return 0; }
/*! \brief main program of the master Sets up the I2C device and ncurses ui. Reacts on the user input. \param argc \param argv[] \return int */ int main(int argc, char *argv[]) { int ch = 0; int i; //initialize an array of '#' which determines the maximum length of a bar for (i = 0; i<LENGTH+1; i++) row[i] = '#'; row[0] = 'a'; row[LENGTH] = '\0'; //Initialize I2C-device if (I2Cinit() != TRUE) { printf("Initializing I2C interface failed\n"); exit (1); } //Initialize ncurses initscr(); if(has_colors() == FALSE) { endwin(); printf("Your terminal does not support color\n"); exit(1); } start_color(); /* Start color */ init_pair(1, COLOR_BLUE, COLOR_BLUE); cbreak(); noecho(); //Initialize the duty cycles of the slave setAllChannels(); printScreen(); int inc = 1; /*!< Increment/Decrement per key press event */ //Wait for user input while(ch != 'q') { ch = getch(); switch(ch) { case '+':inc = 2; break; case '-':inc = -2; break; case '1': channel[0]+=inc; setSingleChannel(0); break; case '2': channel[1]+=inc; setSingleChannel(1); break; case '3': channel[2]+=inc; setSingleChannel(2); break; case '4': channel[3]+=inc; setSingleChannel(3); break; case 'a': channel[0]+=inc; channel[1]+=inc; channel[2]+=inc; channel[3]+=inc; setAllChannels(); break; } printScreen(); } endwin(); //Stop ncurses return 0; }
void main(void) { UINT8 i=0,j=0,k,t;//togflg = 1; OSCCON = 0b01111000; OSCTUNE = 0b00000000; SWDTEN = 0b01; UINT8 tholdcount; ANSELA = 0; ANSELB = 0; TRISA = 0; TRISB = 0; TRISC = 0; WDTCONbits.WDTPS = 0b01010; for ( j = 0 ; j < 8 ; j++ ) { debounc[j] = 0; threshold[j] = 0; cur_read[j] = 0; average[j] = 0; keystat[j]= 0;keycnt[j]= 0; } TRISCbits.TRISC5 = 0; // RC6 = TX out KEYSTATPIN = 1; capsensinit(); //Delay(5); setscanchannel(); channelno = 0;avgflag = 0; count = 0; usartinit(); I2Cinit(); if(STATUSbits.nTO == 0){ USARTWriteString(" reset ");} //else {tholdflg = 0;} //tholdflg = 0; tholdcount=0; max = 500; pos = 9; // TRISAbits.TRISA2 = 0; // LATAbits.LATA2 = 1; /* while(1) { USARTWriteChar('U'); } */ while(1) { CLRWDT(); /* if(togflg) { LATAbits.LATA2 = 0;//togflg; togflg = 0; } else { LATAbits.LATA2 = 1;//togflg; togflg = 1; } */ if(avgflag) { for( i = 0 ; i < 8 ; i++ ) { average[i] /= capsense_avg_cnt; /*USARTWriteInt(average[i],5); USARTWriteChar('\t'); if(i == 7) { USARTWriteChar('\n');USARTWriteChar('\r');}*/ if(tholdflg == 0) { if(tholdcount == 8) threshold[i] = 0; threshold[i] += average[i]; if ( i == 7 ) tholdcount++ ; if( tholdcount == 16 ) { for ( j = 0 ; j < 8 ; j++ ) threshold[ j ] >>= 3 ; tholdflg = 1; } } else { olddiff[i] = curdiff[i]; curdiff[i] = threshold[i] - average[i]; if ( curdiff[i] > olddiff[i] ) diff[i]= curdiff[i] - olddiff[i]; else diff[i]= olddiff[i]- curdiff[i]; if( diff[i] > max ) { max = diff[i]; pos = i; } //if( curdiff[i] > max ){ max = curdiff[i]; pos = i;} //USARTWriteInt(diff[i],5); //USARTWriteChar('\t'); if(i == 7) { //USARTWriteInt(pos,2); //USARTWriteChar(' '); //USARTWriteInt(diff[pos],5); //USARTWriteChar('\n');USARTWriteChar('\r'); for(t = 0; t < 8 ; t++) { if(t != pos) {if(keycnt[t])keycnt[t]--;keystat[t] =0;} else if( max > 600 ) { keycnt[t]++; if( keycnt[t] > 7 ) { for(k = 0 ; k < 8 ; k++) keycnt[k] = 0; keystat[t] = 1; } } else{ if(keycnt[t])keycnt[t]-- ; keystat[t] = 0;} USARTWriteInt(keycnt[t],1); } if( pos != 9 && debounc[pos] == 0 ) { debounc[pos] = 400; USARTWriteChar('\n'); USARTWriteString("Key Detected = "); i2c_tx_buff[ 0 ] = pos; KEYSTATPIN = 0; } USARTWriteInt(pos,2); //i2c_tx_buff[ 0 ] = pos; USARTWriteChar('\n');USARTWriteChar('\r'); max = 500; pos = 9; } //USARTWriteInt(keycnt[i],1); //USARTWriteChar('\t'); //if(i == 7){USARTWriteChar('\n');USARTWriteChar('\r');} //pos = i; /*USARTWriteInt(curdiff[i],5); USARTWriteChar('\t'); if(i == 7) { USARTWriteChar('\n');USARTWriteChar('\r');} if(curdiff[i] > 800){keycnt[i]++;} else if(curdiff[i] < 800){ keycnt[i]=0; keystat[i] = 0;} if(keycnt[i] == 8) keystat[i] = 1;*/ /*USARTWriteInt(keystat[i],1); USARTWriteChar('\t'); if(i == 7) { USARTWriteChar('\n');USARTWriteChar('\r');}*/ } } avgflag = 0 ; } }