dataXfer_echo.c - Demonstrates an echo program which includes usage of the data transfer protocolΒΆ

#include "pic24_all.h"
#include "dataXfer.h"
 

Indexes of all the variables to be transferred.

enum { U16_NUMCHARS_NDX, C_NDX };
 

Number of characters to print on each line.

#define CHARS_PER_LINE 10

int main(void) {
  char c;
  uint16_t u16_numChars = 0;
 

Initialize

  configBasic(HELLO_MSG);
  initDataXfer();
 

All variables received by the PIC must be specified. Params: Index Variable PC can change Format Description

  SPECIFY_VAR(U16_NUMCHARS_NDX, u16_numChars, TRUE,          "%hu",  "Number of characters received");
  SPECIFY_VAR(C_NDX,            c,            FALSE,         "%c",   "Character entered");

  while (1) {

For debug support, send the index and char received.

    sendVar(U16_NUMCHARS_NDX);
    sendVar(C_NDX);
 

Echo a character

    c = inCharXfer();
    outChar(c);
 

Add a CR every ref CHARS_PER_LINE

    if ((++u16_numChars % CHARS_PER_LINE) == 0)
      outChar('\n');
  }
}