Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main(void)
- //-----------------------------------------------------------------------------------------------------
- // Purpose: The MCU comes here after Reset. It will set up UART0 for receive interrupts and
- // whatever is received will be echoed out the transmitter.
- // UART is set to 9600,N,8,1
- //
- // Rev: 1.0 Initial Release
- //
- // Notes: None
- //-----------------------------------------------------------------------------------------------------
- {
- int charCount = 0; // Declare variables to count characters and lines
- int lineCount = 1;
- char message[] = "\n\rRenesas checking in\n\r"; // Store message and its length
- int messCount = 23;
- int charIndex = 0;
- MCUInit();
- InitDisplay(""); // Initialize display
- InitUART(); // Initialize UART for serial comms
- //BNSPrintf(SERIAL_FILE_NUM, "\n\rUART0 Rx\n\r");
- LCD_write(CTRL_WR, CURSOR_MODE_INC); // Increment cursor position when a character is entered
- LCD_write(CTRL_WR, LCD_HOME_L1); // Set the cursor to be at the beginning of line 1 when the program starts
- LCD_write(CTRL_WR, LCD_CURSOR_BLINK); // Set the cursor to blink
- while(1){
- while(U0_DataValid == FALSE); // wait for a character to arrive
- U0_DataValid = FALSE; // clear the arrival flag
- U0RcvdChar = U0_in; // get the character
- if(U0_in != '!') // Check to see if character received is "!"
- {
- if(charCount == 8) // Check to see if the line on the LCD is full
- {
- charCount = 0; // set character count to 0
- if(lineCount == 1) // If the first line is the currently active line
- {
- lineCount = 2; // Make line 2 the active line
- LCD_write(CTRL_WR, LCD_HOME_L2); // Move cursor to line 2
- BNSPrintf(SERIAL_FILE_NUM,"%c", '\n'); // Send newline
- DisplayDelay(500); // Delay
- BNSPrintf(SERIAL_FILE_NUM,"%c", '\r'); // Send carriage return
- DisplayDelay(500); // Delay
- }
- else
- {
- lineCount = 1; // Make line 1 active
- LCD_write(CTRL_WR, LCD_HOME_L1); // Move cursor to line 1
- BNSPrintf(SERIAL_FILE_NUM,"%c", '\n'); // Send newline
- DisplayDelay(500); // Delay
- BNSPrintf(SERIAL_FILE_NUM,"%c", '\r'); // Send carriage return
- DisplayDelay(500); // Delay
- }
- }
- BNSPrintf(LCD_FILE_NUM,"%c",U0RcvdChar); // Echo received character to LCD
- charCount++; // Increment character count
- BNSPrintf(SERIAL_FILE_NUM,"%c",U0RcvdChar); // send character back to the serial port
- }
- else
- {
- charIndex = 0; // Start index at 0
- while(charIndex < messCount) // while the index is less than the length of the message
- {
- BNSPrintf(SERIAL_FILE_NUM,"%c", message[charIndex]); // Print one character at a time back to the terminal
- DisplayDelay(100); // Delay
- charIndex++; // increment the character index
- }
- DisplayDelay(200); // Delay after the last character
- }
- }
- }
Add Comment
Please, Sign In to add comment