Exemplo n.º 1
0
int multi_view_mode(char previous) {
    sensor_changer(&sensor_selector, &previous);
    lcd_display_top_row("Mult");
    lcd_display_bottom_row();
    //use sweep_num to see what stage of 'turning' the object is at

    char a = read_keypad(33);
    if (a == 'A'&& previous != a) {
        SYSTICK_IntCmd(DISABLE);
        clear_display(59);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 0;
    }
    else if (a == 'B'&& previous != a) {
        SYSTICK_IntCmd(DISABLE);
        clear_display(59);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 1;
    }
    else if (a == 'C'&& previous != a) {
        servoreset();
        SYSTICK_IntCmd(ENABLE);
        clear_display(59);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 2;
    }
    else if (a == 'D'&& previous != a) {
        servoreset();
        SYSTICK_IntCmd(ENABLE);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 3;
    }
    else {
        keypad_change_servo_speed(&turnspeed, a, &previous);
        keypad_change_servo_start_pos(&servo_start, a, &previous);
        keypad_change_servo_stop_pos(&servo_stop, a, &previous);
        keypad_change_sample_rate(&samplerate, a, &previous);
        keypad_activate_interrupt(a, &previous);
        average_calculator(us_dist_arr, ir_dist_arr, array_counter, &us_avg, &ir_avg);
        previous = keypad_check(a, previous);

        //distanceircalc();
        //RTC_AlarmIntConfig((LPC_RTC_TypeDef *) LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
        //RTC_SetAlarmTime((LPC_RTC_TypeDef *) LPC_RTC, RTC_TIMETYPE_SECOND, 1);
        return 3;
    }
}
Exemplo n.º 2
0
void run_app()
{
	void (*user_code_entry)(void);

	unsigned *p;	// used for loading address of reset handler from user flash

	//NVIC_DeInit();
	//NVIC_SCBDeInit();

	SYSTICK_Cmd(0);
	SYSTICK_IntCmd(0);

	/* Change the Vector Table to the USER_FLASH_START
	in case the user application uses interrupts */
	SCB->VTOR = (FLASH_START_ADDR & 0x1FFFFF80);

	// Load contents of second word of user flash - the reset handler address
	// in the applications vector table
	p = (unsigned *)(FLASH_START_ADDR + 4);

	// Set user_code_entry to be the address contained in that second word
	// of user flash
	user_code_entry = (void *) *p;

	// Jump to user application
    user_code_entry();

}
Exemplo n.º 3
0
int tape_measure_mode(char previous) {
    sensor_changer(&sensor_selector, &previous);
    count = 18;
    lcd_display_top_row("Tape");
    lcd_display_bottom_row();


    char a = read_keypad(33);
    if (a == 'A'&& previous != a) {
        SYSTICK_IntCmd(DISABLE);
        clear_display(59);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 0;
    }
    else if (a == 'B'&& previous != a) {
        SYSTICK_IntCmd(DISABLE);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 1;
    }
    else if (a == 'C'&& previous != a) {
        servoreset();
        SYSTICK_IntCmd(ENABLE);
        clear_display(59);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 2;
    }
    else if (a == 'D'&& previous != a) {
        servoreset();
        SYSTICK_IntCmd(ENABLE);
        clear_display(59);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 3;
    }
    else {
        //distanceircalc();
        //RTC_AlarmIntConfig((LPC_RTC_TypeDef *) LPC_RTC, RTC_TIMETYPE_SECOND, DISABLE);
        PWM_MatchUpdate((LPC_PWM_TypeDef *) LPC_PWM1,2,18,PWM_MATCH_UPDATE_NOW);
        keypad_change_sample_rate(&samplerate, a, &previous);
        average_calculator(us_dist_arr, ir_dist_arr, array_counter, &us_avg, &ir_avg);
        previous = keypad_check(a, previous);
        return 1;
    }
}
Exemplo n.º 4
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	PINSEL_CFG_Type PinCfg;
	TIM_TIMERCFG_Type TIM_ConfigStruct;
	TIM_MATCHCFG_Type TIM_MatchConfigStruct;

	// Conifg P1.28 as MAT0.0
	PinCfg.Funcnum = 3;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 1;
	PinCfg.Pinnum = 28;
	PINSEL_ConfigPin(&PinCfg);

	/* P3.26 as STCLK */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 3;
	PinCfg.Pinnum = 26;
	PINSEL_ConfigPin(&PinCfg);

	// Initialize timer 0, prescale count time of 10uS
	TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
	TIM_ConfigStruct.PrescaleValue	= 10;

	// use channel 0, MR0
	TIM_MatchConfigStruct.MatchChannel = 0;
	// Disable interrupt when MR0 matches the value in TC register
	TIM_MatchConfigStruct.IntOnMatch   = TRUE;
	//Enable reset on MR0: TIMER will reset if MR0 matches it
	TIM_MatchConfigStruct.ResetOnMatch = TRUE;
	//Stop on MR0 if MR0 matches it
	TIM_MatchConfigStruct.StopOnMatch  = FALSE;
	//Toggle MR0.0 pin if MR0 matches it
	TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_TOGGLE;
	// Set Match value, count value of 10 (10 * 10uS = 100uS --> 10KHz)
	TIM_MatchConfigStruct.MatchValue   = 10;

	TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
	TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct);
	TIM_Cmd(LPC_TIM0,ENABLE);

	GPIO_SetDir(0, (1<<0), 1); //Set P0.0 as output

	//Use P0.0 to test System Tick interrupt
	/* Initialize System Tick with 10ms time interval
	 * Frequency input = 10kHz /2 = 5kHz
	 * Time input = 10ms
	 */
	SYSTICK_ExternalInit(5000, 10);
	//Enable System Tick interrupt
	SYSTICK_IntCmd(ENABLE);
	//Enable System Tick Counter
	SYSTICK_Cmd(ENABLE);

	while(1);
	return 1;
}
Exemplo n.º 5
0
 /*********************************************************************//**
 * @brief 		Initial System Tick with Config
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void SYSTICK_Config(void)
{
  //Initialize System Tick with 10ms time interval
  SYSTICK_InternalInit(1);
  //Enable System Tick interrupt
  SYSTICK_IntCmd(ENABLE);
  //Enable System Tick Counter
  SYSTICK_Cmd(ENABLE);
}
/*********************************************************************//**
 * @brief       c_entry: Main program body
 * @param[in]   None
 * @return      None
 **********************************************************************/
void c_entry (void)
{
    uint8_t* pDest =    (uint8_t*)VTOR_OFFSET;
    uint8_t* pSource = NULL;
    GPIO_Init();
    
    /* Initialize debug via UART0
     * – 115200bps
     * – 8 data bit
     * – No parity
     * – 1 stop bit
     * – No flow control
     */
    debug_frmwrk_init();

    // print welcome screen
    print_menu();

    GPIO_SetDir(BRD_LED_1_CONNECTED_PORT, BRD_LED_1_CONNECTED_MASK, 1);

    _DBG(" Remapping Vector Table at address: ");

    _DBH32(VTOR_OFFSET); _DBG_("");

    NVIC_SetVTOR(VTOR_OFFSET);

    /* Copy Vector Table from 0x00000000 to new address
     * In ROM mode: Vector Interrupt Table is initialized at 0x00000000
     * In RAM mode: Vector Interrupt Table is initialized at 0x10000000
     * Aligned: 256 words
     */


#ifdef __RAM_MODE__ //Run in RAM mode
  pSource =  (void*)0x10000000;
  memcpy(pDest,pSource , 256*4);
#else
  pSource = (void*)0x00000000;
  memcpy(pDest,pSource , 256*4);
#endif

    _DBG_(" If Vector Table remapping is successful, LED P2.10 will blink by using\n\r SysTick interrupt");
    //Initialize System Tick with 100ms time interval
    /* Input parameter for SysTick in range 0..174 ms */
    SYSTICK_InternalInit(100);

    //Enable System Tick interrupt
    SYSTICK_IntCmd(ENABLE);

    //Enable System Tick Counter
    SYSTICK_Cmd(ENABLE);

    while(1);

}
Exemplo n.º 7
0
void Timer_Init(void) {
  
        SystemCoreClockUpdate(); // Получим текущую частоту CPU !
  //Инициализируем System Tick на интервал 1ms
	SYSTICK_InternalInit(1);
  // Для порядка запрещаем работу таймера
        SYSTICK_Cmd(DISABLE);
  // Разрешаем прерывания от таймера
       	SYSTICK_IntCmd(ENABLE);
  // Обнуляем счетчик миллисекунд
        msTicks = 0;
}
Exemplo n.º 8
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	//Use P0.0 to test System Tick interrupt
	GPIO_SetDir(0, (1<<0), 1); //Set P0.0 as output

	//Initialize System Tick with 10ms time interval
	SYSTICK_InternalInit(10);
	//Enable System Tick interrupt
	SYSTICK_IntCmd(ENABLE);
	//Enable System Tick Counter
	SYSTICK_Cmd(ENABLE);

	while(1);
	return 1;
}
int main(void)
{
    CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCGPIO, ENABLE);
    GPIO_SetDir(1, 1 << 18, 1);

    SYSTICK_InternalInit(1);  // 1ms entre ticks
    SYSTICK_IntCmd(ENABLE);   // Habilita interrupcion SYSTICK
    SYSTICK_Cmd(ENABLE);      // Habilita timer SYSTICK

    while(1)
    {
    	Delay(100);
    	GPIO_ClearValue(1, 1 << 18);
    	Delay(250);
    	GPIO_SetValue(1, 1 << 18);
    }
}
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	//Use P0.0 to test System Tick interrupt
	GPIO_SetDir(1, (1<<28), 1); //Set P0.0 as output

	_DBG("Remapping Vector Table at address: ");
	_DBH32(VTOR_OFFSET); _DBG_("");
	NVIC_SetVTOR(VTOR_OFFSET);

	/* Copy Vector Table from 0x00000000 to new address
	 * In ROM mode: Vector Interrupt Table is initialized at 0x00000000
	 * In RAM mode: Vector Interrupt Table is initialized at 0x10000000
	 * Aligned: 256 words
	 */

#if(__RAM_MODE__==0)//Run in ROM mode
	memcpy(VTOR_OFFSET, 0x00000000, 256*4);
#else
	memcpy(VTOR_OFFSET, 0x10000000, 256*4);
#endif

	_DBG_("If Vector Table remapping is successful, LED P1.28 will blink by using SysTick interrupt");
	//Initialize System Tick with 100ms time interval
	SYSTICK_InternalInit(100);
	//Enable System Tick interrupt
	SYSTICK_IntCmd(ENABLE);
	//Enable System Tick Counter
	SYSTICK_Cmd(ENABLE);

	while(1);
	return 1;
}
Exemplo n.º 11
0
/*********************************************************************//**
 * @brief       c_entry: Main program body
 * @param[in]   None
 * @return      None
 **********************************************************************/
void c_entry (void)
{
    GPIO_Init();
    
    //Use GPIO to test System Tick interrupt
    GPIO_SetDir(PIO_PORT_USED, PIO_PIN_VALUE, 1);

    //Initialize System Tick with 10ms time interval
    SYSTICK_InternalInit(10);

    //Enable System Tick interrupt
    SYSTICK_IntCmd(ENABLE);

    //Enable System Tick Counter
    SYSTICK_Cmd(ENABLE);

    while(1);
    
}
Exemplo n.º 12
0
int main() {
	BOOT_INIT;

	#ifdef LED_PORT
		LED_PORT->FIODIR |= 1<<LED_PIN;
	#endif
		//init_printf(NULL, vcom_putc);
		//printf("a\n");
//	#ifdef LED_PORT
//		LED_PORT->FIOCLR |= 1<<LED_PIN;
//	#endif

	int rstsrc = LPC_SC->RSID & 0xF;
	uint8_t wdreset = (rstsrc & (1<<2)) /*|| rstsrc == 0*/;

	LPC_SC->RSID = 0xF;

#ifdef P2_10_RESET
	if(!(LPC_GPIO2->FIOPIN & 1<<10)) {
		LPC_SC->RSID = 0xF;
		NVIC_SystemReset();
	}
#endif

	if(!BOOT_ENTRY_CONDITION) {
		if(!wdreset && user_code_present()
#ifdef P2_10_RESET
		&& !(LPC_GPIO2->FIODIR & (1<<10))
#endif

		) {
			//delay_busy(1000);
			execute_user_code();
		}
	}

	SystemInit();
	_segs_init();

	//uart_init();
	//init_printf(NULL, vcom_putc);

	SYSTICK_InternalInit(1);
	SYSTICK_IntCmd(ENABLE);
	SYSTICK_Cmd(ENABLE);

#ifdef USB_CONNECT_PORT
	USB_CONNECT_PORT->FIODIR |= 1<<USB_CONNECT_PIN;
#ifdef USB_CONNECT_INVERT
	USB_CONNECT_PORT->FIOSET |= 1<<USB_CONNECT_PIN;
#endif
#endif

	USBInit();

	USBRegisterDescriptors(abDescriptors);
	//USBHwRegisterDevIntHandler(on_usb_device_status);

	usb_boot_init();

	usbConnect(TRUE);

	NVIC_EnableIRQ(USB_IRQn);

	//printf("labas\n");
	uint8_t timeout = 50;

	while(1) {

		//LED_PORT->FIOSET |= 1<<LED_PIN;


#ifdef LED_PORT
		delay_busy(80);
		LED_PORT->FIOSET |= 1<<LED_PIN;
		delay_busy(80);
		LED_PORT->FIOCLR |= 1<<LED_PIN;
#else
		delay_busy(160);
#endif
		timeout--;
		if(timeout == 0 && wdreset && dfu_state == DFU_STATE_dfuIDLE) {
			//LPC_SC->RSID |= 1<<2; //clear wd reset bit
			usbConnect(FALSE);
			NVIC_SystemReset();
		}

#ifdef P2_10_RESET
		// if P2.10 is low, reset the system to enter ISP
		if(!(LPC_GPIO2->FIOPIN & 1<<10)) {
			NVIC_SystemReset();
		}
#endif


	}
}
Exemplo n.º 13
0
Arquivo: timer.c Projeto: Q-Mart/EMPR
void timer_disable_systick(void)
{
    SYSTICK_IntCmd(DISABLE);
}
Exemplo n.º 14
0
int calibration_mode(char previous) {
    sensor_changer(&sensor_selector, &previous);
    count = 18;
    PWM_MatchUpdate((LPC_PWM_TypeDef *) LPC_PWM1,2,18,PWM_MATCH_UPDATE_NOW);


    char a = read_keypad(33);
    /*
    Selector to change the mode using the keypad keys A,B,C and D. Replicated in the rest of the modes too.
    When the system is started for the first time, it starts in calibration mode and requests its values unless one of the
    B, C or D keys is held at startup.
    */
    if (a == 'A'&& previous != a) {
        SYSTICK_IntCmd(DISABLE);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 0;
    }
    else if (a == 'B'&& previous != a) {
        SYSTICK_IntCmd(DISABLE);
        clear_display(59);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 1;
    }
    else if (a == 'C'&& previous != a) {
        servoreset();
        SYSTICK_IntCmd(ENABLE);
        clear_display(59);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 2;
    }
    else if (a == 'D'&& previous != a) {
        servoreset();
        SYSTICK_IntCmd(ENABLE);
        clear_display(59);
        char a = read_keypad(33);
        previous = keypad_check(a, previous);
        return 3;
    }
    else {
        int ir_calib_arr[3];
        int us_calib_arr[3];
        int ir_reported;
        int us_reported;
        int ir_calib_val;
        int us_calib_val;
        int u = 0;
        char write[2];
        strcpy(write, "");
        /*
        Code to get values from the keypad. The user places an object at a set distance away from the head, enters how far it is from
        the head, then finalises this value with the # key. If a mistake is made, the screen can be cleared with the A key,
        Then repostions it closer or further and enters the new distance.
        This is repeated once more to obtain three different calibration values.
        */
        while(calib_tracker <3) {
            if (u == 1000) {
                sensor_changer_cali_mode(&sensor_selector, &previous);
                int addr = 0x80;
                int i;
                for(i=0; i < strlen("Input actual dist: "); i++) {
                    addr = alloc_lcd_addr(addr, i, "Input actual dist: ");
                }
                for(i=0; i < strlen(write); i++) {
                    addr = alloc_lcd_addr(addr, i, write);
                }
                char x;
                x = read_keypad(33);
                if (x == previous) {
                    previous = x;
                }
                else if (x != 'Z' && x != previous) {
                    if (x == 'A') {
                        clear_display(59);
                        strcpy(write, "");
                        previous = x;
                    }
                    else if (isalpha(x) || x == '*' || isdigit(x)) {
                        addr = 0x80;
                        append(write, x);
                        clear_display(59);
                        for(i=0; i < strlen("Input actual dist: "); i++) {
                            addr = alloc_lcd_addr(addr, i, "Input actual dist: ");
                        }
                        for(i=0; i < strlen(write); i++) {
                            addr = alloc_lcd_addr(addr, i, write);
                        }
                        previous = x;
                    }
                    else if(x == '#') {
                        clear_display(59);
                        int act_val = atoi(write);
                        int anglemax = ((servo_stop-8)*9);
                        int anglemin = ((servo_start-8)*9);
                        int angle = ((count-8)*9);
                        char port3[90] = "";
                        sprintf(port3, ";%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;\n\r", ir_raw, us_raw, ir_dist, us_dist, angle, anglemax, anglemin, act_val, sweep_num, multicheck, mode, newmulti);
                        write_usb_serial_blocking(port3 ,90);
                        ir_reported = ir_dist;
                        char port[3] = "";
                        sprintf(port, "%i", ir_reported);
                        //write_usb_serial_blocking("ir_report: ", 11);
                        //write_usb_serial_blocking(port, 3);
                        //write_usb_serial_blocking("\n\r", 2);
                        us_reported = us_dist;
                        char port1[3] = "";
                        sprintf(port1, "%i", us_reported);
                        //write_usb_serial_blocking("us_report: ", 11);
                        //write_usb_serial_blocking(port1, 3);
                        //write_usb_serial_blocking("\n\r", 2);
                        ir_calib_val = (act_val - ir_reported);
                        us_calib_val = (act_val - us_reported);
                        ir_calib_arr[calib_tracker] = ir_calib_val;
                        us_calib_arr[calib_tracker] = us_calib_val;
                        calib_tracker++;
                        strcpy(write, "");
                        previous = x;
                    }
                }
                else if (x == 'Z' && previous != 'Z') {
                    previous = 'Z';
                }
            }
            else {
                u++;
            }
        }
        /*
        If the calibration values have been entered, but the calibration is not yet complete, this calculates the calibration adjustments
        for both IR and US, then sets calibrated_flag to stop them from being recalculated.
        */
        if (calibrated_flag == 0) {
            for (calib_tracker = 0; calib_tracker <3; calib_tracker++) {
                ir_calib_total += ir_calib_arr[calib_tracker];
                us_calib_total += us_calib_arr[calib_tracker];
            }
            calibrated_flag = 1;
            ir_calibration_adjust = ir_calib_total/3;
            us_calibration_adjust = us_calib_total/3;
            char port1[3] = "";
            sprintf(port1, "%i", ir_calib_total);
            /*write_usb_serial_blocking("IR total: ", 8);
            write_usb_serial_blocking(port1, 3);
            write_usb_serial_blocking("\n\r", 2);*/
            char port2[3] = "";
            sprintf(port2, "%i", us_calib_total);
            /*write_usb_serial_blocking("US total: ", 8);
            write_usb_serial_blocking(port2, 3);
            write_usb_serial_blocking("\n\r", 2);*/
            char port3[3] = "";
            sprintf(port3, "%i", ir_calibration_adjust);
            /*write_usb_serial_blocking("IR adjust: ", 9);
            write_usb_serial_blocking(port3, 3);
            write_usb_serial_blocking("\n\r", 2);*/
            char port4[3] = "";
            sprintf(port4, "%i", us_calibration_adjust);
            /*write_usb_serial_blocking("US adjust: ", 9);
            write_usb_serial_blocking(port4, 3);
            write_usb_serial_blocking("\n\r", 2);*/
        }

        lcd_display_top_row("Cali");
        lcd_display_bottom_row();
        //distanceircalc();
        //RTC_AlarmIntConfig((LPC_RTC_TypeDef *) LPC_RTC, RTC_TIMETYPE_SECOND, DISABLE);
        //keypad_change_sample_rate(&samplerate, a, &previous);
        average_calculator(us_dist_arr, ir_dist_arr, array_counter, &us_avg, &ir_avg);
        previous = keypad_check(a, previous);
        return 0;
    }
}