TCPmaker : Visual Tour    Exploring and Customizing the Generated Code  

As we said before, TCPmaker helps you by providing helpful comments containing snippets of code: suggestions of what you might want to add to your project.

Now let's add look at code we will add to the mtEndOfMessage() event handler in our simple PICDEM.net2 project.  The lines of code we added are shown in red, and call routines that are supplied by TCPmaker in commented out form in file mtGen.c.  We activate these, and show these routines below, also in red.

  // Example of mtEndOfMessage event code --------------
    //
    // Call user defined setLedStates() routine:
    // set the LEDs to reflect the variables
    // setLedStates();
    //
    // Call user defined sendPotValue() routine:
    // only send the pot once each response
    // sendPotValue();

    // Call user defined sendPotValue() routine:
    // only send the temperature once each response
    // sendTemperatureValue();


  // *********  Add your custom mtEndOfMessage event code here:  *********
  // OK, we'll follow the above suggestions
  sendPotValue();
  sendButtons();
  sendTemperatureValue();


}  // mtEndOfMessage()

 

// CHANGED BY HAND: Enable this function
void sendButtons(void)
{
  unsigned char myButton;

  myButton = !BUTTON0_IO;
  if (myButton != Btn0) {
    Btn0 = myButton;
    Btn0TxFlag = 1;
    if (Btn0) {
      strcpypgm2ram(It1,"Button 0");
      It1TxFlag = 1;
    }
  }

  myButton = !BUTTON1_IO;
  if (myButton != Btn1) {
    Btn1 = myButton;
    Btn1TxFlag = 1;
    if (Btn1){
      strcpypgm2ram(It1,"Button 1");
      It1TxFlag = 1;
    }
  }

  myButton = !BUTTON2_IO;
  if (myButton != Btn2) {
    Btn2 = myButton;
    Btn2TxFlag = 1;
    if (Btn2){
      strcpypgm2ram(It1,"Button 2");
      It1TxFlag = 1;
    }
  }

  myButton = !BUTTON3_IO;
  if (myButton != Btn3) {
    Btn3 = myButton;
    Btn3TxFlag = 1;
    if (Btn3){
      strcpypgm2ram(It1,"Button 3");
      It1TxFlag = 1;
    }
  }

}  // sendButtons()

 

// CHANGED BY HAND: Enable this function
void sendPotValue(void)
{
  // AN2 should already be set up as an analog input
  ADCON0 = 0x09;  // ADON, Channel 2 (AN2)
    ADCON0bits.GO = 1;

    // Wait until A/D conversion is done
    while(ADCON0bits.GO);

  // AD converter errata work around (ex: PIC18F87J10 A2)
  #if !defined(__18F87J50) && !defined(_18F87J50)
    PRODL = ADCON2;
    ADCON2bits.ADCS0 = 1;
    ADCON2bits.ADCS1 = 1;
    ADCON2 = PRODL;
  #endif

  //Pot1 = ADRESL & 0xFF;
  //Pot1 |= (ADRESH << 8) & 0xF00;
  //Pot1 = Pot1 + (ADRESH << 8);
 
  Pot1 = ADRES;

  Pot1TxFlag = 1;

}  // sendPotValue()

 

// CHANGED BY HAND: Enable this function
void sendTemperatureValue(void)
{
  // AN1 should already be set up as an analog input
  ADCON0 = 0x0D;  // ADON, Channel 3 (AN3)
    ADCON0bits.GO = 1;

    // Wait until A/D conversion is done
    while(ADCON0bits.GO);

  // AD converter errata work around (ex: PIC18F87J10 A2)
  #if !defined(__18F87J50) && !defined(_18F87J50)
    PRODL = ADCON2;
    ADCON2bits.ADCS0 = 1;
    ADCON2bits.ADCS1 = 1;
    ADCON2 = PRODL;
  #endif

  //Degrees = ADRESL & 0xFF;
  //Degrees |= (ADRESH << 8) & 0xF00;
  //Degrees += (ADRESH << 8);
 
  Degrees = ADRES;

// need to convert to degrees here!

  DegreesTxFlag = 1;

}  // sendTemperatureValue()


 
  

20 of 21
Copyright Notice and Author Information