Exemplo n.º 1
0
int main(void) {
	
	led2_init(); // Setup GPIO for led2 (on GPIO0.22)

	// Turn on power to TIMER2 and TIMER3
	// (TIMER0 and TIMER1 on by default)
	LPC_SC->PCONP |=  PCTIM2_POWERON | PCTIM3_POWERON;

	// Initialise all timers
	init_timer( 0, TIMER0_INTERVAL );
	init_timer( 1, TIMER1_INTERVAL );
	init_timer( 2, TIMER2_INTERVAL );
	init_timer( 3, TIMER3_INTERVAL );

	// Enable all timers
	enable_timer( 0 );
	enable_timer( 1 );
	enable_timer( 2 );
	enable_timer( 3 );

	// Enter an infinite loop, just incrementing a counter
	volatile static int i = 0 ;
	while(1) {
		i++ ;
	}
	return 0 ;
}
Exemplo n.º 2
0
// ****************
int main(void) {
	
	led2_init();	// Setup GPIO for LED2
	led2_on();		// Turn LED2 on

	// Setup SysTick Timer to interrupt at 1 msec intervals
	if (SysTick_Config(SystemCoreClock / 1000)) { 
	    while (1);  // Capture error
	}

	
	// Enter an infinite loop, just incrementing a counter and toggling leds every second
	volatile static int i = 0 ;
	while(1) {
		i++;
	    systick_delay (2000); // wait 2 seconds (2000ms)
	    led2_invert();	// Toggle state of LED2
	}
	return 0 ;
}
Exemplo n.º 3
0
// ****************
int main(void) {
	
	// Setup SysTick Timer to interrupt at 10 msec intervals
	if (SysTick_Config(SystemCoreClock / 100)) {
	    while (1);  // Capture error
	}

	led2_init();	// Setup GPIO for LED2
	led2_on();		// Turn LED2 on

	systick_delay(100);
	led2_off();
	systick_delay(100);
	led2_on();


	UARTInit(2, 9600);	/* baud rate setting */
	UARTSendCRLF(2);
	UARTSendCRLF(2);
	UARTSendStringln(2, "UART2 online ...");

	EINT3_init();





	// Enter an infinite loop, just incrementing a counter and toggling leds every second
	//led2_off();
	//int ledstate;
	uint32_t s0_msticks = 0;
	uint8_t s0_active = 0;
	uint32_t s0_state = 0;
	uint32_t s0_oldState = 0;
	uint32_t s0_newState = 0;


	//EINT3_enable();
	logger_logStringln("logger online ...");
	while(1) {

		/* process logger */
		if (logger_dataAvailable() && UARTTXReady(2)) {
			uint8_t data = logger_read();
			UARTSendByte(2,data);
		}


		if (!s0_active) {
			//s0_newState = LPC_GPIO2->FIOPIN & (S0_INPUT0);
			s0_newState = ~LPC_GPIO2->FIOPIN & (S0_INPUT0 | S0_INPUT1);
			if (s0_oldState != s0_newState) {
				s0_active = 1;
				s0_msticks = msTicks;
			}
		}

		if (s0_active && s0_msticks != msTicks) {
			s0_state = ~LPC_GPIO2->FIOPIN & (S0_INPUT0 | S0_INPUT1 );
			logger_logNumberln(s0_state);
			if (s0_state == s0_newState) {
				// falling edge
				if ((s0_newState & S0_INPUT0) > 0) {
					led2_invert();
				}

				// rising edge
				if ((s0_newState & S0_INPUT1) == 0) {
					led2_invert();
				}

			}
			s0_oldState = s0_state;
			s0_active = 0;
		}

	}
	return 0 ;
}