void main() { auto int nIn1, nIn2; auto char cOut; brdInit(); //initialize board for this demo serCopen(_232BAUD); serBopen(_232BAUD); serCwrFlush(); serCrdFlush(); serBwrFlush(); serBrdFlush(); serMode(0); //enable serial device while (1) { for (cOut='a';cOut<='z';++cOut) { serCputc (cOut); // Send lowercase byte while ((nIn1=serBgetc()) == -1); // Wait for echo serBputc (toupper(nIn1)); // Send the converted upper case byte while ((nIn2=serCgetc()) == -1); // Wait for echo printf ("Serial C sent %c, serial B sent %c, serial C received %c\n", cOut, toupper(nIn1), nIn2); } } }
main() { auto int nIn1, nIn2; auto char cOut; serCopen(_232BAUD); serDopen(_232BAUD); serCwrFlush(); serCrdFlush(); serDwrFlush(); serDrdFlush(); while (1) { for (cOut='a';cOut<='z';++cOut) { serCputc (cOut); // Send lowercase byte while ((nIn1=serDgetc()) == -1); // Wait for echo serDputc (toupper(nIn1)); // Send the converted upper case byte while ((nIn2=serCgetc()) == -1); // Wait for echo printf ("Serial C sent %c, serial D sent %c, serial C received %c\n", cOut, toupper(nIn1), nIn2); } } }
void initGPS() { //memset(gps.gps_string, 0x00, MAX_SENTENCE); string_pos = 0; serCopen(BAUDGPS); // Flush Buffers serCwrFlush(); serCrdFlush(); writeGPSString("$PGRMO,GPRMC,2"); //Disable all strings writeGPSString("$PGRMO,GPRMC,1"); //enable GPRMC string //writeGPSString("$PGRMC1,1,2,2,,,,2,W,N,,,,1"); writeGPSString("$PGRMC1,1,1,2,,,,2,W,N,,,,1"); //enable NMEA 0183 2.3 writeGPSString("$PGRMI,,,,,,,R"); writeGPSString("$PGRMO,GPGSA,1"); //get sat info printf("using garmin GPS\n"); }
void main() { //This is necessary for initializing RS232 functionality //of LP35XX boards. #if _BOARD_TYPE_ == 0x1200 || _BOARD_TYPE_ == 0x1201 brdInit(); #endif bytesreceived = 0; bytessent = 0; // Initialize internal OS data structures OSInit(); // Create the three tasks with no initial data and 512 byte stacks OSTaskCreate(task0, NULL, 512, 0); OSTaskCreate(task1, NULL, 512, 1); OSTaskCreate(task2, NULL, 512, 2); // open serial port and set baud rate serCopen(2400); // clear rx and tx data buffers serCrdFlush(); serCwrFlush(); // create semaphore used by task1 serCsem = OSSemCreate(0); // display start message printf("*********************************\n"); printf("Start\n"); printf("*********************************\n"); // begin multi-tasking (execution will be transferred to task0) OSStart(); }
void main() { auto int nIn; auto char cOut; auto char inkey; brdInit(); keypadDef(); serCopen(_232BAUD); serMode(0); serCwrFlush(); serCrdFlush(); while (1) { costate { // Process Keypad Press/Hold/Release keyProcess(); waitfor(DelayMs(10)); } costate { if ((inkey = keyGet()) != 0) { // Wait for Keypress dispPrintf ("%c", inkey); // Display Byte serCputc(inkey); // Transmit byte } waitfor(DelayMs(10)); } costate { if ((nIn=serCgetc()) != -1) // Wait for receive byte dispPrintf ("%c", nIn); // Display Byte waitfor(DelayMs(10)); } } }
void main() { int c,i,n,g, rvalue; auto int nIn; auto char cOut; brdInit(); serCopen(9600); // serPORT(9600); //serCopen(BAUDGPS); serMode(0); serCrdFlush();// main loop serCwrFlush(); serCrdFlush(); serCputc('t'); serCputc('e'); printf("starting the loop"); memset(sentence,0x00,sizeof(sentence)); while(1) { c = serCgetc(); if( c == -1){ printf("nothing recieved\n"); } else{ printf("recieved: %c\n",serCgetc()); } // this costate will check if the GPS has sent some data or not and // call the appropriate functions to process the data costate GPSRead always_on { // wait until gps mode is engaged and a gps string has been recieved waitfor(serCrdUsed() > 0); //printf("gps read: "); // read until finding the beginning of a gps string then wait while(1) { //int test2; c = serCgetc(); printf("%c\n",c); if (c == -1) { serCrdFlush(); abort; } else { i = 0; sentence[i++] = c; waitfor(DelayMs(10)); //should only take 5ms or so at 115200 baud break; } }//end while(1) // now that 20 ms have passed, read in the gps string (it must all // be there by now, since so much time has passed //serCwrFlush(); //serCrdFlush(); //serCrdFlush(); //i = 0; while((nIn=serCgetc()) != -1){ sentence[i++] = nIn; } for(n = 0; n<i;n++){ serCputc(sentence[n]); } sentence[i] = '\0'; printf("%s\n",sentence); memset(sentence,0x00,sizeof(sentence)); }//end costate }// end while(1) }//end main()
main() { auto int i, ch; auto char buffer[64]; //buffer used for serial data auto int sw1, sw2, led1, led2; static const char string1[] = {"This message has been Rcv'd from serial port D !!!\n\n\r"}; static const char string2[] = {"This message has been Rcv'd from serial port C !!!\n\n\r"}; //--------------------------------------------------------------------- // Initialize the controller //--------------------------------------------------------------------- brdInit(); //initialize board for this demo led1=led2=1; //initialize led to off value sw1=sw2=0; //initialize switch to false value // Initialize serial port D, set baud rate to 19200 serDopen(19200); serDwrFlush(); serDrdFlush(); // Initialize serial portC, set baud rate to 19200 serCopen(19200); serCwrFlush(); serCrdFlush(); // Clear data buffer memset(buffer, 0x00, sizeof(buffer)); printf("\nStart of Sample Program!!!\n\n\n\r"); //--------------------------------------------------------------------- // Do continuous loop transmitting data between serial ports D and C //--------------------------------------------------------------------- for(;;) { costate { if (pbRdSwitch(S2)) //wait for switch S2 press abort; waitfor(DelayMs(50)); if (pbRdSwitch(S2)) //wait for switch release { sw1=!sw1; abort; } } costate { if (pbRdSwitch(S3)) //wait for switch S3 press abort; waitfor(DelayMs(50)); if (pbRdSwitch(S3)) //wait for switch release { sw2=!sw2; abort; } } costate { // toggle DS1 upon valid S2 press/release if (sw1) { pbWrLed(DS1, ON); //turn on DS1 led sw1=!sw1; // Transmit an ascii string from serial port C to serial port D memcpy(buffer, string2, strlen(string2)); serCputs(buffer); memset(buffer, 0x00, sizeof(buffer)); // Get the data string that was transmitted by port C i = 0; while((ch = serDgetc()) != '\r') { // Copy only valid RCV'd characters to the buffer if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // Display ascii string received from serial port C printf("%s", buffer); // Clear buffer memset(buffer, 0x00, sizeof(buffer)); pbWrLed(DS1, OFF); //turn off DS1 } } costate { // toggle DS2 upon valid S3 press/release if (sw2) { pbWrLed(DS2, ON); //turn on DS2 led sw2=!sw2; // Transmit an ascii string from serial port D to serial port C memcpy(buffer, string1, strlen(string1)); serDputs(buffer); memset(buffer, 0x00, sizeof(buffer)); // Get the data string that was transmitted by serial port D i = 0; while((ch = serCgetc()) != '\r') { // Copy only valid RCV'd characters to the buffer if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // Display ascii string received from serial port D printf("%s", buffer); pbWrLed(DS2, OFF); //turn off DS2 } //endif } //endcostate } //endfor }
main() { auto int i, ch; auto char buffer[64]; //buffer used for serial data auto int sw1, sw2; static const char string1[] = {"This message has been Rcv'd from serial port C !!!\n\n\r"}; static const char string2[] = {"This message has been Rcv'd from serial port D !!!\n\n\r"}; sw1 = sw2 = 0; //initialize switch to false value // Initialize serial port C, set baud rate to 19200 serCopen(19200); serCwrFlush(); serCrdFlush(); // Initialize serial port D, set baud rate to 19200 serDopen(19200); serDwrFlush(); serDrdFlush(); // Clear data buffer memset(buffer, 0x00, sizeof(buffer)); printf("\nStart of Sample Program!!!\n\n\n\r"); //--------------------------------------------------------------------- // Do continuous loop transmitting data between serial ports C and D //--------------------------------------------------------------------- while(1) { costate { if (BitRdPortI(S2_PORT, S2_BIT)) //wait for switch press abort; waitfor(DelayMs(50)); if (BitRdPortI(S2_PORT, S2_BIT)) { //wait for switch release sw1 = !sw1; abort; } } costate { if (BitRdPortI(S3_PORT, S3_BIT)) //wait for switch press abort; waitfor(DelayMs(50)); if (BitRdPortI(S3_PORT, S3_BIT)) { //wait for switch release sw2 = !sw2; abort; } } costate { // toggle led upon valid switch press/release if (sw1) { sw1 = !sw1; // The switch is attached the the serial port, so we need to read // the junk it sends serCrdFlush(); // Transmit an ascii string from serial port D to serial port C memcpy(buffer, string2, strlen(string2)); serDputs(buffer); memset(buffer, 0x00, sizeof(buffer)); // Get the data string that was transmitted by port D i = 0; while((ch = serCgetc()) != '\r') { // Copy only valid RCV'd characters to the buffer if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // Display ascii string received from serial port D printf("%s", buffer); // Clear buffer memset(buffer, 0x00, sizeof(buffer)); } } costate { // toggle led upon valid switch press/release if (sw2) { sw2=!sw2; // The switch is attached the the serial port, so we need to read // the junk it sends serDrdFlush(); // Transmit an ascii string from serial port C to serial port D memcpy(buffer, string1, strlen(string1)); serCputs(buffer); memset(buffer, 0x00, sizeof(buffer)); // Get the data string that was transmitted by serial port C i = 0; while((ch = serDgetc()) != '\r') { // Copy only valid RCV'd characters to the buffer if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // Display ascii string received from serial port C printf("%s", buffer); } //endif } //endcostate } //endwhile }
void main() { auto int i, ch; auto char buffer[64]; //buffer used for serial data static const char string1[] = "Rcv'd data on serial port C from serial port B\n\r"; static const char string2[] = "Rcv'd data on serial port B from serial Port C\n\r"; brdInit(); //required for BL2000 series boards // initialize serial portB, set baud rate to 19200 serBopen(19200); serBwrFlush(); serBrdFlush(); // initialize serial portC, set baud rate to 19200 serCopen(19200); serCwrFlush(); serCrdFlush(); serMode(0); //required for BL2000 series bds...must be done after serXopen function(s) //clear data buffer memset(buffer, 0x00, sizeof(buffer)); printf("\nStart of Sample Program!!!\n\n\n\r"); for(;;) { //transmit an ascii string from serial port B to serial port C memcpy(buffer, string1, strlen(string1)); serBputs(buffer); memset(buffer, 0x00, sizeof(buffer)); //get the data string that was transmitted by serial port B i = 0; while((ch = serCgetc()) != '\r') { if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // display ascii string received from serial port B printf("%s", buffer); //transmit an ascii string from serial port C to serial port B memcpy(buffer, string2, strlen(string2)); serCputs(buffer); memset(buffer, 0x00, sizeof(buffer)); //get the data string that was transmitted by port C i = 0; while((ch = serBgetc()) != '\r') { if(ch != -1) { buffer[i++] = ch; } } buffer[i++] = ch; //copy '\r' to the data buffer buffer[i] = '\0'; //terminate the ascii string // display ascii string received from serial port C printf("%s", buffer); } }
void main() { auto int c, num_bytes, done; auto char *ptr; auto int parallel_counter, loop_counter; auto char buffer[256]; auto char s[256]; brdInit(); //required for BL2100 series boards c = 0; //initialize variables parallel_counter = 0; loop_counter = 0; done = FALSE; sprintf(s, "Character counter = %d", 0); //initialize for proper STDIO effects DispStr(2, 2, s); // display exit message DispStr(2, 5, "Press the ESC key in Hyperterminal to exit the program"); serCopen(BAUD_RATE); //set baud rates for the serial ports to be used serBopen(BAUD_RATE); serCwrFlush(); //clear Rx and Tx data buffers serCrdFlush(); serBwrFlush(); serBrdFlush(); serMode(0); //required for BL2100 series bds...must be done after serXopen function(s) while (!done) { loophead(); //required for single-user cofunctions costate //single-user serial cofunctions { // Wait for char from hyperterminal wfd c = cof_serBgetc(); // yields until successfully getting a character //do clean exit from costatement if(c == ESC) { //flag used to exit out of this WHILE loop and other costatements done = TRUE; //abort this costatement abort; } // send character to serial port C wfd cof_serBputc(c); // yields until c successfully put // wait for char from serial port C wfd c = cof_serCgetc(); // yields until successfully getting a character //send character back to hyperterminal wfd cof_serCputc(c); // yields until c successfully put waitfor(serCwrUsed() == 0); //demonstrates that the above cofunctions only yields to other costates //and not to the code within the same costatement section. sprintf(s, "Character counter = %d", ++loop_counter); DispStr(2, 2, s); } costate { // Abort this costatement if the done flag has been set if(done) { abort; //do clean exit of costatement } //execute code while waiting for characters from hyperterminal sprintf(s, "Parallel code execution counter = %d\r", parallel_counter++); DispStr(2, 3, s); } } // send program exit message serBputs("\n\n\rProgram Done...exiting"); // wait for memory data buffer, serial holding register, and shift // register all to become empty while (serBwrFree() != BOUTBUFSIZE); while((RdPortI(SBSR)&0x08) || (RdPortI(SBSR)&0x04)); // read data and send to hyperterminal num_bytes = serCread(buffer, sizeof(buffer), 5); buffer[num_bytes] = '\0'; serCwrite(buffer, strlen(buffer)); // wait for memory data buffer, serial holding register, and shift // register all to become empty while (serCwrFree() != COUTBUFSIZE); while((RdPortI(SCSR)&0x08) || (RdPortI(SCSR)&0x04)); //close the serial ports serCclose(); serBclose(); }