TCPmaker : Visual Tour    Exploring and Customizing the Generated Code  

Let's customize the Receive Event Handler for D1. (It's really simple to do.)

We scroll down a bit further in the mtGen.c file until we find the section that holds the Receive Event Handlers for our variables, and we see this:

// (Receive) Event Handlers:
// =======================
// Each of the following routines is an Event Handler for its corresponding
// data transfer variable (declared above).
// When a particular data transfer variable is sent from the PC browser
// and has been received by this device, its particular Event Handler
// (below) will be called.
// Customize each routine to handle the data item that has just arrived:
// use it as a command to light an LED, turn on a motor, or whatever your
// application requires.
// See notes below on how to transmit a data item in the other direction:
// from the device to the PC browser.

// Event handler for variable: D1 - Diode D1 connected to RJ7
void eventD1(void)
  // Variable has just arrived, so add your code to DO something with it here:

  PORTJbits.RJ7 = D1; // Just add this single line, to light up the LED

We have shown above, in bold red type, the one single line that we had to add to our eventD1() Receive Event handler, in order to actually turn the correct LED on or off.

(For clarity, we have shown the specific hardware bit for this LED.  Since we made sure that file HardwareProfile.h was set up correctly for the PICDEM.net2 board, we could just as easily have used the constant LED7_IO that is #defined for this board in HardwareProfile.h.)

The important point to remember is that, by the time TCPmaker's code has called a Receive Event handler, the new value  that was sent from the PC has already been placed in the corresponding variable in the PIC code (D1 in this case). So, in order to light up the LED, all we had to do was just use the value in D1. 



8 of 21
Copyright Notice and Author Information