Esempio n. 1
0
main( void)
{
    initEX16();
    initLCD();
    putsLCD( "Insert card...\n");
    while ( !getCD());
    Delayms( 100);
    
    if ( !mount())
        putsLCD("Mount Failed");
    else
    {  
        clrLCD();
        putsLCD("Playing...");
        if ( !playWAV( "NELLY.WAV"))
        {
            clrLCD();
            putsLCD("File not found");
        }
    } 

    while( 1)
    {
    } // main loop

} //main 
Esempio n. 2
0
/*************************************************************************************
menu_pwm()
*************************************************************************************/
int menu_pwm(int c)
{
	IN0 = 0;	// definiramo smer
	IN1 = 1;
	CR = 1;		// vkljucimo PCA
	do
	{
		putccLCD(1);     // brisanje ekrana
        printf("Menu pwm:");
        gotoxyLCD(1,2);
        putsLCD("CCAP0H:");
        gotoxyLCD(1,3);
        printf("%s", itoa(CCAP0H, s));
        gotoxyLCD(1,4);
        putsLCD(" +1   -1  SET  SMER");
        do
        {
			c = (unsigned char)key_getch();
        } while(c == 0);
        switch(c)
        {
            case F1:
				if(CCAP0H < 255)
				CCAP0H++;
        		gotoxyLCD(1,3);
				printf("%s", itoa(CCAP0H, s));
				break;
            case F2:
				if(CCAP0H > 0)
				CCAP0H--;
        		gotoxyLCD(1,3);
				printf("%s", itoa(CCAP0H, s));
				break;
            case F3:
				gotoxyLCD(1,3);
				printf("Nova vrednost: ");
				gets(s);
				CCAP0H = atoi(s);
				gotoxyLCD(1,3);
				printf("%s", itoa(CCAP0H, s));
				break;
            case F4:
				IN0 = !IN0;
				IN1 = !IN1;
				break;
            case 27:            // Escape
				c = 0;
				break;
        }
    } while(c != 0);
    CR = 0;		// izkljucimo PCA
    return c;
}
Esempio n. 3
0
int main(void)
{
    char            str[32];
    unsigned int ad[4][10],i;
    RCONbits.SWDTEN = 0;			//disable Watch dog timer
    initPLL();
    while (OSCCONbits.CF == 1);			//check clock failed
    while (OSCCONbits.COSC != 0b011);           // Wait for Clock switch to occur
    while (OSCCONbits.LOCK == 0);		//check PLL locked
    
    T1_Initial();
    PORTS_Test_Initial();
    ADC1_Initial();
    InitializeLCM();
    LATDbits.LATD11 = 1;                        /* turn the LCM back light */
    ser1=0;
    ser2=0;
    ser3=0;
    ser4=0;
    ser5=0;
    ser6=0;
    LCD_start();
    LCD_Delay200usX(5000);
    LCD_clear();
    LCD_Delay200usX(5000);
    while (1) 
    {
        ser1 = (ADC_read(1,DIVCOUNT)/341)*112;
        ser2 = ((ADC_read(2,DIVCOUNT)-217)/479)*124+217;
        ser3 = ((ADC_read(3,DIVCOUNT)-209)/481)*114+209;
        ser4 = ((ADC_read(4,DIVCOUNT)-308)/463)*115+308;
        ser5 = ((ADC_read(5,DIVCOUNT)-237)/184)*46+237;
        ser6 = ((ADC_read(6,DIVCOUNT)-246)/411)*105+246;
        LCD_Cursor_New(0, 0);
        //sprintf(str, "timer1.count: %d  ",timer1.count);
        //putsLCD((unsigned char*)str);
        putsLCD("Final Prj. TEAM 12  ");
        LCD_Cursor_New(1, 0);
        sprintf(str, "AD1: %5d AD2:%5d",ser1,ser2);
        putsLCD((unsigned char*)str);
        LCD_Cursor_New(2, 0);
        sprintf(str, "AD3: %5d AD4:%5d",ser3,ser4);
        putsLCD((unsigned char*)str);
        LCD_Cursor_New(3, 0);
        sprintf(str, "AD5: %5d AD6:%5d",ser5,ser6);
        putsLCD((unsigned char*)str);
    }
}
Esempio n. 4
0
void LCD_only_out(char String[128])
{
    setLCDC(0x00); // point to 1st line
  Delayms(200);
    putsLCD(String);
  Delayms(2000);
}
Esempio n. 5
0
/*************************************************************************************
menu_glavni()
*************************************************************************************/
int menu_glavni(int c)
{
	refresh = 1;
    do
    {
        putccLCD(1);     // brisanje ekrana
        printf("Glavni menu");
        gotoxyLCD(1,3);
        putsLCD(" F1   F2   F3   F4");
        gotoxyLCD(1,4);
        putsLCD("LABV PWM  SEL3 TIME");
        do
        {
            c = (unsigned char)key_getch();
         	if (refresh == 1)
         	{
         	     gotoxyLCD(16,1);
                 SecToHms(value,s);
                 s[5] = 0;
                 putsLCD(s);
         	     refresh = 0;
                 led_y = !led_y;
            }
        } while(c == 0);
        switch(c)
        {
            case 0:
                 break;
            case F1:
                 menu_pwm_labvaja(0);
                 break;
            case F2:
                 menu_pwm(0);
                 break;
            case F3:
                 nodef();
                 break;
            case F4:
                 menu_time(0);
                 break;
            case 27:            // Escape
                 c = 0;
                 break;
        }
    } while(c != 0);
    return c;
}
Esempio n. 6
0
void LCD_and_Console_out(char String[128])
{
    putsConsole(String);
    setLCDC(0x00); // point to 1st line
  Delayms(200);
    putsLCD(String);
  Delayms(2000);
}
Esempio n. 7
0
/** LCD (Mode Select Menu) **/
void modeMenu(void){
    _INT1IF = LOW;                  //set INT1 flag back to zero 
    _INT2IF = LOW;                  //set INT2 flag back to zero 
    clearLCD();
    setCursor(1,1);
    putsLCD("Stir");
    setCursor(2,1);
    putsLCD("Shake");
    modeMenuSelect = 32766;         // this handles cursor position by means of modulus
    myBOOLs.mainMenuTrue = FALSE;   // these determine which menu for ext interrupt 2
    myBOOLs.modeMenuTrue = TRUE;    // these determine which menu for ext interrupt 2
    myBOOLs.rpmMenuTrue = FALSE;    // these determine which menu for ext interrupt 2
    while(myBOOLs.modeDecide){
        if(modeMenuSelect % 2 == 0){
            setCursor(1,0);
            putsLCD(">");
            setCursor(2,0);
            putsLCD(" ");
        }
        else{
            setCursor(1,0);
            putsLCD(" ");
            setCursor(2,0);
            putsLCD(">");
        }
    }
}
Esempio n. 8
0
/*************************************************************************************
menu_sub()				Sample menu
						c - default selection
						Return value: last submenu selection
*************************************************************************************/
int menu_sub(int c)
{
    do
    {
        putccLCD(1);     // brisanje ekrana
        printf("Menu sub:");
        gotoxyLCD(1,2);
        putsLCD("Select Submenu with");
        gotoxyLCD(1,3);
        putsLCD(" F1   F2   F3   F4");
        gotoxyLCD(1,4);
        putsLCD("SEL1 SEL2 SEL3 SEL4");
        do
        {
            c = (unsigned char)key_getch();
        } while(c == 0);
        switch(c)
        {
            case F1:
				nodef();
				break;
            case F2:
				nodef();
				break;
            case F3:
				nodef();
				break;
            case F4:
				nodef();
				break;
            case 27:            // Escape
				c = 0;
				break;
        }
    } while(c != 0);
    return c;
}
Esempio n. 9
0
/** LCD (RPM Menu) **/
void rpmMenu(void){
    _INT1IF = LOW;                  //set INT1 flag back to zero 
    _INT2IF = LOW;                  //set INT2 flag back to zero 
    
    clearLCD();
    setCursor(1,0);
    putsLCD("Set RPM to: ");
    myBOOLs.mainMenuTrue = FALSE;   // these determine which menu for ext interrupt 2
    myBOOLs.modeMenuTrue = FALSE;   // these determine which menu for ext interrupt 2
    myBOOLs.rpmMenuTrue = TRUE;     // these determine which menu for ext interrupt 2
    while(myBOOLs.rpmDecide){
        period = ((8000000*60)/(1600*rpm));
        if(period != period_old){
            PR3 = period-1;
            duty = period/2; 
            OC1R = OC1RS = duty;    // duty cycle to 50%
        }
        sprintf(strRPM,"%lu",rpm);
        setCursor(1,12);
        putsLCD(strRPM);
        putsLCD("   ");
        period_old = period;
    }
}
Esempio n. 10
0
/* test task for keypad */
int keypad_task(void)
{
    int ii;
    static int cnt = 0;
    char temp[10];
    //keypad_init();

//    while(1) {
        for (ii=0; ii<16; ii++) {
            if (keypad_GetButton(ii)) {
                LCD_Cursor_New(2, 0);
                sprintf(temp, "%X", ii);
                putsLCD((unsigned char *)temp);
                if (++cnt >= 20) {
                    cnt = 0;
                }
            }
        }

//        LCD_Delay200usX(5); /* 1ms */
//    }
    return 0;
}
Esempio n. 11
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
Esempio n. 13
0
void main(void) {


    unsigned int i,b;
    unsigned long int n, q, k[3];
    char j=0;


    char *msg1,*msg2,*msg3,*msg4;   //messages to display

    msg1 = "Enter decimal:";
    msg2 = "Hex conversion:";
    msg3 = "Not valid input";
    msg4 = "Max range 65535";

start:

    n = 0;                          //initialize to 0
    q = 5;                          //initialize to not 0

    openLCD();                      //turn LCD on
    cmd2LCD(0x01);                  //clear LCD
    delayms(10);                    //wait of LCD to clear
    putsLCD(msg1);                  //display first message
    cmd2LCD(0xC0);                  //go to second line


    while (1)
    {

keyin:
        i= getkey1();               //get key from keypad
        delayms(10);                //wait to ensure debounce

        if(i == 0x0A) {             //if i=A (enter key)
            goto dec2hex;             //convert decimal to hex
        }
        else if (i > 0x0A) {        //if i not a valid input

            cmd2LCD(0x01);            //clear LCD
            delayms(10);              //wait for LCD to be cleared
            putsLCD(msg3);            //display third message
            exit();                   //exit program
        }

        if((n*10+i) > 0xFFFF) {    //if n exceeds limit
            cmd2LCD(0x01);            //clear LCD
            delayms(10);              //wait for LCD to be cleared
            putsLCD(msg4);            //display message 4
            exit();
        }

        j= (char)i;                //turn i into char
        j=j+0x30;                  //convert hex to ASCII
        putcLCD(j);                //display ASCII to LCD


        n = n*10 +i;               //keep track of decimal value
        delayms(5);
        goto keyin;                //get another key


dec2hex:

        cmd2LCD(0x01);              //clear LCD
        delayms(10);                //wait for LCD to clear
        putsLCD(msg2);              //display message 2
        cmd2LCD(0xC0);              //go to second line

        b = 0;                      //set b to 0
        while(q != 0) {             //while quotient is not 0
            q = n/16;               //quotient is equal to number/16
            k[b] = n%16;            //store remainder in array
            n /= 16;                //new number value
            b ++;
        }

        while(b !=0) {             //display array values to LCD
            b --;                     //decrease b
            if(k[b] < 10) {           //if number add 0x30 for ASCII
                k[b] = k[b] + 0x30;
            } else {                  //if letter add 0x37 for ASCII
                k[b] = k[b] + 0x37;
            }
            putcLCD((char)k[b]);      //display ASCII to LCD
        }
        exit();


    }
}
Esempio n. 14
0
int main(void)
{
    init_serial();
    initLCD();
    initRadio();

    unsigned char volume = getVolume();

    // tune this bitch to 102.7
    seek(FM, UP, 1);
    tuneStatus();

    char lcdStr[33];

    putsLCD("Radio!", LCD_SAMELINE);

    enum DisplayModes dispMode;
    int refresh = 0;

    while(1) {
        if(available_serial() >= 6) {
            char current = read_serial();
            if(current != 128) {
                continue;
            }
            refresh = 1;
            // read the 4-bytes length
            long length = (long)read_serial() << 24;
            length |= (long)read_serial() << 16;
            length |= (long)read_serial() << 8;
            length |= (long)read_serial();

            current = read_serial();
            char opcode = (current & 0xE) >> 5;
            switch(opcode) {
                case TUNE:
                {
                    enum Band band = current & 0x10 >> 4;
                    char freq_b = read_serial();
                    int freq = convert_freq(band, freq_b);
                    //tuneStation(band, freq);
                    if(band == FM) {
                        sprintf(lcdStr, "Tune FM: %d", freq);
                    }
                    else {
                        sprintf(lcdStr, "Tune AM: %d", freq);
                    }
                    break;
                }
                case TUNE_PRESET:
                {
                    enum Band band = current & 0x10 >> 4;
                    int preset = current & 0x0F;
                    //tunePreset(band, preset);
                    if(band == FM) {
                        sprintf(lcdStr, "Tune FM Preset: %d", preset);
                    }
                    else {
                        sprintf(lcdStr, "Tune AM Preset: %d", preset);
                    }
                }
                    break;
                case VOLUME:
                {
                    enum Direction dir = current & 0x10 >> 4;
                    if(dir == UP) {
                        ++volume;
                    }
                    else {
                        --volume;
                    }
                    //setVolume(volume);
                    sprintf(lcdStr, "Volume %d", volume);
                }
                    break;
                case BAND:
                {
                    enum Band band = current & 0x10 >> 4;
                    //tuneStation(band, getLastStation(band));
                    if(band == FM) {
                        sprintf(lcdStr, "Band set to FM");
                    }
                    else {
                        sprintf(lcdStr, "Band set to AM");
                    }
                }
                    break;
                case SET_PRESET:
                {
                    enum Band band = current & 0x10 >> 4;
                    int preset = current & 0x0F;
                    char freq_b = read_serial();
                    int freq = convert_freq(band, freq_b);
                    //setPreset(band, preset, freq);
                    if(band == FM) {
                        sprintf(lcdStr, "Set FM Preset %d: %d", preset,  freq);
                    }
                    else {
                        sprintf(lcdStr, "Set AM Preset %d: %d", preset,  freq);
                    }
                    break;
                }
                    break;
                case NEXT:
                {
                    enum Direction dir = current & 0x10 >> 4;
                    enum Mode mode = current & 0x0C >> 2;
                    if(mode == PRESET) {
                        currentPreset += (dir) ? 1 : -1;
                        if(currentPreset < 0) currentPreset = 5;
                        if(currentPreset > 5) currentPreset = 0;
                        //tunePreset(currentBand, currentPreset);
                        sprintf(lcdStr, "Tune preset %d", currentPreset);

                    }
                    else if(mode == FREQUENCY) {
                        int currentFreq = getFrequency();
                        currentFreq += (dir) ? 10 : -10;
                        if(currentBand == FM) {
                            if(currentFreq < FM_MIN_FREQ) currentFreq = FM_MAX_FREQ;
                            if(currentFreq > FM_MAX_FREQ) currentFreq = FM_MIN_FREQ;
                            sprintf(lcdStr, "Tune FM %d", currentFreq);
                        }
                        else {
                            if(currentFreq < AM_MIN_FREQ) currentFreq = AM_MAX_FREQ;
                            if(currentFreq > AM_MAX_FREQ) currentFreq = AM_MIN_FREQ;
                            sprintf(lcdStr, "Tune AM %d", currentFreq);
                        }
                        tuneStation(currentBand, currentFreq);
                    }
                    else if(mode == SCAN) {
                        //seek(currentBand, dir);
                        sprintf(lcdStr, "Seek activated");
                    }
                }
                    break;
                case DISPLAY:
                {
                    dispMode = (current & 0x1C) >> 2;
                    sprintf(lcdStr, "Set displayMode %d", dispMode);
                }
                    break;
            }
        }
        if(refresh) {
            refresh = 0;
            clearLCD();
            putsLCD(lcdStr, LCD_NEXTLINE);
            LCD_DELAY(0xFFFF);
            LCD_DELAY(0xFFFF);
            LCD_DELAY(0xFFFF);
        }
    }
Esempio n. 15
0
/*------------------MAIN FUNCTION------------------*/
int main(void)
{  
    __builtin_write_OSCCONL(2); // Enable secondary oscillator with unlock sequence
    T1CON = 0x8012; // Enable T1 from external oscillator (SECONDARY), pre-scaler of 8)
    T2CON = 0x8000;
    PR1 = 410;      // this value generates an interrupt every 100 milliseconds (Primary)

    /*------------------CONFIGURE INTERRUPTS------------------*/
    INTCON2bits.INT0EP = 0;     // interrupt on positive edge
    INTCON2bits.ALTIVT = 0;     // use primary IVT
    IPC0bits.T1IP = 4;          // set priority level to 4 (100)
    IFS0bits.T1IF = 0;          // initialize T1 flag to zero
    IEC0bits.T1IE = 1;          // enable the T1 timer interrupt source
    
    TRISBbits.TRISB2 = 0; // Used as Register Select for LCD
    initPMP();
    initLCD();
    
    setLCDG(0);
    putLCD(0b00000);
    putLCD(0b10001);
    putLCD(0b00000);
    putLCD(0b00100);
    putLCD(0b00000);
    putLCD(0b10001);
    putLCD(0b01110);
    putLCD(0);
    
    putLCD(0b00000);
    putLCD(0b10001);
    putLCD(0b00000);
    putLCD(0b00100);
    putLCD(0b00000);
    putLCD(0b00000);
    putLCD(0b11111);
    putLCD(0);
    
    putLCD(0b00000);
    putLCD(0b10001);
    putLCD(0b00000);
    putLCD(0b00100);
    putLCD(0b00000);
    putLCD(0b01110);
    putLCD(0b10001);
    putLCD(0);

    int Buf = 0;
    initADC();
    //TRISB = 0xFF00; // configure LED port as outputs
    char BufString[20];
    char BufString2[5];
    char BufString3[16];
    double voltage, vAvg, avgTime;
    int i, time;
    unsigned long bufAvg;
    int nAvg = 100;
    TMR1 = 0;
    /*------------------INFINITE LOOP------------------*/
    while(1)
    {
        vAvg = 0;
        voltage = 0;
        bufAvg = 0;
        time = 0;
        avgTime = 0;
        for(i=0;i<nAvg;i++)
        {
            TMR2 = 0;
            Buf = getADC(0);    // read channel 1 of ADC
            time = TMR2;
            voltage = Buf*3.3/1023;
            vAvg = vAvg + voltage;
            bufAvg = bufAvg + Buf;
            avgTime = avgTime + time;
        }
        vAvg = vAvg/nAvg;
        bufAvg = bufAvg/nAvg;
        avgTime = avgTime/nAvg/16/1000;
        if(myBOOLs.timer_flag == TRUE)
        {
            setCursor(1,0);
            putsLCD("Voltage: ");
            sprintf(BufString,"%.02f",vAvg);
            sprintf(BufString2,"%lu",bufAvg);
            sprintf(BufString3,"%.05f",avgTime);
            setCursor(1,9);
            putsLCD(BufString);
            setCursor(1,16);
            putsLCD(BufString2);
            putsLCD("   ");
            setCursor(2,0);
            putsLCD("Time: ");
            setCursor(2,6);
            putsLCD(BufString3);
            setCursor(2,14);
            putsLCD("ms");
            setCursor(2,19);
            if(bufAvg > 1023*2/3)
                putLCD(0);
            if(bufAvg < 1023*2/3 && bufAvg > 1023*1/3)
                putLCD(1);
            if(bufAvg < 1023*1/3 && bufAvg > 0)
                putLCD(2);
            myBOOLs.timer_flag = FALSE;
        }
    }
    return (EXIT_SUCCESS);
}
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
Esempio n. 17
0
/*************************************************************************************
menu_pwm_labvaja()
*************************************************************************************/
int menu_pwm_labvaja(int c)
{   uint frekvenca;
	IN0 = 1;	// definiramo smer
	IN1 = 0;
	CR = 1;  // vkljucimo PCA
	TRIGGER = 0;
    putccLCD(1);     // brisanje ekrana
	
	do
	{
		putccLCD(1);     // brisanje ekrana
        printf("Menu pwm_labvaja:");
        gotoxyLCD(1,2);
        putsLCD("CCAP0H:");
        gotoxyLCD(12,2);
        printf("%s", itoa(CCAP0H, s));
		gotoxyLCD(1,3);
        printf("Frekvenca:");
        gotoxyLCD(1,4);
        putsLCD(" -10   -20  SET  TG0");
        do
        {
			c = (unsigned char)key_getch();
             if(refresh == 1)
			{
				refresh = 0;
				frekvenca = pulz*10000/cas;
				pulz = 0;
				cas = 0;
				gotoxyLCD(12,3);
				printf("%s", itoa(frekvenca, s));
			}
        } while(c == 0);
        switch(c)
        {
            case F1:
				if(CCAP0H > 9)
				{
					TRIGGER = 1;
				    CCAP0H = CCAP0H - 10;
				}
				gotoxyLCD(1,3);
				printf("%s", itoa(CCAP0H, s));
				break;
            case F2:
				if(CCAP0H > 19)
				{   TRIGGER = 1;
					CCAP0H = CCAP0H - 20;
				}
				gotoxyLCD(1,3);
				printf("%s", itoa(CCAP0H, s));
				break;
            case F3:
				gotoxyLCD(1,3);
				printf("Nova vrednost: ");
				gets(s);
				TRIGGER = 1;
				CCAP0H = atoi(s);
				gotoxyLCD(1,3);
				printf("%s", itoa(CCAP0H, s));
				break;
            case F4:
			if(CCAP0H < 255)
				TRIGGER = 0;
        		gotoxyLCD(1,3);
				printf("%s", itoa(CCAP0H, s));
				break;
            case 27:            // Escape
				c = 0;
				break;
        }
    } while(c != 0);
    CR = 0;		// izkljucimo PCA
    return c;
}
Esempio n. 18
0
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
Esempio n. 19
0
/** LCD (Main Menu) **/
void mainMenu(void){
    _INT1IF = LOW;                      //set INT1 flag back to zero 
    _INT2IF = LOW;                      //set INT2 flag back to zero
    int i;
    clearLCD();
    setCursor(1,1);
    putsLCD("Mode");
    setCursor(1,15);
    putsLCD("C");
    setCursor(2,1);
    putsLCD("RPM");
    setCursor(2,9);
    sprintf(strRPM,"%lu",rpm);
    putsLCD(strRPM);
    mainMenuSelect = 32766;             // this handles cursor position by means of modulus
    myBOOLs.mainMenuTrue = TRUE;        // these determine which menu for ext interrupt 2
    myBOOLs.modeMenuTrue = FALSE;       // these determine which menu for ext interrupt 2
    myBOOLs.rpmMenuTrue = FALSE;        // these determine which menu for ext interrupt 2
    while(myBOOLs.mainDecide){
        if(mainMenuSelect % 2 == 0){
            setCursor(1,0);
            putsLCD(">");
            setCursor(2,0);
            putsLCD(" ");
        }
        else if(mainMenuSelect % 2 != 0){
            setCursor(1,0);
            putsLCD(" ");
            setCursor(2,0);
            putsLCD(">");
        }

        // Take 50 readings of tempC
        tempC = 0;
        for(i=0;i<50;i++){
            tempC = tempC + thermoRead();
        }
        // Find average
        tempC = tempC/50;
        sprintf(strTempC,"%.02f",tempC);
        if(tempC < 100 && tempC >= 10){
            setCursor(1,15);
            putsLCD("C");
            setCursor(1,7);
            putLCD(' ');
            setCursor(1,8);
            putLCD(' ');
            setCursor(1,9);
            putLCD(0);
            setCursor(1,10);
        }
        else if(tempC < 10 && tempC >= 0){
            setCursor(1,15);
            putsLCD("C");
            setCursor(1,8);
            putLCD(' ');
            setCursor(1,9);
            putLCD(' ');
            setCursor(1,10);
            putLCD(0);
            setCursor(1,11);
        }
        else{
            setCursor(1,15);
            putsLCD("C");
            setCursor(1,8);
            putLCD(0);
            setCursor(1,9);
        }
        // Show averaged temp on display
        putsLCD(strTempC);
    }   
}
Esempio n. 20
0
/** Main **/
int main(void){  
    /** Declare Local Variables **/
    
    /** Initialize State Variables **/
    myBOOLs.mainMenuTrue = TRUE;    // want program to enter into the main menu
    myBOOLs.mainDecide = TRUE;      // want program to enter into the main menu
    myBOOLs.modeMenuTrue = FALSE;
    myBOOLs.modeDecide = FALSE;
    myBOOLs.rpmMenuTrue = FALSE;
    myBOOLs.rpmDecide = FALSE;
    
    /** Initialize Value Variables **/
    rpm = 60;
    
    /** Configure Analog Ports **/
    AD1PCFGbits.PCFG5 = HIGH;  // disable analog functionality for AN5 (Encoder Pin A)
    AD1PCFGbits.PCFG0 = HIGH;  // disable analog functionality for AN0 (SPI - SS)
    AD1PCFGbits.PCFG2 = HIGH;  // disable analog functionality for AN2 (SPI - SDI)
    AD1PCFGbits.PCFG4 = HIGH;  // disable analog functionality for AN4 (SPI - SCK)

    /** Configure Pin Directions **/
    TRISAbits.TRISA2 = OUTPUT;      // *output* Stepper Motor Dir
    TRISAbits.TRISA4 = OUTPUT;      // *output* Red LED Sink
    
    TRISBbits.TRISB3 = INPUT;       // *input* (Encoder Pin A) ~interrupt
    TRISBbits.TRISB4 = INPUT;       // *input* (Encoder Pin B)
    TRISBbits.TRISB9 = INPUT;       // *input* (Encoder PUSH) ~interrupt
    
    TRISAbits.TRISA0 = OUTPUT;      // *output* (SS for Thermo)
    TRISBbits.TRISB0 = INPUT;       // *input*  (SPI - SDI)
    TRISBbits.TRISB2 = OUTPUT;      // *output* (SPI - SCK)
    
    /** Initialize Pin States **/
    LATAbits.LATA2 = LOW;       // Set direction to CW
    LATAbits.LATA4 = LOW;       // Set Red LED ON (sink current)
    LATAbits.LATA0 = HIGH;      // Set SS high
    TRISBbits.TRISB2 = LOW;     // Set SCK low
    
    /** Configure Peripheral Pin Selects **/
    __builtin_write_OSCCONL(OSCCON & 0xBF); // unlock registers to configure PPS
    RPINR0bits.INT1R = 3;   // configure RP3 as Ext. Int. 1
    RPINR1bits.INT2R = 9;   // configure RP9 as Ext. Int. 2
    RPOR7bits.RP15R = 18;   // configure RP15 as OC1 (PWM for EasyDriver)
    RPOR5bits.RP10R = 19;   // configure RP11 as OC2 (PWM for buzzer)
    __builtin_write_OSCCONL(OSCCON | 0x40); // lock registers
    
    /** Configure PWMs **/
    period = ((8000000*60)/(1600*rpm));     // calculate PR based on desired PRM
    duty = period/2;                        // duty cycle of 50%
    initPWM(period, duty);                  // PWM initialization function
    initPWMbuzz();

    /** Configure PMP & LCD **/
    initPMP();
    initLCD();
    
    setLCDG(0);
    putLCD(0b00000);
    putLCD(0b01100);
    putLCD(0b01100);
    putLCD(0b01100);
    putLCD(0b11110);
    putLCD(0b11110);
    putLCD(0b01100);
    putLCD(0);
    
    /** Configure Interrupts **/
    INTCON2bits.ALTIVT = 0; //use primary IVT
    //EXT1 interrupt
    INTCON2bits.INT1EP = 1; // interrupt on falling edge
    IPC5bits.INT1IP = 4; //set priority level to 4
    IFS1bits.INT1IF = 0; //initialize INT1 flag to zero
    IEC1bits.INT1IE = 1; //enable the interrupt source
    //EXT2 interrupt
    INTCON2bits.INT2EP = 1; // interrupt on falling edge
    IPC7bits.INT2IP = 7; //set priority level to 4
    IFS1bits.INT2IF = 0; //initialize INT2 flag to zero
    IEC1bits.INT2IE = 1; //enable the interrupt source

    /** LCD Splash Screen **/
    clearLCD();
    setCursor(1,0);
    putsLCD("   Stir Plate   ");
    setCursor(2,0);
    putsLCD("      9000      ");
    delay_ms(3000);
    clearLCD();
    OC2CON = 0x0000;
    /*------------------INFINITE LOOP------------------*/
    while(1)
    {
        menuDecision();
    }
    return (EXIT_SUCCESS);
}
Esempio n. 21
0
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
Esempio n. 22
0
/*************************************************************************************
menu_time
*************************************************************************************/
int menu_time(int c)
{
    char *pt;
    char *pt1;
    uint nv;

    do
    {
        putccLCD(1);     // brisanje ekrana
        printf("Time");
        gotoxyLCD(11,2);
        putsLCD(SecToHms(value,s));
        gotoxyLCD(1,4);
        putsLCD("Comp.  -1s  +1s  SET");
        do
        {
            c = (unsigned char)key_getch();
         	if (refresh == 1)
         	{
         	     gotoxyLCD(11,2);
                 putsLCD(SecToHms(value,s));
         	     refresh = 0;
                 led_y = !led_y;
            }
        } while(c == 0);
        switch(c)
        {
            case F1:
                 gotoxyLCD(1,2);
                 printf("   1s comp = %d  ", comp);
                 gotoxyLCD(1,3);
                 putsLCD("New comp: ");
                 gets(s);
                 if (strlen(s) > 3)
                 {
                    comp = atoi(s);
                 }
                 break;
            case F2:
                 --value;
                 break;
            case F3:
                 ++value;
                 break;
            case F4:
                 gotoxyLCD(11,2);
                 putsLCD("hh.mm.ss ");
                 gotoxyLCD(1,3);
                 putsLCD("New time: ");
                 gets(s);
                 if (strlen(s) > 4)
                 {
                    pt = strchr(s, '.');   //  10.49.27
                    if (pt) *pt = 0;         //    pt
                    nv = atoi(s) * 3600;
                    pt1 = strchr(pt+1, '.'); //       pt1
                    if (pt1) *pt1 = 0;
                    nv += atoi(pt+1) * 60;
                    nv += atoi(pt1+1);
                    if (nv > 43200)
                        nv -= 43200;
                    value = nv;
                 }
                 break;
            case 27:            // Escape
                 c = 0;
                 break;
        }
    } while(c != 0);
    return c;
}