Beispiel #1
0
void putsLCD(char *s) {
    char c;
    while (*s) {
        switch (*s) {
            case '\n':      // point to second line
                setLCDC(0x40);
                break;
            case '\r':      // home, point to first line
                setLCDC(0);
                break;
            case '\t':      // advance next tab (8) positions
                c = addrLCD();
                while (c & 7) {
                    putLCD(' ');
                    c++;
                }
                if (c > 15) // if necessary to move to second line
                    setLCDC(0x40);
                break;
            default:        // print character
                putLCD(*s);
                break;
        }
        s++;            // point to next character
        delayTimer1(30);// Increase if characters are dropped
    }
}
Beispiel #2
0
void LCD_only_out(char String[128])
{
    setLCDC(0x00); // point to 1st line
  Delayms(200);
    putsLCD(String);
  Delayms(2000);
}
Beispiel #3
0
void LCD_and_Console_out(char String[128])
{
    putsConsole(String);
    setLCDC(0x00); // point to 1st line
  Delayms(200);
    putsLCD(String);
  Delayms(2000);
}
Beispiel #4
0
int main(void)
{
unsigned char   temp1, temp2, temp3;
unsigned char   iloop, jloop;
char            CharChoice;
char            ADC_read;
char            Buttons;
char            ssid_size;
bool            flash, finish;

unsigned char   ChanSel, ChanTime;
unsigned char   Channel[7];
unsigned char   NewChannel[7];
unsigned char   charWiFlyMsgLen;
bool            MsgGood, MsgSame;


    InitializeSystem();
    AssociatedCheck = 0;
    initAllIndicators();

    for (jloop = 0; jloop <=6; jloop++)
      {
        Channel[jloop] = 0;
        NewChannel[jloop] = 1;
      }



    LED_D3 = 1;
  Delayms(1000);
    LED_D3 = 0;
    LED_D4 = 1;
  Delayms(1000);
    LED_D4 = 0;
    LED_D5 = 1;
  Delayms(1000);
    LED_D5 = 0;
    LED_D6 = 1;
  Delayms(1000);
    LED_D6 = 0;
    LED_D7 = 1;
  Delayms(1000);
    LED_D7 = 0;
    LED_D8 = 1;
  Delayms(1000);
    LED_D8 = 0;
    LED_D9 = 1;
  Delayms(1000);
    LED_D9 = 0;

    sprintf(OutString, "WiFly Pass_thru\nDemo");
    putsLCD(OutString);
    // JKW starts here
  Delayms(5000);
    sprintf(OutString,"$$$");
    putsWiFly(OutString);
    putsConsole(OutString);

    sprintf(OutString, "                \n                ");  // columns 41, 59
    setLCDC(0x00); // point to 1st line
  Delayms(200);
    putsLCD(&OutString[0]);
    jloop = 0;
    temp1 = 0;
    ssid_size = 0;

    Buttons = ButtonState();

/* ****************************
    sprintf(OutString, "Select SSID from\nmenu:           ");  // columns 41, 59
    LCD_and_Console_out(OutString);
    sprintf(OutString, "Hogwarts        \n                ");  // columns 41, 59
    LCD_and_Console_out(OutString);
    sprintf(OutString, "Press S3 for YES\nor wait for NO  ");  // columns 41, 59
    LCD_and_Console_out(OutString);
    sprintf(OutString, "Zoltan          \n                ");  // columns 41, 59
    LCD_and_Console_out(OutString);
    sprintf(OutString, "Press S3 for YES\nor wait for NO  ");  // columns 41, 59
    LCD_and_Console_out(OutString);
    sprintf(OutString, "These are all I \nsee, to manually");  // columns 41, 59
    LCD_and_Console_out(OutString);
    sprintf(OutString, "enter your own  \ntext, press S3  ");  // columns 41, 59
    LCD_and_Console_out(OutString);
    sprintf(OutString, "You have chosen \nto enter SSID by");  // columns 41, 59
    LCD_and_Console_out(OutString);
    sprintf(OutString, "text wheel,press\nS3 for next char");  // columns 41, 59
    LCD_and_Console_out(OutString);
  **************************** */

    sprintf(OutString, "S6 to go back   \nS5 when done    ");  // columns 41, 59
    LCD_and_Console_out(OutString);

    temp2 = 0;
    CharChoice = 0xFF; // impossible value
    finish = 0;
    ssid_size = 8;
    SSID_text[0] = 'H';
    SSID_text[1] = 'o';
    SSID_text[2] = 'g';
    SSID_text[3] = 'w';
    SSID_text[4] = 'a';
    SSID_text[5] = 'r';
    SSID_text[6] = 't';
    SSID_text[7] = 's';


while(!finish)
{
    sprintf(OutString, "                \n                ");  // columns 41, 59
    ADC_read = ReadADC_char();
    if ( (ADC_read > CharChoice + 0x05) || (ADC_read < CharChoice - 0x05) )
    {   CharChoice = ADC_read - 0x05;
        temp2 = 0;    }
    else
    {   if (temp2>0)
        {   CharChoice++;
            temp2 = 0;   }
        temp2++;    }

    if (CharChoice <= 0x20) CharChoice = 0x20;
    if (CharChoice >= 0x7F) CharChoice = 0x7F;

    if (ssid_size > 0)  // characters previously entered
    {  for (iloop = 0; iloop < ssid_size; iloop++)
       { OutString[iloop] = SSID_text[iloop];   }  }

    OutString[ssid_size] = CharChoice;
    OutString[17] = '_';
    OutString[18] = '_';
    OutString[19] = '_';
    OutString[20] = '_';
    OutString[21] = 0x30;  //(ssid_size - ssid_size %10) + 0x30;
    OutString[22] = (ssid_size %10) + 0x30;

   // putsConsole(OutString);
   LCD_only_out(OutString);

flash = 0;
finish = 0;

for (iloop = 0; iloop <6; iloop++)
{
    if (!( flash || finish) )
       {Buttons = ButtonState(); }  // only allow one button push per
    else Buttons = 0x00;
}

    if (Buttons == 0x01)
    {   SSID_text[ssid_size] = CharChoice;
        ssid_size++;
        Buttons = 0x00;
        OutString[17] = '*';
        flash = 1;  //button action seen, flash the underscore;
    }

    if (Buttons == 0x02)
    {   if (ssid_size != 0) ssid_size = ssid_size - 0x01;
        Buttons = 0x00;
        OutString[18] = '*';
        flash = 1;
    }

if (Buttons == 0x04)
    {   finish = 1;
        if (ssid_size != 0) ssid_size = ssid_size - 0x01;
        Buttons = 0x00;
        OutString[19] = '*';
        iloop = 6;
    }

    if (flash == 1)
    {   if (iloop %2) OutString[ssid_size] = ' ';
        else OutString[ssid_size] = '_';   }

   LCD_only_out(OutString);

  // Wait for button release
  while (Buttons != 0x00)
  {  Buttons = ButtonState();
     Delayms(100);  }

  OutString[17] = '_';
  OutString[18] = '_';
  OutString[19] = '_';
  OutString[20] = '_';
  OutString[21] = 0x30;  //(ssid_size - ssid_size %10) + 0x30;
  OutString[22] = (ssid_size %10) + 0x30;

}  //end of my little text wheel exercise

    // Output Final Result
    sprintf(OutString, "                \n                ");  // columns 41, 59
    if (ssid_size > 0)  // characters previously entered
    {  for (iloop = 0; iloop <= ssid_size; iloop++)
       { OutString[iloop] = SSID_text[iloop];   }
    OutString[17] = '_';
    OutString[18] = '_';
    OutString[19] = '_';
    OutString[20] = '_';
    OutString[21] = (ssid_size - ssid_size %10) + 0x30;
    OutString[22] = (ssid_size %10) + 0x30;
    LCD_only_out(OutString);

 //   setLCDC(0x00); // point to 1st line
 // Delayms(200);
 //   putsLCD(OutString);    }
    }




  Delayms(5000);
    sprintf(OutString,"set ip proto 18\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"set dns name 74.208.7.3\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"set ip remote 80\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"set comm remote 0\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"set ip timer 1\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"set ip a 192.168.1.115\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"set ip host 74.208.7.3\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"set ip gateway 192.168.1.1\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"set dns a 68.105.28.12\r\n");
    WiFly_and_Console_out(OutString);
//    sprintf(OutString,"set comm remote GET$/users/102\r\n");
    sprintf(OutString,"set comm remote GET$/boardshortmessages/1");
//    sprintf(OutString,"set comm remote GET$/users/105\r\n");
//    sprintf(OutString,"set comm remote GET$/users/112\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"set wlan ssid                     \r\n"); //set wlan ssid Hogwarts\r\n");
    for (iloop = 0; iloop <= ssid_size; iloop++)
    {
        if (iloop <= ssid_size)  { OutString[iloop+14] = SSID_text[iloop];}
//        if (iloop == (ssid_size+1)) { OutString[iloop+14] = 0x5C; } // use 0x5V for '\'
//        if (iloop == (ssid_size+2)) { OutString[iloop+14] = 'r'; }
//        if (iloop == (ssid_size+3)) { OutString[iloop+14] = 0x5C; } // use 0x5V for '\'
//        if (iloop == (ssid_size+4)) { OutString[iloop+14] = 'n'; }
    }

    WiFly_and_Console_out(OutString);
    LCD_only_out(OutString);

  Delayms(2000);

    sprintf(OutString,"set wlan phrase pooKums496\r\n");
    WiFly_and_Console_out(OutString);
    sprintf(OutString,"save\r\n");
    WiFly_and_Console_out(OutString);
//    sprintf(OutString,"get everything\r\n");
//    WiFly_and_Console_out(OutString);
  Delayms(200);
    setLCDC(0x00); // point to 1st line
  Delayms(200);
    sprintf(OutString, "Sept22 5:48PM   \nsocket gets only");  // columns 41, 59
    putsConsole(OutString);
    putsLCD(OutString);
  Delayms(2000);

//    sprintf(OutString,"scan\r\n");
//    WiFly_and_Console_out(OutString);
//    sprintf(OutString,"join # 1\r\n");  // NOT GOOD SINCE THIS CAN CHANGE EVERY MINUTE!!!
    sprintf(OutString,"join                  \r\n"); //set wlan ssid Hogwarts\r\n");
    for (iloop = 0; iloop <= ssid_size; iloop++)
    {
        if (iloop <= ssid_size)  { OutString[iloop+5] = SSID_text[iloop];}
    }
    WiFly_and_Console_out(OutString);
    LCD_only_out(OutString);

  Delayms(5000);

  if (AssociatedCheck)
  {
    putsConsole(WiFlyMsg);
  Delayms(200);
    setLCDC(0x00); // point to 1st line
    sprintf(OutString, "                \n                ");  // columns 41, 59
    putsLCD(OutString);
  Delayms(200);
    setLCDC(0x00); // point to 1st line
    putsLCD(WiFlyMsg);
  }
  else
  {
    sprintf(OutString, "nope\r\n");
    putsConsole(OutString);
  Delayms(200);
    setLCDC(0x00); // point to 1st line
    sprintf(OutString, "nope            \n                ");  // columns 41, 59
  Delayms(200);
    putsLCD(OutString);
  }

  Delayms(2000);

    for (iloop = 0; iloop <=25; iloop++)
    {
    AssociatedCheck = 1;
    MessageCheck = 0;
    MessageCnt = 0;

    sprintf(OutString,"open\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"!");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(10000);
    sprintf(OutString,"$$$");
    putsConsole(OutString);
    putsWiFly(OutString);

  Delayms(200);
    setLCDC(0x00); // point to 1st line
  Delayms(200);
    sprintf(OutString, "iloop =         \nLoop to 25      ");
    OutString[9] = (char) (0x30 + iloop %10);
    OutString[8] = '0';
    if ((iloop >= 10) && (iloop <= 19)) OutString[8] = '1';
    if ((iloop >= 20) && (iloop <= 29)) OutString[8] = '2';
    putsLCD(OutString);
  Delayms(200);

  if (MessageCheck)
  {
    putsConsole(WiFlyMsg);
    
    sprintf(OutString, "                \n                ");  // 41, 59
//    if (charWiFlyMsgLen > 0)  LED_D5 = 1;
//    if (charWiFlyMsgLen > 5)  LED_D6 = 1;
//    if (charWiFlyMsgLen > 10) LED_D7 = 1;
//    if (charWiFlyMsgLen > 20) LED_D8 = 1;
//    if (charWiFlyMsgLen > 30) LED_D9 = 1;
    temp2 = ( (char) WiFlyMsgLen) %10;
    temp3 = (char) ((char)WiFlyMsgLen - temp2) /10;
    charWiFlyMsgLen = temp3*10+temp2;
    OutString[1] = temp3 + 0x30;
    OutString[2] = temp2 + 0x30;
    LCD_only_out(OutString);
  Delayms(2000);

    if (charWiFlyMsgLen <= 15)
    {
      for (jloop = 0; jloop<=charWiFlyMsgLen; jloop++)
      {  OutString[jloop] = WiFlyMsg[jloop]; }

    }
    else if (charWiFlyMsgLen >= 31 )
    {
      for (jloop = 0; jloop<=15; jloop++)
      {  OutString[jloop] = WiFlyMsg[jloop]; }

      for (jloop = 16; jloop<=31; jloop++)
      {  OutString[jloop+1] = WiFlyMsg[jloop]; }

    }
    else
    {
//      OutString[16] = 0x5C; // '\'
//      OutString[17] = 'n';
      for (jloop = 0; jloop<=15; jloop++)
      {  OutString[jloop] = WiFlyMsg[jloop]; }

      for (jloop = 16; jloop<=charWiFlyMsgLen; jloop++)
      {  OutString[jloop+1] = WiFlyMsg[jloop]; }
    }
    LCD_only_out(OutString);

  }
  else
  {
    sprintf(OutString, "nope\r\n");
    putsConsole(OutString);
  Delayms(200);
    setLCDC(0x00); // point to 1st line
    sprintf(OutString, "nope            \n                ");  // columns 41, 59
  Delayms(200);
    putsLCD(OutString);
  }



  // ***************************************************
  // processing WiFlyMsg quality, and channels and times
  // ***************************************************
  MsgGood = 1;
  MsgSame = 1;
  for (jloop = 12; jloop <=25; jloop++)
  {
      if ( (WiFlyMsg[jloop] >=0x30) && (WiFlyMsg[jloop] <=0x39) )
        {
          if (jloop == 8) LED_D3 = 1;
          if (jloop == 9) LED_D4 = 1;
          if (jloop == 10) LED_D5 = 1;
          if (jloop == 11) LED_D6 = 1;
          if (jloop == 12) LED_D7 = 1;
          if (jloop == 13) LED_D8 = 1;
          if (jloop == 14) LED_D9 = 1;
          if (jloop %2 == 0)
            { temp1 = WiFlyMsg[jloop] - 0x30; }
          else
            { NewChannel[(jloop-1)/2 - 6] = 10*temp1 + WiFlyMsg[jloop] - 0x30; }
        }
      else
        {
          MsgGood = 0;
        }
  }

  if (MsgGood == 1)
  {
    for (jloop = 0; jloop <=6; jloop++)
      {
      if ( NewChannel[jloop] != Channel[jloop] )
        { MsgSame = 0; }
      }
   }

  sprintf(OutString, "\r\n");
  putsConsole(OutString);

  sprintf(OutString, "                        \r\n");
  for (jloop = 0; jloop <=6; jloop++)
  {
  temp2 = NewChannel[jloop] %10;
  temp3 = (char) ((NewChannel[jloop] - temp2) /10);
  OutString[jloop*2] = temp3 + 0x30;
  OutString[jloop*2+1] = temp2 + 0x30;
  }
  putsConsole(OutString);


  if (1)   //MsgSame == 0)
  {
    for (jloop = 0; jloop <=6; jloop++)
      { Channel[jloop] = NewChannel[jloop]; }

    sprintf(OutString, "\r\n");
    putsConsole(OutString);
    sprintf(OutString, "                        \r\n");
    for (jloop = 0; jloop <=6; jloop++)
      {
        temp2 = Channel[jloop] %10;
        temp3 = (char) ((Channel[jloop] - temp2) /10);
        OutString[jloop*2] = temp3 + 0x30;
        OutString[jloop*2+1] = temp2 + 0x30;
      }
    putsConsole(OutString);
    
    ChanSel = 0;
    ChanTime = 0;
    for (jloop = 0; jloop <=6; jloop++)
      {
        sprintf(OutString, "\r\njloop=           ");
        OutString[8] = jloop + 0x30;
        putsConsole(OutString);
        ChanSel = jloop;
        ChanTime = 0;

        if (Channel[jloop] == 0)  // ignore this channel
        {
            sprintf(OutString, "ChanSel=      skip \r\n");
            OutString[12] = ChanSel + 0x31;  //start at 1 not 0
            putsConsole(OutString);
            ChanTime = 0;
        }
        else
        {
            sprintf(OutString, "ChanSel=     ");
            OutString[10] = ChanSel + 0x31;  //start at 1 not 0
            putsConsole(OutString);
            temp2 = ChanTime %10;
            temp3 = (ChanTime - temp2)/10;
            sprintf(OutString, "ChanTime=     ");
            OutString[10] = temp3 + 0x30;
            OutString[11] = temp2 + 0x30;
            putsConsole(OutString);
           while (ChanTime < Channel[jloop])
             {
               LED_D3 = 0;
               LED_D4 = 0;
               LED_D5 = 0;
               LED_D6 = 0;
               LED_D7 = 0;
               LED_D8 = 0;
               LED_D9 = 0;
               if (ChanSel == 0) LED_D3 = 1;
               if (ChanSel == 1) LED_D4 = 1;
               if (ChanSel == 2) LED_D5 = 1;
               if (ChanSel == 3) LED_D6 = 1;
               if (ChanSel == 4) LED_D7 = 1;
               if (ChanSel == 5) LED_D8 = 1;
               if (ChanSel == 6) LED_D9 = 1;
               Delayms(1000);  // the 1 second count
               ChanTime++;
               sprintf(OutString, "   ");
               temp2 = ChanTime %10;
               temp3 = (char) ((ChanTime - temp2) /10);
               OutString[0] = temp3 + 0x30;
               OutString[1] = temp2 + 0x30;
               putsConsole(OutString);
             }
               LED_D3 = 0;
               LED_D4 = 0;
               LED_D5 = 0;
               LED_D6 = 0;
               LED_D7 = 0;
               LED_D8 = 0;
               LED_D9 = 0;
           }  //  big else
        }  // main jloop
    }  // MsgSame if statement

  // ***************************************************






    } // big iloop of 25 passes

  return 0;
} // main
int main(void)
{
 unsigned char iloop, jloop;
 char AddrString[30];
 char ConstString[256];


    InitializeSystem();

 unsigned char   temp, temp1, temp2, temp3, temp4;
 unsigned char   ones_char, tens_char, huns_char;
 int16_t   change_cnt;
    sprintf(OutString, "WiFly Pass_thru\nDemo");
    putsLCD(OutString);
    // JKW starts here
  Delayms(5000);
    sprintf(OutString,"$$$");
    putsWiFly(OutString);
    putsConsole(OutString);
  Delayms(5000);
    sprintf(OutString,"set comm open [\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set wlan name Hogwarts\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set wlan phrase pooKums496\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set ftp timer 40\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set comm close ]\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"save\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
//    sprintf(OutString,"get everything\r\n");
//    putsConsole(OutString);
//    putsWiFly(OutString);
  Delayms(200);
    sprintf(OutString, "Aug31 7:44AM    \nputs only       ");  // columns 41, 59
    putsConsole(OutString);
  Delayms(200);
   setLCDC(0x00); // point to 1st line
  Delayms(200);
    putsLCD(OutString);
  Delayms(2000);
    sprintf(OutString, "\r\n");
    putsConsole(OutString);

  change_cnt = 0;
    for (iloop = 0; iloop <=5; iloop++)
    {
  Delayms(5000);
    sprintf(AddrString,"ftp put zzaq29_000.txt\r\n");
    temp1 = (iloop  % 10);
    ones_char = temp1 + 0x30;
    temp2 = (iloop - temp1)/10;
    tens_char = temp2 + 0x30;
    temp3 = (iloop - temp2*10 - temp1)/100;
    huns_char = temp3 + 0x30;
    AddrString[15] = huns_char;
    AddrString[16] = tens_char;
    AddrString[17] = ones_char;
  Delayms(5000);
    putsConsole(AddrString);
  Delayms(1000);
    putsWiFly(AddrString);


  sprintf(ConstString,"A9ABE296E34713800CC11D0D1E0FB197B36810D14F32085E4E50BFB685EC755E26C88F63A105284B0AC627FA90EF3B294D6D549C0A0D88E814B5A2C17794B1EBD1A064868BB377DFD5CD80218D73D3F0A18B642EFAFACEDDBA6E2694D27F3E7EE3B04A57D6CBBE452343D9428133C5209D763B2F776628529B94173B3568");  // 1009
  temp4 = ConstString[change_cnt] - 0x01;
  if (temp4 < 0x30)
    {
		temp4 = 0x30;
		change_cnt++;
		if (change_cnt == 251) {change_cnt = 0;}
      temp4 = ConstString[change_cnt] - 0x01;
	}
  if ((temp4 < 0x41) && (temp4 > 0x39)) temp4 = 0x39;
  ConstString[change_cnt] = temp4;
  change_cnt++;
  if (change_cnt == 251) {change_cnt = 0;}

    temp = 0x00;
    while (temp != '.') {temp = U1RXREG; Delayms(10);}
    temp = 0x00;
    while (temp != '.') {temp = U1RXREG; Delayms(10);}
    temp = 0x00;
    while (temp != '.') {temp = U1RXREG; Delayms(10);}
    temp = 0x00;
    while (temp != '.') {temp = U1RXREG; Delayms(10);}
    temp = 0x00;
    while (temp != '.') {temp = U1RXREG; Delayms(10);}

    while (U1RXREG != '1')  // [ = 0x5B, ] = 0x5D
    {
      putConsole(U1RXREG);
  Delayms(200);
    }

    putsConsole(ConstString);
  Delayms(1000);
    putsWiFly(ConstString);

  Delayms(10000);
//  Delayms(10000);

  sprintf(ConstString,"$$$");
    putsConsole(ConstString);
  Delayms(1000);
    putsWiFly(ConstString);
  Delayms(1000);


  setLCDC(0x00); // point to 1st line
  Delayms(200);
    sprintf(OutString, "iloop =         \nLoop to 25      ");
    OutString[9] = (char) (0x30 + iloop %10);
    OutString[8] = '0';
    if ((iloop >= 10) && (iloop <= 19)) OutString[8] = '1';
    if ((iloop >= 20) && (iloop <= 29)) OutString[8] = '2';
    putsLCD(OutString);

  Delayms(10000);
    }

// JKW ends here

    while(1)
    {
        // check if S4 pressed to trigger WiFly factory restoral
        if(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS))
        {
            sprintf(OutString,"\r\n\r\ninitiating WiFly factory reset...\r\n\r\n");
            putsConsole(OutString);
            // drive GPIO9 high for 10ms before resetting the module
            RN_GPIO9 = 1;
            Delayms(1000);
            // Assert RESET for 10ms
            RN_RESET = 0;
            Delayms(100);
            RN_RESET = 1;
            Delayms(100);
            // toggle GPIO9 5 times, delaying at least 1 sec between toggles
            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);

            // now toggle RESET to reboot the module and apply factory default settings
            RN_RESET = 0;
            Delayms(100);
            RN_RESET = 1;
            // wait for user to release S4
            while(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS));
        }
    }

} // main
int main(void)
{
 unsigned char jloop;
 unsigned int iloop;

 char AddrString[30];
 char ConstString[256];

 InitializeSystem();

 unsigned char   temp, temp1, temp2, temp3, temp4;
 unsigned char   ones_char, tens_char, huns_char;
 int16_t   change_cnt;

     ODCAbits.ODA6 		= 0;  	// This is for the Explorer-16 Demo Board
     TRISAbits.TRISA6 	= 0;		// This is for the Explorer-16 Demo Board
 //  ODCCbits.ODC2 		= 0;
 //  TRISCbits.TRISC2 	= 0;

 unsigned long i;

 	GreenLEDState = 0;
 	RedLEDState = 0;

        RTCCInit();		// initialization includes set the time and date

        TimeMinBinary = 0;
 	while (TimeMinBinary < 3)
        {
	if (TenSecondTick == 1)
	{
        RTCCgrab();
        TimeHourBinary = mRTCCDec2Bin(TimeHourBCD);
        TimeMinBinary = mRTCCDec2Bin(TimeMinBCD);
        TimeSecBinary = mRTCCDec2Bin(TimeSecBCD);
        TimeDayOfWeekBinary = mRTCCDec2Bin(TimeDayOfWeekBCD);
        TimeDayBinary = mRTCCDec2Bin(TimeDayBCD);
        TimeMonthBinary = mRTCCDec2Bin(TimeMonthBCD);
        TimeYearBinary = mRTCCDec2Bin(TimeYearBCD);


    sprintf(OutString, "  :  :          \n  /  /   20     ");  // columns 41, 59
//  sprintf(OutString, "Sept4 1:00PM    \nputs only       ");  // columns 41, 59
    temp1 = (TimeHourBinary  % 10);
    ones_char = temp1 + 0x30;
    temp2 = (TimeHourBinary - temp1)/10;
    tens_char = temp2 + 0x30;
    OutString[0] = tens_char;
    OutString[1] = ones_char;

    temp1 = (TimeMinBinary  % 10);
    ones_char = temp1 + 0x30;
    temp2 = (TimeMinBinary - temp1)/10;
    tens_char = temp2 + 0x30;
    OutString[3] = tens_char;
    OutString[4] = ones_char;

    temp1 = (TimeSecBinary  % 10);
    ones_char = temp1 + 0x30;
    temp2 = (TimeSecBinary - temp1)/10;
    tens_char = temp2 + 0x30;
    OutString[6] = tens_char;
    OutString[7] = ones_char;

    temp1 = (TimeDayOfWeekBinary  % 10);
    ones_char = temp1 + 0x30;
    temp2 = (TimeDayOfWeekBinary - temp1)/10;
    tens_char = temp2 + 0x30;
    OutString[17] = tens_char;
    OutString[18] = ones_char;

    temp1 = (TimeDayBinary  % 10);
    ones_char = temp1 + 0x30;
    temp2 = (TimeDayBinary - temp1)/10;
    tens_char = temp2 + 0x30;
    OutString[20] = tens_char;
    OutString[21] = ones_char;

    temp1 = (TimeMonthBinary  % 10);
    ones_char = temp1 + 0x30;
    temp2 = (TimeMonthBinary - temp1)/10;
    tens_char = temp2 + 0x30;
    OutString[23] = tens_char;
    OutString[24] = ones_char;

    temp1 = (TimeYearBinary  % 10);
    ones_char = temp1 + 0x30;
    temp2 = (TimeYearBinary - temp1)/10;
    tens_char = temp2 + 0x30;
    OutString[28] = tens_char;
    OutString[29] = ones_char;

    Delayms(200);
    setLCDC(0x00); // point to 1st line
    Delayms(2000);
    putsLCD(OutString);
    TenSecondTick = 0;
} // if (TenSecondTick == 1)
} // while(TimeMinBinary < 4)

    sprintf(OutString, "WiFly Pass_thru\nDemo");
    putsLCD(OutString);
    // JKW starts here
  Delayms(5000);
    sprintf(OutString,"$$$");
    putsWiFly(OutString);
    putsConsole(OutString);
  Delayms(5000);
    sprintf(OutString,"set comm open [\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
//  sprintf(OutString,"set wlan ssid AMI\r\n");
//  sprintf(OutString,"set wlan ssid Arthur$and$Matts$Internet\r\n");
    sprintf(OutString,"set wlan ssid Hogwarts\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
//    sprintf(OutString,"set wlan phrase hot7blue\r\n");
    sprintf(OutString,"set wlan phrase pooKums496\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set ftp timer 80\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set comm close ]\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set ftp dir /jackwaterman\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set ftp user waterallusers\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set ftp pass aRkeO7755123!\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
//User=jaycen     is now waterallusers
//Pass=jWes232740 is now aRkeO7755123!
//Dir=../../      is now /jackwaterman
    Delayms(1000);
    sprintf(OutString,"save\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
//  Delayms(1000);
//    sprintf(OutString,"get everything\r\n");
//    putsConsole(OutString);
//    putsWiFly(OutString);
  Delayms(200);
    sprintf(OutString, "Sept7 8:00AM    \nputs only       ");  // columns 41, 59
    putsConsole(OutString);
  Delayms(200);
   setLCDC(0x00); // point to 1st line
  Delayms(200);
    putsLCD(OutString);
  Delayms(2000);
    sprintf(OutString, "\r\n");
    putsConsole(OutString);

  change_cnt = 0;
//  sprintf(ConstString,"A9ABE296E34713800CC11D0D1E0FB197B36810D14F32085E4E50BFB685EC755E26C88F63A105284B0AC627FA90EF3B294D6D549C0A0D88E814B5A2C17794B1EBD1A064868BB377DFD5CD80218D73D3F0A18B642EFAFACEDDBA6E2694D27F3E7EE3B04A57D6CBBE452343D9428133C5209D763B2F776628529B94173B3568");  // 1009


  for (iloop = 0; iloop <=999; iloop++)
    {
  Delayms(500);  // worked well with 5000
    sprintf(AddrString,"ftp put sept9__000.txt\r\n");
//  sprintf(AddrString,"ftp put arthur_000.txt\r\n");
    temp1 = (iloop  % 10);
    ones_char = temp1 + 0x30;
    temp2 = ((iloop - temp1) % 100)/10;
    tens_char = temp2 + 0x30;
    temp3 = (iloop - temp2*10 - temp1)/100;
    huns_char = temp3 + 0x30;
    AddrString[15] = huns_char;
    AddrString[16] = tens_char;
    AddrString[17] = ones_char;
  Delayms(500);  // worked well with 5000
    putsConsole(AddrString);
  Delayms(500);
    putsWiFly(AddrString);

  sprintf(ConstString,"A9ABE296E34713800CC11D0D1E0FB197B36810D14F32085E4E50BFB685EC755E26C88F63A105284B0AC627FA90EF3B294D6D549C0A0D88E814B5A2C17794B1EBD1A064868BB377DFD5CD80218D73D3F0A18B642EFAFACEDDBA6E2694D27F3E7EE3B04A57D6CBBE452343D9428133C5209D763B2F776628529B94173B3568");  // 1009
  temp4 = ConstString[change_cnt] - 0x01;
  if (temp4 < 0x30)
    {
		temp4 = 0x30;
		change_cnt++;
		if (change_cnt == 251) {change_cnt = 0;}
      temp4 = ConstString[change_cnt] - 0x01;
	}
  if ((temp4 < 0x41) && (temp4 > 0x39)) temp4 = 0x39;
  ConstString[change_cnt] = temp4;
  change_cnt++;
  if (change_cnt == 251) {change_cnt = 0;}

    temp = 0x00;
    kickout_seconds = 0;  // kicks out if takes longer than 2 minutes
    RTCCgrab();
    TimeHourBinary = mRTCCDec2Bin(TimeHourBCD);
    TimeMinBinary = mRTCCDec2Bin(TimeMinBCD);
    TimeSecBinary = mRTCCDec2Bin(TimeSecBCD);
    time_mark1 = TimeHourBinary*3600 + TimeMinBinary*60+ TimeSecBinary;
    TimeHourBinarySave = TimeHourBinary;

    while ( (U1RXREG != '1') && (kickout_seconds < 60) )  // [ = 0x5B, ] = 0x5D
    {
        putConsole(U1RXREG);
    	RTCCgrab();
    	TimeHourBinary = mRTCCDec2Bin(TimeHourBCD);
    	TimeMinBinary = mRTCCDec2Bin(TimeMinBCD);
    	TimeSecBinary = mRTCCDec2Bin(TimeSecBCD);
    	time_mark2 = TimeHourBinary*3600 + TimeMinBinary*60+ TimeSecBinary;
    	if (TimeHourBinary < TimeHourBinarySave) time_mark2 = time_mark2 + 24*3600;
    	kickout_seconds = time_mark2 - time_mark1;
        Delayms(200);
    }
    if (kickout_seconds < 60)
    {
    putsConsole(ConstString);
  Delayms(500);
    putsWiFly(ConstString);
//  Delayms(7000);  // works OK when ftp_timeout = 40, 1 every 12 sec
//  Delayms(21000);// works OK when ftp_timeout = 40, 1 every 24 sec
  Delayms(12000);  // works OK when ftp_timeout = 40, 1 every 16 sec
    }
  sprintf(ConstString,"$$$");
    putsConsole(ConstString);
  Delayms(500);
    putsWiFly(ConstString);
  Delayms(500);


  setLCDC(0x00); // point to 1st line
  Delayms(200);
    sprintf(OutString, "iloop =         \nLoop to 1000    ");
    temp1 = (iloop  % 10);
    ones_char = temp1 + 0x30;
//    temp2 = (iloop - temp1)/10;
    temp2 = ((iloop - temp1) % 100)/10;
    tens_char = temp2 + 0x30;
    temp3 = (iloop - temp2*10 - temp1)/100;
    huns_char = temp3 + 0x30;
    OutString[8] = huns_char;
    OutString[9] = tens_char;
    OutString[10] = ones_char;
    putsLCD(OutString);

  Delayms(1000);  // worked well with 10000
    }

// JKW ends here

    while(1)
    {
        // check if S4 pressed to trigger WiFly factory restoral
        if(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS))
        {
            sprintf(OutString,"\r\n\r\ninitiating WiFly factory reset...\r\n\r\n");
            putsConsole(OutString);
            // drive GPIO9 high for 10ms before resetting the module
            RN_GPIO9 = 1;
            Delayms(1000);
            // Assert RESET for 10ms
            RN_RESET = 0;
            Delayms(100);
            RN_RESET = 1;
            Delayms(100);
            // toggle GPIO9 5 times, delaying at least 1 sec between toggles
            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);

            // now toggle RESET to reboot the module and apply factory default settings
            RN_RESET = 0;
            Delayms(100);
            RN_RESET = 1;
            // wait for user to release S4
            while(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS));
        }
    }

} // main
int main(void)
{
 unsigned char iloop, jloop;
 char AddrString[30];
 char ConstString[70];


    InitializeSystem();

 unsigned char   temp1, temp2, temp3, temp4;
 unsigned char   ones_char;
 unsigned char   tens_char;

    sprintf(OutString, "WiFly Pass_thru\nDemo");
    putsLCD(OutString);
    // JKW starts here
  Delayms(5000);
    sprintf(OutString,"$$$");
    putsWiFly(OutString);
    putsConsole(OutString);
  Delayms(5000);
    sprintf(OutString,"set comm open *OPEN*\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set wlan name Hogwarts\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set wlan phrase pooKums496\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set ftp timer 40\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set comm close *CLOS*\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"save\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
//    sprintf(OutString,"get everything\r\n");
//    putsConsole(OutString);
//    putsWiFly(OutString);
  Delayms(200);
    sprintf(OutString, "Aug29 5:54AM    \nputs only       ");  // columns 41, 59
    putsConsole(OutString);
  Delayms(200);
   setLCDC(0x00); // point to 1st line
  Delayms(200);
    putsLCD(OutString);
  Delayms(2000);
    sprintf(OutString, "\r\n");
    putsConsole(OutString);

//    sprintf(ConstString,"A9ABE296E34713800CC11D0D1E0FB19");
//                      "FEA626636B6656949F2CFD4873E51691\r\n");



    for (iloop = 0; iloop <=5; iloop++)
    {
  Delayms(1000);
//    sprintf(OutString,"get ftp\r\n");
//    putsConsole(OutString);
//    putsWiFly(OutString);
//    sprintf(OutString,"$$$");
//    putsWiFly(OutString);
//    putsConsole(OutString);
  Delayms(5000);
    if (iloop == 0) sprintf(AddrString,"ftp put zzak29_00.txt\r\n");
    if (iloop == 1) sprintf(AddrString,"ftp put zzak29_01.txt\r\n");
    if (iloop == 2) sprintf(AddrString,"ftp put zzak29_02.txt\r\n");
    if (iloop == 3) sprintf(AddrString,"ftp put zzak29_03.txt\r\n");
    if (iloop == 4) sprintf(AddrString,"ftp put zzak29_04.txt\r\n");
    if (iloop == 5) sprintf(AddrString,"ftp put zzak29_05.txt\r\n");
//    temp1 = (iloop  % 10);
//    ones_char = temp1 + 0x30;
//    temp2 = (iloop - temp1)/10;
//    tens_char = temp2 + 0x30;
//    AddrString[15] = tens_char;
//    AddrString[16] = ones_char;
//  Delayms(5000);
    putsConsole(AddrString);
//  Delayms(2000);
//    sprintf(OutString,"\r\n");
//    putsConsole(OutString);
  Delayms(1000);
    putsWiFly(AddrString);
  Delayms(6000);
//    sprintf(ConstString,"the once and xxth future king\r\n");
//    ConstString[13] = tens_char;
//    ConstString[14] = ones_char;
  if (iloop == 0) sprintf(ConstString,"A9ABE296E34713800CC11D0D1E0FB19*CLOS*");
  if (iloop == 1) sprintf(ConstString,"99ABE296E34713800CC11D0D1E0FB19*CLOS*");
  if (iloop == 2) sprintf(ConstString,"98ABE296E34713800CC11D0D1E0FB19*CLOS*");
  if (iloop == 3) sprintf(ConstString,"989BE296E34713800CC11D0D1E0FB19*CLOS*");
  if (iloop == 4) sprintf(ConstString,"989AE296E34713800CC11D0D1E0FB19*CLOS*");
  if (iloop == 5) sprintf(ConstString,"989AD296E34713800CC11D0D1E0FB19*CLOS*");
//  temp4 = ConstString[iloop] - 0x01;
//  if (temp4 < 0x30) temp4 = 0x46; //'F'
//  if ((temp4 < 0x41) && (temp4 > 0x39)) temp4 = 0x39;
//  ConstString[iloop] = temp4;
    putsConsole(ConstString);
  Delayms(1000);
    putsWiFly(ConstString);
  Delayms(10000);
  Delayms(10000);


  sprintf(ConstString,"$$$");
    putsConsole(ConstString);
  Delayms(1000);
    putsWiFly(ConstString);
  Delayms(1000);


  setLCDC(0x00); // point to 1st line
  Delayms(200);
    sprintf(OutString, "iloop =         \nLoop to 25      ");
    OutString[9] = (char) (0x30 + iloop %10);
    OutString[8] = '0';
    if ((iloop >= 10) && (iloop <= 19)) OutString[8] = '1';
    if ((iloop >= 20) && (iloop <= 29)) OutString[8] = '2';
    putsLCD(OutString);

//  Delayms(2000);
//    sprintf(OutString,"\r\n");
//    putsWiFly(OutString);
//    putsConsole(OutString);
//  Delayms(2000);
//    sprintf(OutString,"reboot\r\n");
//    putsWiFly(OutString);
//    putsConsole(OutString);
//  Delayms(2000);
//    sprintf(OutString,"\r\n");
//    putsWiFly(OutString);
//    putsConsole(OutString);
//  Delayms(10000);
//    sprintf(OutString,"$$$");
//    putsWiFly(OutString);
//    putsConsole(OutString);
  Delayms(10000);
    }

// JKW ends here

    while(1)
    {
        // check if S4 pressed to trigger WiFly factory restoral
        if(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS))
        {
            sprintf(OutString,"\r\n\r\ninitiating WiFly factory reset...\r\n\r\n");
            putsConsole(OutString);
            // drive GPIO9 high for 10ms before resetting the module
            RN_GPIO9 = 1;
            Delayms(1000);
            // Assert RESET for 10ms
            RN_RESET = 0;
            Delayms(100);
            RN_RESET = 1;
            Delayms(100);
            // toggle GPIO9 5 times, delaying at least 1 sec between toggles
            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);

            // now toggle RESET to reboot the module and apply factory default settings
            RN_RESET = 0;
            Delayms(100);
            RN_RESET = 1;
            // wait for user to release S4
            while(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS));
        }
    }

} // main
int main(void)
{
    char iloop, jloop;
    char AddrString[30];
    char ConstString[35];


    InitializeSystem();

 char   length;
 char   ones_char;
 char   tens_char;

    sprintf(OutString, "WiFly Pass_thru\nDemo");
    putsLCD(OutString);
    // JKW starts here
  Delayms(5000);
    sprintf(OutString,"$$$");
    putsWiFly(OutString);
    putsConsole(OutString);
  Delayms(5000);
    sprintf(OutString,"set comm open [\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set wlan name Hogwarts\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set wlan phrase pooKums496\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set ftp timer 20\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"set comm close ]\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
    sprintf(OutString,"save\r\n");
    putsConsole(OutString);
    putsWiFly(OutString);
  Delayms(1000);
//    sprintf(OutString,"get everything\r\n");
//    putsConsole(OutString);
//    putsWiFly(OutString);
  Delayms(200);
    sprintf(OutString, "Aug26 6:07AM    \nputs only       ");  // columns 41, 59
    putsConsole(OutString);
  Delayms(200);
   setLCDC(0x00); // point to 1st line
  Delayms(200);
    putsLCD(OutString);
  Delayms(2000);
    sprintf(OutString, "\r\n");
    putsConsole(OutString);


    for (iloop = 0; iloop <=13; iloop++)
    {
  Delayms(1000);
//    sprintf(OutString,"get ftp\r\n");
//    putsConsole(OutString);
//    putsWiFly(OutString);
//    sprintf(OutString,"$$$");
//    putsWiFly(OutString);
//    putsConsole(OutString);
  Delayms(5000);
    sprintf(AddrString,"ftp put aaad26_00.txt\r\n");
    ones_char = (iloop  % 10);
    length = (iloop - ones_char)/10;
    ones_char = ones_char + 0x30;
    tens_char = length + 0x30;
    AddrString[15] = tens_char;
    AddrString[16] = ones_char;
  Delayms(5000);
    putsConsole(AddrString);
  Delayms(2000);
    sprintf(OutString,"\r\n");
    putsConsole(OutString);
  Delayms(1000);
    putsWiFly(AddrString);
  Delayms(2000);
    sprintf(ConstString,"the once and xxth future king\r\n");
    ConstString[13] = tens_char;
    ConstString[14] = ones_char;
    putsConsole(ConstString);
  Delayms(1000);
    putsWiFly(ConstString);
  Delayms(10000);
    setLCDC(0x00); // point to 1st line
  Delayms(200);
    sprintf(OutString, "iloop =         \nLoop to 25      ");
    OutString[9] = (char) (0x30 + iloop %10);
    OutString[8] = '0';
    if ((iloop >= 10) && (iloop <= 19)) OutString[8] = '1';
    if ((iloop >= 20) && (iloop <= 29)) OutString[8] = '2';
    putsLCD(OutString);

  Delayms(2000);
    sprintf(OutString,"\r\n");
    putsWiFly(OutString);
    putsConsole(OutString);
  Delayms(2000);
    sprintf(OutString,"reboot\r\n");
    putsWiFly(OutString);
    putsConsole(OutString);
  Delayms(2000);
    sprintf(OutString,"\r\n");
    putsWiFly(OutString);
    putsConsole(OutString);
  Delayms(10000);
    sprintf(OutString,"$$$");
    putsWiFly(OutString);
    putsConsole(OutString);
  Delayms(10000);
    }

// JKW ends here

    while(1)
    {
        // check if S4 pressed to trigger WiFly factory restoral
        if(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS))
        {
            sprintf(OutString,"\r\n\r\ninitiating WiFly factory reset...\r\n\r\n");
            putsConsole(OutString);
            // drive GPIO9 high for 10ms before resetting the module
            RN_GPIO9 = 1;
            Delayms(1000);
            // Assert RESET for 10ms
            RN_RESET = 0;
            Delayms(100);
            RN_RESET = 1;
            Delayms(100);
            // toggle GPIO9 5 times, delaying at least 1 sec between toggles
            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);
            RN_GPIO9 = 1;
            Delayms(1200);

            RN_GPIO9 = 0;
            Delayms(1200);

            // now toggle RESET to reboot the module and apply factory default settings
            RN_RESET = 0;
            Delayms(100);
            RN_RESET = 1;
            // wait for user to release S4
            while(0 == SwitchLevel(&SW_S4_PORT, SW_S4_PIN, SWITCH_DEBOUNCE_MS));
        }
    }

} // main