Пример #1
0
// Configs the GPS using MTK sentences to use RMC & GGA sentences at 5Hz, and switch to 115200 baud
void gps_config_output(struct GpsConfig *gpsconfig)
{
	// Change to 115200 baud
	
	uart2_puts("$PMTK251,115200*1F\r\n");  // this can take a while if no GPS is connected
	microcontroller_delay_ms(10);
	uart2_open(115200l);
	
	// only RMC and GGA
	// RMC & GGA
	uart2_puts("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n");  // this can take a while if no GPS is connected
	microcontroller_delay_ms(10);	

	// 5Hz mode
	microcontroller_delay_ms(10);
	uart2_puts("$PMTK220,200*2C\r\n");

    if (gpsconfig->enable_waas)
    {
        microcontroller_delay_ms(10);
        // DGPS data source mode
        // ?0?: No DGPS source
        // ?1?: RTCM
        // ?2?: WAAS
        microcontroller_delay_ms(10);
        uart2_puts("$PMTK301,2*2E\r\n");

        // Enable to search a SBAS satellite or not
        // ?0? = Disable
        // ?1? = Enable
        microcontroller_delay_ms(10);
        uart2_puts("$PMTK313,1*2E\r\n");
    }
}
Пример #2
0
int main() {
    /* receive enable aktivieren, data deaktivieren */
    DDRD = (1 << PD4) | (1 << PD5) | (1 << PD6) | (1 << PD7);
    PORTD = (1 << PD6);

    /* Ziffernfeld-pins (PA0-PA7) als Eingang schalten */
    DDRA = 0;
    PORTA = 0xFF;

    /* LEDs und Summer als Ausgang schalten */
    DDRB = (1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) | (1 << PB4);

    /* Selbst-Test: Alle LEDs hintereinander für 250 ms aktivieren, ebenso den Summer */
    PORTB = 0;
    _delay_ms(250);
    PORTB = (1 << PB0);
    _delay_ms(250);
    PORTB = (1 << PB1);
    _delay_ms(250);
    PORTB = (1 << PB2);
    _delay_ms(250);
    PORTB = (1 << PB3);
    _delay_ms(250);

    PORTB = (1 << PB4);
    _delay_ms(250);
    PORTB = 0;

    memset((void*)ibuffer, '\0', sizeof(ibuffer));

    uart2_init();
    uart2_puts("Initializing RS485\r\n");
    uart1_init();

    uart2_puts("Waiting for LCD...\r\n");

    lcd_init(LCD_DISP_ON);
    uart2_puts("initialized LCD\r\n");
    lcd_clrscr();
    lcd_puts("pinpad ready\nself-test ok");
    uart2_puts("done. now accepting cmds\r\n");

    /* Timer aufsetzen: nach 1 ms soll der Interrupt ausgelöst werden. */
    /* 8 bit counter (TIMER0) */
    /* normal mode */
    TCCR0A = 0;
    /* CLK/64 */
    TCCR0B = (1 << CS01) | (1 << CS00);
    /* timer ticks: 250 */
    TCNT0 = 5;
    TIMSK0 = (1 << TOIE0);
    TIFR0 = (1 << TOV0);

    sei();

    int c;
    char keypress_buffer[COMMAND_BUFFER_SIZE + 2] =
        "^PAD c                               $\r\n";
    char bufcopy[COMMAND_BUFFER_SIZE];


    for (;;) {
        /* Handle commands received on the UART */
        if (ibuffer[sizeof(ibuffer)-2] == '$') {
            strncpy(bufcopy, (const char *)ibuffer, sizeof(bufcopy));
            /* change the end of packet marker in memory so that the next
             * packet will be accepted by the RX interrupt handler */
            ibuffer[sizeof(ibuffer)-2] = '\0';

            handle_command(bufcopy);
        }

        uint8_t sample = (PINA | (1 << 3));

		bool button_debounced = true;

        for (c = 0; c < sizeof(lookup_table) / sizeof(struct lookup_entry); c++) {
            if (sample != lookup_table[c].state || lookup_table[c].debounce != DEBOUNCE_MS) {
                button_debounced = false;
				continue;
			}
            keypress_buffer[5] = lookup_table[c].key;
            uart_puts(keypress_buffer);
            lookup_table[c].debounce = DEBOUNCE_MS+1;
        }
		if (button_debounced) {
			_delay_ms(80);
		}
    }
}
Пример #3
0
/*!
 *  Hot restarts the GPS module.
 */
void gps_hot_restart()
{
	uart2_puts("$PMTK101*32");
	uart2_putc(0x0D); uart2_putc(0x0A);
}