Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a) Write a C program that keeps taking inputs from a user until the user enters the character Z. The program should prompt the user

a) Write a C program that keeps taking inputs from a user until the user enters the character Z. The program should prompt the user to enter any character. If the user enters a number, the program should echo that number, i.e. it should print the number entered by the user. If the user enters a letter, the output should be based on the following table. For all characters not listed in the table, there should be no additional output I.e., nothing other than Please enter a character. Note that the switch-case-break is a good way to implement this, as you have some specific actions associated with a set of inputs.

b) Afterwards, use the following template as a starting point and take your C program and make appropriate modifications so that the input and output is done through the UART using PSoC Creator.

Template:

#include

#include

#include // contains strtod(), which converts an ASCII string to a double

int main()

{

char rxbuffer[100]; // UART receive buffer

int rxindex; // UART receive buffer index

double number; // floating-point number

uint8 ch; // variable to hold received character

// initialize and clear rxbuffer

for( rxindex = 0; rxindex < 100; rxindex++ ) {

rxbuffer[rxindex] = 0u;

}

rxindex = 0; // initialize rxindex

UART_Start(); // start UART

// printf( "COM OPEN! " );

UART_UartPutString( "COM OPEN! " );// display initialization string

// printf( "Type a number: " );

UART_UartPutString( "Type a number: " );

// read string until the user presses return

// scanf( "%s", rxbuffer );

while( ch != ' ' ) {

ch = UART_UartGetChar(); // get the next character

if( ch != ' ' && ch != 0u ) { // if the character is not a return or null

rxbuffer[rxindex] = ch; // store it in the rxbuffer string

rxindex++; // increment the rxbuffer index

}

}

// output the received string to the UART

// printf( " %s ", rxbuffer );

UART_UartPutChar(' ');

UART_UartPutString(rxbuffer);

UART_UartPutChar(' ');

// convert the received string to a double (floating-point number)

number = strtod( rxbuffer, 0 );

// initialize and clear rxbuffer (good practice to avoid bugs)

for( rxindex = 0; rxindex < 100; rxindex++ ) {

rxbuffer[rxindex] = 0u;

}

rxindex = 0; // initialize rxindex

// output the float as a string and store it in rxbuffer

// NOTE: In order to properly output doubles, you must enable them in the compiler

// See http://www.cypress.com/?id=4&rID=87354 for more details

sprintf( rxbuffer, "Converted from double = %lf ", number );

// output the new string to the UART

// printf( " %s ", rxbuffer );

UART_UartPutChar(' ');

UART_UartPutString(rxbuffer);

UART_UartPutChar(' ');

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Why is SIFS time shorter than DIFS time?

Answered: 1 week ago