// print the event log information static int _SH_Log(void) { int i; char str[64]; UART_OutString("Event Log:\r\n"); for(i = 0; i < _eventIndex; i++) { unsigned long timeStamp = _eventLog[i].timestamp; sprintf(str, "switched to thread %d at %d us \r\n", _eventLog[i].type, timeStamp); UART_OutString(str); } /*switch(_eventLog[i].type) { case EVENT_FIFO_PUT: sprintf(str, "Fifo Put at %d us\r\n", timeStamp); break; case EVENT_FIFO_GET: sprintf(str, "Fifo Get at %d us\r\n", timeStamp); break; case EVENT_FIFO_WAIT: sprintf(str, "Wait on Fifo Semaphore at %d us\r\n", timeStamp); break; case EVENT_FIFO_WAKE: sprintf(str, "Acquired Fifo Semaphore at %d us\r\n", timeStamp); break; case EVENT_CONSUMER_RUN: sprintf(str, "Consumer thread switched to at %d us\r\n", timeStamp); break; case EVENT_CONSUMER_GOT: sprintf(str, "Consumer got data from fifo at %d us\r\n", timeStamp); break; case EVENT_OLED_START: sprintf(str, "Began writing to OLED at %d us\r\n", timeStamp); break; case EVENT_OLED_FINISH: sprintf(str, "Finished writing to OLED at %d us\r\n", timeStamp); break; case EVENT_THREAD + 0: sprintf(str, "Switched to thread %d at %d us\r\n", 0, timeStamp); break; case EVENT_THREAD + 1: sprintf(str, "Switched to thread %d at %d us\r\n", 1, timeStamp); break; case EVENT_THREAD + 2: sprintf(str, "Switched to thread %d at %d us\r\n", 2, timeStamp); break; case EVENT_THREAD + 3: sprintf(str, "Switched to thread %d at %d us\r\n", 3, timeStamp); break; default: sprintf(str, "Unrecognized event at %d us\r\n", timeStamp); break; } UART_OutString(str); }*/ return 0; }
void Xbee_Init(unsigned char ChannelNum){ unsigned char nextStep = 0; SysTick_Init(); // printf("Initializing...%c",NEWLINE); while(nextStep == 0){ UART_OutChar('x'); SysTick_Wait10ms(110);//wait 1.1ms UART_OutChar('+'); UART_OutChar('+'); UART_OutChar('+'); SysTick_Wait10ms(110);//wait 1.1ms nextStep = lookforCR(); } // printf("okay1%c",NEWLINE); nextStep = 0; while(nextStep == 0){ UART_OutString(ATCMD1); SysTick_Wait10ms(2); nextStep = lookforCR(); } // printf("okay2%c",NEWLINE); nextStep = 0; while(nextStep == 0){ UART_OutString(ATCMD2); SysTick_Wait10ms(2); nextStep = lookforCR(); } // printf("okay3%c",NEWLINE); nextStep = 0; while(nextStep == 0){ UART_OutString(ATCMD3); SysTick_Wait10ms(2); nextStep = lookforCR(); } // printf("okay4%c",NEWLINE); nextStep = 0; while(nextStep == 0){ UART_OutString(ATCMD4); SysTick_Wait10ms(2); nextStep = lookforCR(); } //printf("okay5%c",NEWLINE); nextStep = 0; while(nextStep == 0){ UART_OutString(ATCMD5); SysTick_Wait10ms(2); nextStep = lookforCR(); } // printf("okay6%c",NEWLINE); }
// do not edit this main // your job is to implement the UART_OutUDec UART_OutDistance functions int main(void){ unsigned long n; TExaS_Init(); // initialize grader, set system clock to 80 MHz UART_Init(); // initialize UART EnableInterrupts(); // needed for TExaS UART_OutString("Running Lab 11"); while(1){ UART_OutString("\n\rInput:"); n = UART_InUDec(); UART_OutString(" UART_OutUDec = "); UART_OutUDec(n); // your function UART_OutString(", UART_OutDistance ~ "); UART_OutDistance(n); // your function } }
void sendATCommand( char * command, int waitTime, char CRout){ char frame2[50]; char done = 0; char count = 0; int j = 0; int size; int commandLen = strlen2(command); for (j = 0; j < 50; j++) frame2[j] = 0; frame2[0] = 0; frame2[1] = 0; do{ UART_OutString(command); if (CRout) UART_OutChar(CR); Delay(500000*waitTime); j = 0; size = RxFifo_Size(); while (size>0){ frame2[j++] = UART_InChar(); size = RxFifo_Size(); // Delay(500000); } j = 0; while (frame2[j] != 'O') j++; if (frame2[j] == 'O' && frame2[j+1] == 'K' && frame2[j+2] == CR) done = 1; count++; } while (!done && count < 10); }
int main() { // unsigned char onechar = 'a'; PLL_Init(); PortA_Init(); PortC_Init(); SysTick_Init(); UART_Init(); // Зеленый светодиод выкл, PC9. Синий сетодиод вкл, PC8. Положительная логика GPIOC_BSRR = 0x2000100; while(1){ if((GPIOA_IDR & 0x1)){ // Проверяем нажатие кнопки, PA0. Положительная логика GPIOC_BSRR = 0x1000200; // Синий LED off. Зеленый LED on SysTick_Wait10ms(20); // задержка 200 мс GPIOC_BSRR = 0x3000000; // Синий LED off. Зеленый LED off SysTick_Wait10ms(20); // задержка 200 мс // UART_OutChar('a'); UART_OutString("Hello, World!"); // UART_OutString("28"); } else GPIOC_BSRR = 0x2000100; // Синий светодиод вкл. Зеленый сетодиод выкл } }
//debug code int main(void){ char ch; char string[20]; // global to assist in debugging uint32_t n; PLL_Init(Bus50MHz); // 50 MHz UART_Init(); // initialize UART OutCRLF(); for(ch='A'; ch<='Z'; ch=ch+1){// print the uppercase alphabet UART_OutChar(ch); } OutCRLF(); UART_OutChar(' '); for(ch='a'; ch<='z'; ch=ch+1){// print the lowercase alphabet UART_OutChar(ch); } OutCRLF(); UART_OutChar('-'); UART_OutChar('-'); UART_OutChar('>'); while(1){ UART_OutString("InString: "); UART_InString(string,19); UART_OutString(" OutString="); UART_OutString(string); OutCRLF(); UART_OutString("InUDec: "); n=UART_InUDec(); UART_OutString(" OutUDec="); UART_OutUDec(n); OutCRLF(); UART_OutString("InUHex: "); n=UART_InUHex(); UART_OutString(" OutUHex="); UART_OutUHex(n); OutCRLF(); } }
void XBeeInit(){ char * commands [] = {"ATDL66", "ATDH0", "ATMY6D", "ATAP1", "ATCN", ""}; int i = 0; int j; UART_Init(); while (RxFifo_Size()>0){ //flush FIFO UART_InChar(); } ID = 1; UART_OutString("x"); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); //SysTick_Wait10ms(110); //wait waitTime number of ms; sendATCommand("+++", 110, 0); //UART_InString(response, 5); //RIT128x96x4StringDraw(response, 10, 10 , 15); for (i=0;i<5;i++){ sendATCommand(commands[i], 20, 1); } SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); }
void XBeeInit(){ char * commands [] = {"ATDL66", "ATDH0", "ATMY6D", "ATAP1", "ATCN", ""}; int i = 0; int j; unsigned long i44 = 0; unsigned long j44 = 0; unsigned long delay = 110; // SysTick_Init(); UART_Init(); while (RxFifo_Size()>0){ //flush FIFO UART_InChar(); } ID = 1; UART_OutString("x"); // volatile unsigned long dummy = 0; for (i44 = 0; i44 < delay; i44++) for (j44 = 0; j44 < 150000; j44++); // dummy ++ ; //wait10ms(110); // Delay(5500000); //SysTick_Wait10ms(110); //wait waitTime number of ms; sendATCommand("+++", 110, 0); //UART_InString(response, 5); //RIT128x96x4StringDraw(response, 10, 10 , 15); for (i=0;i<5;i++){ sendATCommand(commands[i], 20, 1); } for (i44 = 0; i44 < delay; i44++) for (j44 = 0; j44 < 150000; j44++); // Delay(55000000); }
//-----------------------UART_OutDistance----------------------- // Output a 32-bit number in unsigned decimal fixed-point format // Input: 32-bit number to be transferred (resolution 0.001cm) // Output: none // Fixed format 1 digit, point, 3 digits, space, units, null termination void UART_OutDistance(unsigned long n){ UART_ConvertDistance(n); // convert using your function UART_OutString(String); // output using your function }
//-----------------------UART_OutUDec----------------------- // Output a 32-bit number in unsigned decimal format // Input: 32-bit number to be transferred // Output: none // Fixed format 4 digits, one space after, null termination void UART_OutUDec(unsigned long n){ UART_ConvertUDec(n); // convert using your function UART_OutString(String); // output using your function }
int main( void ) { unsigned long * ptr; unsigned char aux; unsigned int tempo = 500; IO_Init(); SysTick_Init_ms( tempo ); UART_Init_16MHz(); Nokia5110_Init(); Bluetooth_Init(); Nokia5110_OutString("SENAI"); for(;;) { if( UART_InCharAvailable() ) Bluetooth_OutChar( UART_InChar() ); if( Bluetooth_InCharAvailable() ) UART_OutChar ( aux = Bluetooth_InChar() ); if( SysTickRun() ) { if( *ptr ) *ptr = 0x00; else *ptr = 0xFF; } switch( aux ) { case 0: case 'R': *ptr = 0x00; ptr = (unsigned long *)&LED_RED; break; case 'B': *ptr = 0x00; ptr = (unsigned long *)&LED_BLUE; break; case 'G': *ptr = 0x00; ptr = (unsigned long *)&LED_GREEN; break; case 'Y': *ptr = 0x00; ptr = (unsigned long *)&LED_YELLOW; break; case 'P': *ptr = 0x00; ptr = (unsigned long *)&LED_PINK; break; case 'S': *ptr = 0x00; ptr = (unsigned long *)&LED_SKYBLUE; break; case 'W': *ptr = 0x00; ptr = (unsigned long *)&LED_WHITE; break; case 'D': *ptr = 0x00; ptr = (unsigned long *)&LED_DARK; break; case 'T': DHT11_In( (unsigned long *) &sensor ); UART_OutString( "Temp: " ); UART_OutUDec( (unsigned long)sensor.temperatura ); UART_OutString( "\r\n" ); Bluetooth_OutString( "Temp: " ); Bluetooth_OutUDec( (unsigned long)sensor.temperatura ); Bluetooth_OutString( "\r\n" ); SysTick_Init_ms( tempo ); break; case 'U': DHT11_In( (unsigned long *) &sensor ); UART_OutString( "Umidade: " ); UART_OutUDec( (unsigned long)sensor.umidade ); UART_OutString( "\r\n" ); Bluetooth_OutString( "Umidade: " ); Bluetooth_OutUDec( (unsigned long)sensor.umidade ); Bluetooth_OutString( "\r\n" ); SysTick_Init_ms( tempo ); break; } } //for(;;) } //int main( void )
void Interpreter(void) // just a prototype, link to your interpreter { uint32_t stringSize; uint32_t adcVoltage; uint8_t deviceChosen; uint8_t taskAddedBefore = 0; uint8_t commandChosen = -1; char message[MESSAGELENGTH] = ""; OutCRLF(); UART_OutString("Input Command: "); while(1){ OutCRLF(); //UART_OutString("Commands: 0 - ADC, 1 - LCD, 2 - Time"); OutCRLF(); commandChosen = UART_InChar(); switch(commandChosen) { case '0': OutCRLF(); UART_OutString("ADC Voltage = "); //ADC_Open(4); adcVoltage = (ADC_In() *3300) / 4095; //convert to mV UART_OutUDec(adcVoltage); OutCRLF(); break; case '1': OutCRLF(); UART_OutString("Enter LCD device 0 or 1: "); deviceChosen = UART_InUDec(); OutCRLF(); UART_OutString("Enter message: "); UART_InString(message, MESSAGELENGTH); OutCRLF(); stringSize = strlen(message); if(stringSize > 20) { OutCRLF(); UART_OutString("String too long..."); OutCRLF(); } LCD_test(deviceChosen, message); //prints to lcd OutCRLF(); break; case '2': if(!taskAddedBefore){ OS_AddPeriodicThread(dummy, 5, 1); taskAddedBefore = 1; } OutCRLF(); UART_OutUDec(OS_ReadPeriodicTime()); OutCRLF(); break; case '3': UART_OutString("NumSamples: "); UART_OutUDec(NumSamples); OutCRLF(); break; case '4': UART_OutString("Jitter: "); UART_OutUDec(MaxJitter); OutCRLF(); break; case '5': UART_OutString("DataLost: "); UART_OutUDec(DataLost); OutCRLF(); break; case '6': UART_OutString("FilterWork: "); UART_OutUDec(FilterWork); OutCRLF(); break; case '7': UART_OutString("NumCreated: "); UART_OutUDec(NumCreated); OutCRLF(); break; case '8': for(int i = 0; i<64; i++) { UART_OutUDec(x[i]); OutCRLF(); } break; default: UART_OutString("Incorrect command!"); break; } //adcSample = ADC_In(); //ST7735_SetCursor(0,0); //ST7735_OutUDec(adcSample); } }
// prints jitter information void SH_Jitter(void) { UART_OutString("Jitter Measurements:\r\n"); }
static void _SH_InCommand(char *bufPt, unsigned short max) { int length = 0; int space = 0; char character; char* startPt = bufPt; char* word = bufPt; character = UART_InChar(); while(character != CR && character != LF && character != CTRL_C){ if(character == ' ') { space = length; word = bufPt+1; } if(character == BS || character == DEL){ if(length){ bufPt--; length--; printf("\b \b"); } } else if(character == CTRL_L) { int i; printf("\f%s", _SH_getVar(SH_PROMPT_NAME)); for(i = 0; i < length; i++) UART_OutChar(startPt[i]); } else if(character == CTRL_U) { int i; for(i = 0; i < length + 1; i++) { printf ("\b \b"); } printf("%s", _SH_getVar(SH_PROMPT_NAME)); memset(startPt, 0, max); length = 0; bufPt = startPt; word = startPt; space = 0; } else if(character == '\t') { char fBuff[8]; if(space) // tab complete file name { char *c = fBuff; memcpy(fBuff, word, length - space); fBuff[length - space] = 0; strcpy(fBuff, SH_AutoCompleteFile(fBuff, length - space - 1)); while(*c) { *bufPt = *c; bufPt++; length++; UART_OutChar(*c++); } } else // tab complete command name { char *c = fBuff; memcpy(fBuff, startPt, length); fBuff[length] = 0; strcpy(fBuff, SH_AutoCompleteCommand(fBuff, length)); while(*c) { *bufPt = *c; bufPt++; length++; UART_OutChar(*c++); } } } else if(character == 0x42 && length > 1 && startPt[length-1] == 0x5B && startPt[length-2] == 0x1B) // down arrow { int i; printf("%c%c%c%c", 0x41, 0x1B, 0x5B, 0x42); if(!_SH_History[(index+1)&(SH_HISTORY-1)][0]) { length -= 2; bufPt -= 2; character = UART_InChar(); continue; } for(i = 0; i < length - 2; i++) { printf ("\b \b"); } printf("\r"); index = (index + 1) % SH_HISTORY; length = strlen(_SH_History[index]); strcpy(startPt, _SH_History[index]); bufPt = startPt; word = startPt; space = 0; UART_OutString(_SH_getVar(SH_PROMPT_NAME)); for(; bufPt < startPt + length; bufPt++) { UART_OutChar(*bufPt); if(*bufPt == ' ') { space = 1; word = bufPt+1; } } } else if(character == 0x41 && length > 1 && startPt[length-1] == 0x5B && startPt[length-2] == 0x1B) // up arrow { int i; printf("%c%c%c%c", 0x41, 0x1B, 0x5B, 0x42); if(!_SH_History[(index-1)&(SH_HISTORY-1)][0]) { length -= 2; bufPt -= 2; character = UART_InChar(); continue; } for(i = 0; i < length - 2; i++) { printf ("\b \b"); } printf("\r"); index = (index - 1) % SH_HISTORY; length = strlen(_SH_History[index]); strcpy(startPt, _SH_History[index]); bufPt = startPt; word = startPt; space = 0; UART_OutString(_SH_getVar(SH_PROMPT_NAME)); for(; bufPt < startPt + length; bufPt++) { UART_OutChar(*bufPt); if(*bufPt == ' ') { space = 1; word = bufPt+1; } } } else if(length < max){ *bufPt = character; bufPt++; length++; UART_OutChar(character); } character = UART_InChar(); } if(character == CTRL_C) *startPt = 0; *bufPt = 0; if(*startPt) { strcpy(_SH_History[index], startPt); index = (index + 1)&(SH_HISTORY-1); } }
//------------UART_OutStringNL------------ // Runs UART_OutString() and begins a new line. // Input: pointer to a NULL-terminated string to be transferred // Output: none void UART_OutStringNL(char *pt){ UART_OutString(pt); UART_OutCRLF(); }