Exemple #1
0
void inicializar(){
    ANSEL = 0;
    ANSELH = 0;
    Keypad_Init();                           // Initialize Keypad
    Lcd_Init();                              // Initialize Lcd
    Lcd_Cmd(_LCD_CLEAR);                      // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF);                 // Cursor off
}
/**
    The main function.
    This is called on startup and contains the main loop.
*/
int main(void)
{        
    LCD_Init();
    LCD_Clear();
    Keypad_Init();
    i2c_Init();
    PN532_init();
        
    char c;
    int writeMode = 0;
    char buffer[32] = "";

    while (1) {

        c = Keypad_WaitAndGetKey();        

        // * key pressed: toggle write mode
        if (c == '*') {
            LCD_ClearBuffer();
            buffer[0] = '\0';
            writeMode = 1 - writeMode;
            LCD_WriteString(writeMode ? "Write mode..." : "Write ended.");
        }

        // # key pressed while not in write mode: read from NFC
        else if (c == '#' && !writeMode) {
              
            LCD_WriteString("Read from NFC...");
              
            if (readStringFromNFC(buffer)) {
                LCD_WriteString(buffer); 
            } else {
               LCD_WriteString("No Data"); 
            }
              
        }

        // any key other than * pressed while in write mode: write to NFC
        else if (writeMode) {
            LCD_AppendCharToScreen(c);

            int len = strlen(buffer);
            buffer[len] = c;
            buffer[len + 1] = '\0';
            if (!writeStringToNFC(buffer)) {
                LCD_WriteString("Error 63."); 
            }
        }
        
        // otherwise: just show the pressed key
        else {
            LCD_AppendCharToScreen(c);
        }    
    }
}
Exemple #3
0
void main() {


   unsigned short kp;
   int nscale=0;
   char txt[3];

        //initializing scale
   char scale[3][3];
   scale[0][0]='H';scale[0][1]='z';scale[0][2]=' ';
   scale[1][0]='K';scale[1][1]='H';scale[1][2]='z';
   scale[2][0]='M';scale[2][1]='H';scale[2][2]='z';
   TRISA= 0;
   TRISB=0;


  Lcd_Init();                              // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Cursor off
  Lcd_Out(1, 1, "Freq:");                  // Write message text on LCD
  Lcd_Out(1, 14, "Hz");
  Lcd_Out(2,1,"Signal Generator");
  Keypad_Init();                           // Initialize Keypad
  while(1)
  {
          int freq_array[3]={0,0,0};
          unsigned long freq;

          kp=0;
          kp=Keypad_Key_Click();

          if(kp!=0 && kp!=1 && kp!=2)         //when any number is pressed
          {
                freq_array[0]=freq_array[1];
                freq_array[1]=freq_array[2];
                freq_array[2]=keyidentifier(kp);
                freq=100*freq_array[2]+10*freq_array[1]+freq_array[0];
                LongToStr(freq,txt);
                Lcd_Out(1,6,txt);
          }

          if(kp==2)         //when scale key pressed
          {
                if(nscale==2){
                        nscale=0;
                }
                else
                {
                        nscale=nscale+1;
                }
                Lcd_Out(1,14,scale[nscale]);
          }

          if(kp==1)         //when start is pressed
          {
                  if(nscale==2)
                  {
                          freq=freq*1000000;
                  }
                  else if(nscale==1)
                  {
                          freq=freq*1000;
                  }
                  else
                  {
                          freq=freq;
                  }

                  set_keyword(freq);
                  send_data_ad9850();
          }

  }

}
void main() {
  char txt[16];
  trisc=0;
  portc=0;
  Keypad_Init();
  Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);

while(1){
lcd_out(1,1,"EnterTemp=");
x=0;

do{
    kp = 0;
    
    kp = Keypad_Key_Click();
     }
     while(!kp);
     
    switch (kp) {
    
      case  1: kp = 49;previous_value=1;break; // 1
      case  2: kp = 50;previous_value=2;break; // 2
      case  3: kp = 51;previous_value=3;break; // 3
      case  4: kp = 65;break;// A
      case  5: kp = 52;previous_value=4;break;// 4
      case  6: kp = 53;previous_value=5;break; // 5
      case  7: kp = 54;previous_value=6;break; // 6
      case  8: kp = 66;break; // B
      case  9: kp = 55;previous_value=7;break; // 7
      case 10: kp = 56;previous_value=8;break; // 8
      case 11: kp = 57;previous_value=9;break; // 9
      case 12: kp = 67;break; // C
      case 13: kp = 42;break; // *
      case 14: kp = 48;previous_value=0;break;// 0
      case 15: kp = 35;break; // #
      case 16: kp = 68;break; // D

    }
    if(kp==42&&x==0){      //clear the screen
    lcd_cmd(_lcd_clear);
    shift=10;
    first=1000;
    second=1000;
    third=1000;
    desired_temp=0;
    previous_value=0;
    get_temp=0;
    real_temp=0;
    kp=0;
    x=1;
    }



    

    if(first==1000&&second==1000&&third==1000&&kp!=35&&x==0){
    first=previous_value;
    shift++;
    lcd_chr(1,shift,kp);
    }
    else if(first!=1000&&second==1000&&third==1000&&kp!=35&&x==0){
    second=previous_value;
    shift++;
    lcd_chr(1,shift,kp);
    }
    else if(first!=1000&&second!=1000&&third==1000&&kp!=35&&x==0){
    third=previous_value;
    shift++;
    lcd_chr(1,shift,kp);
    }

    if(kp==35&&x==0){
    shift++;
    lcd_chr(1,shift,kp);
    delay_ms(1000);
    if(first!=1000&&second==1000&&third==1000){
    desired_temp=first;
    }
    else if(first!=1000&&second!=1000&&third==1000){
    first=first*10;
    desired_temp=first+second;
    }
    else if(first!=1000&&second!=1000&&third!=1000){
    first=first*100;
    second=second*10;
    desired_temp=first+second+third;
    }
    while(kp==35&&x==0){
     lcd_cmd(_lcd_clear);
     get_temp=adc_read(0);
     real_temp=(500.0*get_temp)/1023;
     inttostr(real_temp,txt);
     lcd_out(2,1,"RealTemp=");
     lcd_out_cp(txt);
     while(real_temp>desired_temp){
      get_temp=adc_read(0);
     real_temp=(500.0*get_temp)/1023;
     inttostr(real_temp,txt);
     lcd_out(2,1,"RealTemp=");
     lcd_out_cp(txt);
     ac_fan=1;
     lcd_out(1,1,"cooling");
     }
     while(real_temp<=desired_temp){
      get_temp=adc_read(0);
     real_temp=(500.0*get_temp)/1023;
     inttostr(real_temp,txt);
     lcd_out(2,1,"RealTemp=");
     lcd_out_cp(txt);
      ac_fan=0;
      lcd_out(1,1,"process done");
      lcd_out(2,1,"RealTemp=");
     lcd_out_cp(txt);
     }

    }
    


    

    
    
    
    
    

    }
}
}
Exemple #5
0
int main(void) {
	char buf[22];
	int len;

	PLLCFG = (1<<5) | (4<<0); //PLL MSEL=0x4 (+1), PSEL=0x1 (/2) so 11.0592*5 = 55.296MHz, Fcco = (2x55.296)*2 = 221MHz which is within 156 to 320MHz
	PLLCON = 0x01;
	PLLFEED = 0xaa;
	PLLFEED = 0x55; // Feed complete
	while(!(PLLSTAT & (1<<10))); // Wait for PLL to lock
	PLLCON = 0x03;
	PLLFEED = 0xaa;
	PLLFEED = 0x55; // Feed complete
	VPBDIV = 0x01; // APB runs at the same frequency as the CPU (55.296MHz)
	MAMTIM = 0x03; // 3 cycles flash access recommended >40MHz
	MAMCR = 0x02; // Fully enable memory accelerator
	
	Sched_Init();
	IO_Init();
	Set_Heater(0);
	Set_Fan(0);
	Serial_Init();
	I2C_Init();
	EEPROM_Init();
	NV_Init();

	if( NV_GetConfig(REFLOW_BEEP_DONE_LEN) == 255 ) {
		NV_SetConfig(REFLOW_BEEP_DONE_LEN, 10); // Default 1 second beep length
	}

	printf("\nInitializing improved reflow oven...");
	LCD_Init();
	LCD_BMPDisplay(logobmp,0,0);

	// Setup watchdog
	WDTC = PCLKFREQ / 3; // Some margin (PCLKFREQ/4 would be exactly the period the WD is fed by sleep_work)
	WDMOD = 0x03; // Enable
	WDFEED = 0xaa;
	WDFEED = 0x55;

	uint8_t resetreason = RSIR;
	RSIR = 0x0f; // Clear it out
	printf("\nReset reason(s): %s%s%s%s", (resetreason&(1<<0))?"[POR]":"", (resetreason&(1<<1))?"[EXTR]":"",
			(resetreason&(1<<2))?"[WDTR]":"", (resetreason&(1<<3))?"[BODR]":"");

	// Request part number
	command[0] = IAP_READ_PART;
	iap_entry(command, result);
	const char* partstrptr = NULL;
	for(int i=0; i<NUM_PARTS; i++) {
		if(result[1] == partmap[i].id) {
			partstrptr = partmap[i].name;
			break;
		}
	}
	// Read part revision
	partrev=*(uint8_t*)PART_REV_ADDR;
	if(partrev==0 || partrev > 0x1a) {
		partrev = '-';
	} else {
		partrev += 'A' - 1;
	}
	len = snprintf(buf,sizeof(buf),"%s rev %c",partstrptr,partrev);
	LCD_disp_str((uint8_t*)buf, len, 0, 64-6, FONT6X6);
	printf("\nRunning on an %s", buf);

	LCD_FB_Update();
	Keypad_Init();
	Buzzer_Init();
	ADC_Init();
	RTC_Init();
	OneWire_Init();
	Reflow_Init();

	Sched_SetWorkfunc( MAIN_WORK, Main_Work );
	Sched_SetState( MAIN_WORK, 1, TICKS_SECS( 2 ) ); // Enable in 2 seconds

	Buzzer_Beep( BUZZ_1KHZ, 255, TICKS_MS(100) );

	while(1) {
		int32_t sleeptime;
		sleeptime=Sched_Do( 0 ); // No fast-forward support
		//printf("\n%d ticks 'til next activity"),sleeptime);
	}
	return 0;
}
Exemple #6
0
/*
 * @brief 初始化线程
 */
void app_init_thread(void *p)
{
	int ret;
#ifdef DEBUG_VER
	printf("app init thread startup...\r\n");
#endif

	OS_CPU_SysTickInit();

	app_init();

	Keypad_Init();

	ret = record_module_init();
	if (ret != 0)
	{
		system_err_tip();
	}

	if (recover_record_by_logfile())
	{
		system_err_tip();
	}

	if (ReadTerminalPara())
	{
		if (DefaultTerminalPara())
		{
			system_err_tip();
		}
	}

	if (g_param.device_state == DEVICE_MODE_MEM || g_param.device_state == DEVICE_MODE_SWITCH)
	{
		device_current_state = STATE_Memory_Mode;	//脱机状态
		hw_platform_led_ctrl(LED_GREEN,1);
	}
	else
	{
		device_current_state = STATE_BT_Mode_Disconnect;	//蓝牙模式未连接状态
		hw_platform_start_led_blink(LED_BLUE,150);
	}

	scanner_mod_init();

	//usb_device_init(USB_KEYBOARD);

	OSTaskCreateExt(State_Machine_thread,
		(void *)0,
		&thread_statemachine_stk[STACK_SIZE_TASKSM-1],
		8,
		8,
		&thread_statemachine_stk[0],
		STACK_SIZE_TASKSM,
		(void *)0,
		(INT16U)(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));

	OSTaskCreateExt(Event_capture_thread,
		(void *)0,
		&thread_eventcapture_stk[STACK_SIZE_TASKEC-1],
		7,
		7,
		&thread_eventcapture_stk[0],
		STACK_SIZE_TASKEC,
		(void *)0,
		(INT16U)(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));

	OSTaskCreateExt(BT_Daemon_thread,
		(void *)0,
		&thread_bt_stk[STACK_SIZE_TASKBT-1],
		6,
		6,
		&thread_bt_stk[0],
		STACK_SIZE_TASKBT,
		(void *)0,
		(INT16U)(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));

	OSTimeDlyHMSM(0,0,0,10);
	OSTaskDel(OS_PRIO_SELF);
}
int main(void)
{
	u8 Status_Flg = 0;

	Keypad_Init();
	LCD_Init();
	StepperMotor_Init();



	LCD_WriteCommand(0x80);
	LCD_WriteString("Motor Status:");

	while(1)
	{

		if( (Keypad_ReadButton(1) == 0) )
		{
			_delay_ms(150);
			Status_Flg = 1;
			LCD_WriteCommand(0xc0);
			LCD_WriteString("Right");
		}


		else if( (Keypad_ReadButton(2) == 0) )
		{
			_delay_ms(150);
			Status_Flg = 2;
			LCD_WriteCommand(0xc0);
		}


		else if( (Keypad_ReadButton(3) == 0) )
		{
			_delay_ms(150);
			Status_Flg = 3;
			LCD_WriteCommand(0xc0);
			LCD_WriteString("Brake");
		}

		if(Status_Flg == 1)
		{
			StepperMotor_Right();
		}

		else if(Status_Flg == 2)
		{
			StepperMotor_Left();
		}

		else if(Status_Flg == 3)
		{
			StepperMotor_Brake();
		}


	}

	return 0;
}