Пример #1
0
int main(void) {

	init_buttons();
	init_leds();
	init_display(intensity);
	init_uart();

	uart_interrupt_enable();

	sei();

	// main loop
	while(1) {

		// while button 1 is pressed, increment display brightness (mod 16)
		uint8_t button_status = debounce(&BUTTON0_PIN, BUTTON0);
		if(button_status == 1) {
			intensity = (intensity + 1) % 16;
			set_register_b(REG_INTENSITY, intensity);
		} else if(button_status == 2) {
			LIGHT_PORT ^= (1<<LIGHT);
		}

		// if timer is stopped (but not yet resetted) ...
		if(state == 'S') {
			
			// ... and button 0 has been pressed (and released),
			// save the current time in the times array (only once!)
			if(debounce(&BUTTON1_PIN, BUTTON1) && !time_already_saved) {
				uart_interrupt_disable();
				append(times, TIMES, last_correct_decoded_time);
				led_blink(2);
				time_already_saved = 1;
				uart_interrupt_enable();
			}

		}

		// if timer has been stopped or reset ...
		if(state == 'I' || state == 'S') {

			// ... and button 0 is pressed, show the current average
			if(!(BUTTON2_PIN & (1<<BUTTON2))) {
				uart_interrupt_disable();
				display_uint16_time(average());
				my_delay_ms(1500);
				while(!(BUTTON2_PIN & (1<<BUTTON2)));
				uart_interrupt_enable();
			}

		}
	}
}
Пример #2
0
int main(void)
{
	WDT_DISABLE; 
	BC1MSET;
	
  	USCIAB0RX_ISR_callbacks = rx_callbacks;
	
	uart_init(UART0, 1000000, 9600);
	uart_XLED_enable(UART0);
	uart_interrupt_enable(UART0);
	
	P1DIR &= ~BUTTON;
	P1REN |= BUTTON;
	P1OUT |= BUTTON;
	
	qputs(UART0, "Inited.\n");
	
	
	json_handle a;
	while (1){
 		p = text;
 		wait = 1;
 		_BIS_SR(CPUOFF + GIE);
 		wait = 0;
 		*p = '\0';
		
 		if (P1IN & BUTTON) {// Key not pressed
			a = objTest();
		}
		else {
			pos = 0;
			a = json_createObjectObj("root", json_createStringObj("response","cleared"), NULL);
		}
 
 		json_dump(text, a);
  		json_free_rude(a);
		
		
// 		int i;
// 		qputh(_uart1, 0xff & (pos >> 8));
// 		qputh(_uart1, 0xff & (pos));
// 		qputc(_uart1,'\n');
// 		for (i=0;i<PERIOD_LENGTH/2;i++){
// 			
// 			//qputs(_uart1, " 0x");
// 			qputh(_uart1, 0xff & (data[pos+i] >> 8));
// 			qputh(_uart1, 0xff & data[pos+i]);
// 		}
// 		qputs(_uart1, "\n============\n");
// 		base64enc(text, &data[pos], PERIOD_LENGTH);
		
		
  		qputs(UART0, text);
		qputc(UART0, '\n');
		//__delay_cycles(800000);
		
		
	}
	
}