void check_buttons(void) { // sample buttons unsigned char temp = PINC & 0x0f; if (temp == old_buttons) return; old_buttons = temp; unsigned char trigger = ~temp & 0x0f; if (!trigger) return; if (trigger & 1) select_cam(0); else if (trigger & 2) select_cam(1); else if (trigger & 4) select_cam(2); else if (trigger & 8) select_cam(3); }
// ============================================================================== // - main // ------------------------------------------------------------------------------ int main(void) { // ------------------------- Initialize Hardware //PORTB: LEDs DDRB = 0x0f; PORTB = 0x00; // PORTC: Buttons DDRC = 0x00; // set all pins to input PORTC = 0x0f; // pullups // PORTD: 4066 control, interrupt, rx/tx DDRD = 0xf2; // init UART UCSR0B = ( 1 << UCSZ02); UCSR0C = /*( 1 << UPM1) | */( 1 << UCSZ01) | ( 1 << UCSZ00 ); // Even Parity, 9 bit, 1 stop bit UBRR0H = 0; UBRR0L = 249; // 5000 baud (F_CPU/16/BAUD - 1) //TODO check speed, we're on 20mhz now!!! // enable Pinchange Interrupt on PC5 -> PCINT13 PCICR = (1 << PCIE1); PCMSK1 = (1 << PCINT13); // enable external interrupt /*EICRA = (1 << ISC01) | (1 << ISC00); EIMSK = (1 << INT0);*/ sei(); tx_state = idle_tx; UCSR0B |= (1 << TXEN0); // turn on uart select_cam(0); unsigned long tt; unsigned char idx; // ------------------------- Main Loop while(1) { /*tt++; if (tt > 100000) { tt = 0; idx++; idx%=4; PORTB = 1 << idx; }*/ wdt_reset(); check_uart(); //check_buttons(); } return 0; }
// ============================================================================== // - main // ------------------------------------------------------------------------------ int main(void) { // ------------------------- Initialize Hardware //PORTB: LEDs DDRB = 0x0f; PORTB = 0x00; // PORTC: Buttons DDRC = 0x00; // set all pins to input PORTC = 0x0f; // pullups // PORTD: 4066 control, interrupt, rx/tx, USB DDRD = 0xf2; // init UART UCSR0B = ( 1 << UCSZ02); UCSR0C = /*( 1 << UPM1) | */( 1 << UCSZ01) | ( 1 << UCSZ00 ); // Even Parity, 9 bit, 1 stop bit UBRR0H = 0; UBRR0L = 249; // 5000 baud (F_CPU/16/BAUD - 1) // enable Pinchange Interrupt on PC5 -> PCINT13 PCICR = (1 << PCIE1); PCMSK1 = (1 << PCINT13); usbDeviceConnect(); usbReset(); usbInit(); wdt_enable(WDTO_1S); // enable watchdog timer sei(); tx_state = idle_tx; UCSR0B |= (1 << TXEN0); // turn on uart select_cam(0); unsigned long tt; unsigned char idx; // ------------------------- Main Loop while(1) { wdt_reset(); usbPoll(); // see if there's something going on on the usb bus check_uart(); } return 0; }
// ------------------------------------------------------------------------------ // - usbFunctionSetup // ------------------------------------------------------------------------------ uchar usbFunctionSetup(uchar data[8]) { if(data[1] == POLL){ // GET ALL ad_values reply[0] = 255; // this comes from the old gnuswitch, mixlevel, does not make sense anymore reply[1] = on_tally_idx; reply[2] = 0; usbMsgPtr = reply; return 3; } else if(data[1] == SET_TALLY) { // Start Bootloader for reprogramming the gnusb uint8_t c = data[2]; c %= 4; select_cam(c); } else if(data[1] == cmd_StartBootloader) { // Start Bootloader for reprogramming the gnusb startBootloader(); } return 0; }
// ============================================================================== // - main // ------------------------------------------------------------------------------ int main(void) { // ------------------------- Initialize Hardware //PORTB: LEDs DDRB = 0x0f; PORTB = 0x00; // PORTC: Buttons DDRC = 0x00; // set all pins to input PORTC = 0x0f; // pullups // PORTD: 4066 control, interrupt, rx/tx, USB DDRD = 0xf2; // timer 0 -> millisecond clock ticks = 0; TCCR0A = (1 << WGM01); // CTC TCCR0B = (0 << CS02) | (1 << CS01) | (0 << CS00); // 8 prescaler @ 20Mhz -> 2'500'000 Hz TIMSK0 = (1 << OCIE0A); // enable interrupt OCR0A = 249; // 10000 Hz -> 10 ticks / Millisecond // init UART UCSR0B = ( 1 << UCSZ02); UCSR0C = /*( 1 << UPM1) | */( 1 << UCSZ01) | ( 1 << UCSZ00 ); // Even Parity, 9 bit, 1 stop bit UBRR0H = 0; UBRR0L = 249; // 5000 baud (F_CPU/16/BAUD - 1) // enable Pinchange Interrupt on PC5 -> PCINT13 PCICR = (1 << PCIE1); PCMSK1 = (1 << PCINT13); usbDeviceConnect(); usbReset(); usbInit(); wdt_enable(WDTO_1S); // enable watchdog timer sei(); tx_state = idle_tx; UCSR0B |= (1 << TXEN0); // turn on uart select_cam(0); unsigned long tt; unsigned char idx; // ------------------------- Main Loop while(1) { wdt_reset(); usbPoll(); // see if there's something going on on the usb bus check_uart(); if (millis()-lastTime >= 80) { check_buttons(); } } return 0; }