/* Request cursor position */
void request_cursor(void)	/* unknown, probably doesnt work */
{
	row_report = 0;
	col_report = 0;
	UART_putc(0x1B);	/* ESC */
	UART_putc(0x5B);	/* [ */
	UART_putc(0x36);	/* 6 */
	UART_putc(0x6E);	/* n */	
	UART_getc();		/* ESC */
	UART_getc();		/* [ */
	row_report += (UART_getc() - 0x30) * 10;	/* Row, 10's digit */
	row_report += UART_getc() - 0x30;			/* Row, 1's digit */
	UART_getc();		/* ; */
	col_report += (UART_getc() - 0x30) * 100;	/* Column, 100's digit */
	col_report += (UART_getc() - 0x30) * 10;	/* Column, 10's digit */
	col_report += UART_getc() - 0x30;			/* Column, 1's digit */	
	if( UART_getc() == 'R' )
	{
		cursor_responded = 1;	/* Put up cursor valid flag */
	}
	else
	{
		cursor_responded = 0;
	}
}
示例#2
0
int main(void) {
	CPU_PRESCALE(CPU_8MHz); // Set CPU clock speed
	DDRB = 0b11111111;
	DDRF = 0b00000000;
	uart_init(BAUD_RATE);
	//USART_Init(USART1UBRR);
	adc_init();
	sei();
	delay_ms(100);
	uart_putchar('i');
	int idle = 99;					//ASCII zero for no user input. This is the value designated for when user is idle
	int command = idle;				// input global variable user input into switch. Switch cannot take variable directly.
	
		while(1)
		{
			switch(command)
			{
				case(0):		// Initializes all Step parameters for temperature and time
				{
					PCR_init();
					break;
				}
			
				case(1):				// Runs the PCR. User can interrupt and cancel process from phone
				{
					Run_PCR();
					command = idle;	
					break;
				}
			
				default:							// If not command is sent the PCR will enter power saving "idle mode" see ATMEGA32U4 datasheet p.44
				{
					while (command != '0' |command != '1'){
					
						// standby Mode Control Register default is off 0000 0000
						SMCR = 00000110; // turn on power saving
						command = UART_getc();
						
						// User sends a "?" to initiate communication firmware sends "t" to confirm ready to receive.
						if(command == '?'){
								uart_putchar('t');
								command = idle;	
						}
					}
					SMCR = 00000000;
				}
			}
		}
	return 0;
}
示例#3
0
//--------------------------------------------------------------------------//
// Function:	main														//
//--------------------------------------------------------------------------//
void main(void)
{
	int c;
	
  //inicjalizacje
	Init_Interrupts();
	LED_Init();
  UART_initialize(115200);
	
  //jakiœ tam komunikat powitalny
	UART_putc('H');
	UART_putc('e');
	UART_putc('l');
	UART_putc('l');
	UART_putc('o');
	
	for (;;)
	{
    //odbieramy znak i odbijamy go na terminal
		c = UART_getc();
		UART_putc(c);
		
    //w zale¿noœci od tego co przysz³o, prze³¹czamy stan jednej z diod
    switch (c)
		{
			case '1':
				*pPORTFIO_TOGGLE = 0x0040;
				break;
			case '2':
				*pPORTFIO_TOGGLE = 0x0080;
				break;
			case '3':
				*pPORTFIO_TOGGLE = 0x0100;
				break;
			case '4':
				*pPORTFIO_TOGGLE = 0x0200;
				break;
			case '5':
				*pPORTFIO_TOGGLE = 0x0400;
				break;
			case '6':
				*pPORTFIO_TOGGLE = 0x0800;
				break;
		}
	}
}
示例#4
0
文件: uart.c 项目: OS-Project/OnlyOS
void UART_stdioRead(unsigned char *rxBuff, unsigned char rxByte)
{
    unsigned int inputCount = 0u;

    while((rxByte != '\r') && (rxByte != ' '))
    {
        UART_putc(rxByte);

        /* Account for the backspace to allow user to edit the input */
        if(('\b' == rxByte) && (inputCount > 0))
        {
            rxBuff--;
            inputCount--;
        }
        else
        {
            *rxBuff++ = rxByte;
            inputCount++;
        }
        rxByte = UART_getc();
    }
    /* Add the delimiting character at the end of the buffer */
    *rxBuff = rxByte;
}
示例#5
0
文件: main.c 项目: altanis/AVR
/**
 * Main program loop
 */
int main(void)
{        
	DDRD = 0xff;
	PORTD = 0xf0;	
	PORTD |= _BV(3);
	
	UART_init(16000000, 19200);			
	LCD_init();
	PCF8583_init();
		
	PCF8583_set_time(12,00,0,0);
	PCF8583_set_date(24,1,2013);
	
	//set the alarm off
	PCF8583_get_status();
	PCF8583_status|=4;
	PCF8583_write(0,PCF8583_status);
	
	cbi(PORTD, 6);
	
	u16 code;
	
	LCD_clear();
	
	get_temperatureSilent();
	power_on();	
	while(1)
	{		
		if(m_requiresSettings == SETTING_ALL)
		{
			updateTime();
			updateTemperature();
			dayNightDecision();	
		}
		
		
			power_on();	
			
			code = decode_rc5();
			if ( code != 0 )
			{
				remote_switch(code);
				while ( UART_unread_data() ) UART_getc();
			}			
		
		//if uart recieved something
		if ( (PC_get_msg() == PC_CONNECT) & bit_is_clear(PORTD, 6) )
		{
			PC_connecting_show();
			do
			{		
				show_PC_menu();		
				code = PC_get_msg();				
				PC_switch( code );				
			}
			while( code != PC_DISCONNECT );
			PC_disconnecting_show();
		}		
	}	
	return 0;
}