ric wrote:Replace all these:
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <p18f2550.h>
#include <xc.h>
#include <usart.h>
with just:
- Code: Select all
#include <xc.h>
That automatically brings in the correct processor file, and any required plib includes.
You rarely require stdio.h, or stdlib.h in an embedded project.
Entropy wrote:example getsUSART(message, 10); what is the procedure when the length of the string is not known? In this example it waits until I send him 10 characters/numbers.
Don't use getsUSART if you don't know the length.
You have a few choices. You could define some termination condition, e.g. a special character, or time for which no characters are received, and implement that yourself as you receive the characters one by one.
Or, you could use interrupts to receive each character, and place them into a circular FIFO buffer. Your non-interrupt code could send each character as soon as it is received.
Also note, this:
char message[] = "";
in combination with this
getsUSART(message, 10);
is a bug, as you have not allocated any space for the buffer. The declaration should have been
char message[10] = "";
and then later, ytou cannot do this
if (message!="") {
you can only directly compare single characters with an if(), you can't do a whole string. You have to use a function like strcmp(), and test the result of that.