Guest User

Untitled

a guest
Jan 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.04 KB | None | 0 0
  1. void main(void)
  2. //-----------------------------------------------------------------------------------------------------
  3. //  Purpose:    The MCU comes here after Reset.  It will set up UART0 for receive interrupts and
  4. //              whatever is received will be echoed out the transmitter.
  5. //              UART is set to 9600,N,8,1
  6. //
  7. //  Rev:    1.0     Initial Release
  8. //  
  9. //  Notes:          None    
  10. //-----------------------------------------------------------------------------------------------------
  11. {
  12.     int charCount = 0;                                          // Declare variables to count characters and lines
  13.     int lineCount = 1;
  14.     char message[] = "\n\rRenesas checking in\n\r";             // Store message and its length
  15.     int messCount = 23;
  16.     int charIndex = 0;
  17.     MCUInit();
  18.     InitDisplay("");                                            // Initialize display
  19.     InitUART();                                                 // Initialize UART for serial comms
  20.  
  21.     //BNSPrintf(SERIAL_FILE_NUM, "\n\rUART0 Rx\n\r");
  22.     LCD_write(CTRL_WR, CURSOR_MODE_INC);                        // Increment cursor position when a character is entered
  23.     LCD_write(CTRL_WR, LCD_HOME_L1);                            // Set the cursor to be at the beginning of line 1 when the program starts
  24.     LCD_write(CTRL_WR, LCD_CURSOR_BLINK);                       // Set the cursor to blink
  25.     while(1){
  26.         while(U0_DataValid == FALSE);                           // wait for a character to arrive
  27.         U0_DataValid = FALSE;                                   // clear the arrival flag
  28.         U0RcvdChar = U0_in;                                     // get the character
  29.        
  30.         if(U0_in != '!')                                        // Check to see if character received is "!"
  31.         {
  32.             if(charCount == 8)                                  // Check to see if the line on the LCD is full
  33.             {
  34.                 charCount = 0;                                  // set character count to 0
  35.                 if(lineCount == 1)                              // If the first line is the currently active line
  36.                 {
  37.                     lineCount = 2;                              // Make line 2 the active line
  38.                     LCD_write(CTRL_WR, LCD_HOME_L2);            // Move cursor to line 2
  39.                     BNSPrintf(SERIAL_FILE_NUM,"%c", '\n');      // Send newline
  40.                     DisplayDelay(500);                          // Delay
  41.                     BNSPrintf(SERIAL_FILE_NUM,"%c", '\r');      // Send carriage return
  42.                     DisplayDelay(500);                          // Delay
  43.                 }
  44.                 else
  45.                 {
  46.                     lineCount = 1;                              // Make line 1 active
  47.                     LCD_write(CTRL_WR, LCD_HOME_L1);            // Move cursor to line 1
  48.                     BNSPrintf(SERIAL_FILE_NUM,"%c", '\n');      // Send newline
  49.                     DisplayDelay(500);                          // Delay
  50.                     BNSPrintf(SERIAL_FILE_NUM,"%c", '\r');      // Send carriage return
  51.                     DisplayDelay(500);                          // Delay
  52.                 }
  53.             }
  54.             BNSPrintf(LCD_FILE_NUM,"%c",U0RcvdChar);            // Echo received character to LCD
  55.             charCount++;                                        // Increment character count
  56.             BNSPrintf(SERIAL_FILE_NUM,"%c",U0RcvdChar);         // send character back to the serial port
  57.         }
  58.         else
  59.         {
  60.             charIndex = 0;                                      // Start index at 0
  61.             while(charIndex < messCount)                        // while the index is less than the length of the message
  62.             {
  63.                 BNSPrintf(SERIAL_FILE_NUM,"%c", message[charIndex]);    // Print one character at a time back to the terminal
  64.                 DisplayDelay(100);                                      // Delay
  65.                 charIndex++;                                            // increment the character index
  66.             }
  67.             DisplayDelay(200);                                  // Delay after the last character
  68.         }
  69.     }
  70.        
  71. }
Add Comment
Please, Sign In to add comment