void store_new_wakeup(void) { uint8_t idx; IRMP_DATA wakeup_IRData; toggle_LED(); /* 5 seconds to press button on remote */ delay_ms(5000); if (irmp_get_data(&wakeup_IRData)) { wakeup_IRData.flags = 0; idx = (MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS; /* store received wakeup IRData in first wakeup slot */ eeprom_store(idx, (uint8_t *) &wakeup_IRData); toggle_LED(); } }
/** * \brief SysTick Interrupt handler. */ void SysTick_Handler( void ) { ul_tickcount++ ; // Toggle LEDs every second (ie 1000ms) if ( ul_tickcount % 1000 == 0 ) { toggle_LED() ; } }
/** * \brief PIOA interrupt handler. * */ void PIOA_Handler( void ) { uint32_t ul_status ; /* Read PIO controller status */ ul_status = SW0_PIO->PIO_ISR ; ul_status &= SW0_PIO->PIO_IMR ; /* Check pending events */ if ( (ul_status & SW0_PIN) != 0 ) { toggle_LED() ; } }
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10k ohm pull down resistor // PE1, PB1, or PA3 connected to positive logic LED through 470 ohm current limiting resistor // To avoid damaging your hardware, ensure that your circuits match the schematic // shown in Lab8_artist.sch (PCB Artist schematic file) or // Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat). int main(void){ unsigned long volatile Input; //********************************************************************** // The following version tests input on PE0 and output on PE1 //********************************************************************** TExaS_Init(SW_PIN_PE0, LED_PIN_PE1); // activate grader and set system clock to 80 MHz PORTE_Init(); EnableInterrupts(); // enable interrupts for the grader GPIO_PORTE_DATA_R |= 0x02; // turn LED on while(1){ Delayms(100); // delay of 100ms Input = GPIO_PORTE_DATA_R & 0x01; if (Input == 0x01) { // if switch (PE1) is pressed toggle_LED(); // toggle LED once } else{ GPIO_PORTE_DATA_R = 0x02; } } }
int main(void) { uint8_t buf[HID_OUT_BUFFER_SIZE-1], RepeatCounter = 0; IRMP_DATA myIRData; int8_t ret; /* first wakeup slot empty? */ uint8_t learn_wakeup = eeprom_restore(buf, (MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS); USB_HID_Init(); LED_Switch_init(); IRMP_Init(); irsnd_init(); FLASH_Unlock(); EE_Init(); Systick_Init(); while (1) { if (!AlarmValue) Wakeup(); wakeup_reset(); /* test if USB is connected to PC and command is received */ if (USB_HID_GetStatus() == USB_HID_CONNECTED && USB_HID_ReceiveData(buf) == RX_READY && buf[0] == STAT_CMD) { switch ((enum access) buf[1]) { case ACC_GET: ret = get_handler(buf); break; case ACC_SET: ret = set_handler(buf); break; case ACC_RESET: ret = reset_handler(buf); break; default: ret = -1; } if (ret == -1) { buf[0] = STAT_FAILURE; ret = 3; } else { buf[0] = STAT_SUCCESS; } /* send configuration data */ USB_HID_SendData(REPORT_ID_CONFIG, buf, ret); toggle_LED(); } /* poll IR-data */ if (irmp_get_data(&myIRData)) { if (learn_wakeup) { /* store received wakeup IRData in first wakeup slot */ eeprom_store((MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS, (uint8_t *) &myIRData); learn_wakeup = 0; } if (!(myIRData.flags)) { RepeatCounter = 0; } else { RepeatCounter++; } if (RepeatCounter == 0 || RepeatCounter >= MIN_REPEATS) { toggle_LED(); /* if macros are sent already, while the trigger IR data are still repeated, * the receiving device may crash */ check_macros(&myIRData); check_wakeups(&myIRData); } /* send IR-data */ memcpy(buf, &myIRData, sizeof(myIRData)); USB_HID_SendData(REPORT_ID_IR, buf, sizeof(myIRData)); } } }