void portInit( void ) { // Init all needed modules ******************************************************************** initPin( PTB5, 0x1u, 0x1u ); // PIN FOR SPEAKER IS NOT CONNECTED; INIT WITH PULLUP initPin( OUTPUT_PIN( PIN_LED0 ), 0x1u, 0 ); // red LED initPin( OUTPUT_PIN( PIN_LED1 ), 0x1u, 0 ); // yellow LED initPin( OUTPUT_PIN( PIN_LED2 ), 0x1u, 0 ); // green LED initPin( OUTPUT_PIN( PIN_LED3 ), 0x1u, 0 ); // 'orange' LED //initPin( PIN_IRQ_TAS0, 0x1u, 0x1u ); // PIN // SET ALL LEDS OFF BY DEFAULT (LOW-ACTIVE) SET_PIN_HIGH( PIN_LED0 ); SET_PIN_HIGH( PIN_LED1 ); SET_PIN_HIGH( PIN_LED2 ); SET_PIN_HIGH( PIN_LED3 ); }
void set_led(unsigned char sel_pin, unsigned char led_pin) { SET_PIN_OUTPUT(LED_BUTTON_PORT, led_pin); SET_PIN_LOW(LED_BUTTON_PORT, led_pin); SET_PIN_OUTPUT(LED_BUTTON_SEL_PORT, sel_pin); if (LED_STATUS(sel_pin * led_pin)) { SET_PIN_HIGH(LED_BUTTON_SEL_PORT, sel_pin); } else { SET_PIN_LOW(LED_BUTTON_SEL_PORT, sel_pin); } }
void tsk1( void ) { SET_PIN_LOW(PIN_LED0); svc_mtx_TakeMtx( (MtxNr) 0x1u, &tsk_AR[1], 100 ); SET_PIN_HIGH(PIN_LED0); SET_PIN_LOW( PIN_LED1 ); SET_PIN_LOW( PIN_LED2 ); svc_tsk_InitTsk( (TskID) 0x2u, &tsk2, &tsk_EndTheTask, MY_STACK_SIZE ); svc_tsk_SetTskPrio( (TskID) 0x2u, TSK_PRIO_HIG ); svc_tsk_ActvTsk( (TskID) 0x2u ); SET_PIN_HIGH( PIN_LED1 ); svc_tmr_SetTimer( (WaitTime) 500, &tsk_AR[1] ); svc_mtx_GiveMtx( (MtxNr) 0x1u, &tsk_AR[1] ); SET_PIN_HIGH( PIN_LED2 ); svc_tsk_KillTsk( &tsk_AR[1] ); }
void tsk2( void ) { SET_PIN_LOW( PIN_LED3 ); svc_mtx_TakeMtx( (MtxNr) 0x1u, &tsk_AR[2], 100 ); svc_tmr_SetTimer( (WaitTime) 500, &tsk_AR[2] ); SET_PIN_HIGH( PIN_LED3 ); svc_mtx_GiveMtx( (MtxNr) 0x1u, &tsk_AR[2] ); svc_tsk_KillTsk( &tsk_AR[2] ); }
void ask_poti(unsigned char sel_pin, unsigned char adc) { SET_PIN_LOW(POTI_SEL_PORT, sel_pin); _delay_us(50); ADMUX = _BV(ADLAR) | adc; ADCSRA |= _BV(ADSC); loop_until_bit_is_set(ADCSRA, ADIF); loop_until_bit_is_clear(ADCSRA, ADSC); last_adc = ADC; SET_PIN_HIGH(POTI_SEL_PORT, sel_pin); unsigned char val = convert_to_cc(last_adc); unsigned char poti = sel_pin + 8 * adc; unsigned char old = poti_status[poti] & 0x7f; if ((val != old) && ((val == 00) || (val == 0x7F) || (abs(val - old) > 1))) poti_status[poti] = 0x80 | val; }
void ask_button(unsigned char button_pin, unsigned char sel_pin) { SET_PIN_LOW(LED_BUTTON_SEL_PORT, sel_pin); SET_PIN_INPUT_PULLUP(LED_BUTTON_PORT, button_pin + 2); unsigned char val = PIN_VALUE(LED_BUTTON_PORT, button_pin + 2); SET_PIN_HIGH(LED_BUTTON_SEL_PORT, sel_pin); unsigned char button = sel_pin * BUTTON_ROWS + button_pin; switch (button_status[button]) { case BUTTON_NOTHING: if (!val) button_status[button] = BUTTON_PRESSED; break; case BUTTON_PRESSED: case BUTTON_NORMAL: if (val) button_status[button] = BUTTON_RELEASED; break; case BUTTON_RELEASED: if (val) button_status[button] = BUTTON_NOTHING; else button_status[button] = BUTTON_PRESSED; break; } }