Exemple #1
0
ISR(TIMERB1, serialRxTimerInterrupt)
{
    // start of reception
    if (serialRxEnabled[0]
            && serialRecvCb[0]
            && pinRead(UART0_RX_PORT, UART0_RX_PIN) == 0) {x
        // start bit detected on UART0!

        TBCCTL2 = OUT;
        TBCCR2 += UART_HALF_BITTIME - 100;
        while (0 == (TBCCTL2 & CCIFG));

        rxByte0();
    }
    else if (serialRxEnabled[1]
            && serialRecvCb[1]
            && pinRead(UART1_RX_PORT, UART1_RX_PIN) == 0) {
        // start bit detected on UART1!

        TBCCTL2 = OUT;
        TBCCR2 += UART_HALF_BITTIME - 100;
        while (0 == (TBCCTL2 & CCIFG));

        rxByte1();
    }

    // heuristic value...
    TBCCR2 = TBR + UART_HALF_BITTIME;
    TBCCTL2 = CCIE;
}
Exemple #2
0
static void processButtons()
{
	bool isPressed[3];
	isPressed[BTN_UP]		= !pinRead(BTN_UP_P);
	isPressed[BTN_SELECT]	= !pinRead(BTN_SELECT_P);
	isPressed[BTN_DOWN]		= !pinRead(BTN_DOWN_P);

	LOOPR(BTN_COUNT, i)
		processButton(&buttons[i], isPressed[i]);
}
Exemple #3
0
// proces zajistujici zpracovani prikazu od uzivatele
// Bezi v nekonecne smycce a testuje zda bylo stisknuto tlacitko.
// Pokud ano, provede prislusnou akci.
void prikazy(void * pvParameters)
{
	int n = 0;
	(void) pvParameters; /* parameter not used */

	while (1) {

		LCD_clear();
		LCD_puts("Na uctu:");
		sprintf(buff, "%d", BankaOperace(0));
		LCD_puts(buff);
		LCD_set_cursor(2, 1);
		LCD_puts("SW1=START");

		// cekani na tlacitko
		while (pinRead(SW1) != 0) {
			;
		}

		VkladBezi = 1;
		VyberBezi = 1;

		// Spustime procesy simulujici vklad a vyber...
		vTaskResume(TaskVklad);
		vTaskResume(TaskVyber);

		while (VkladBezi || VyberBezi) {
			;
		}

		// Po zastaveni procesu vkladu i vyberu pokracujeme zde..
		// a umoznime opakovat simulaci
		VypisVysledek();
		ZapisUcet(10000);   // nastavit konto na pocatecni castku
		nVyberu = 0;
		nVkladu = 0;
		// cekani na tlacitko
		while (pinRead(SW1) != 0) {
			;
		}
	}
}
void ButtonEventSource::poll( unsigned int interval_ms /*= 5*/ )
{
    for (unsigned int i = 0; i < ARRAY_SIZE(pin_to_button_map); ++i) {
        PinMapEntry *ent = pin_to_button_map + i;
        int status = pinRead(ent->pin);
        if (status_table[i] != status) {
            status_table[i] = status;
            callback(ButtonEvent(ent->player, ent->button, status == LOW));
        }
    }
    delay(interval_ms);
}
Exemple #5
0
static void rxByte1(void)
{
    uint8_t rxByte, bitnum;
    bool rxOk;
    uint16_t i;

#if USE_SW_SERIAL_INTERRUPTS
    udelay(75);
#endif

  restart:
    rxByte = 0;
    TBCCR2 = TBR;
    for (bitnum = 0; bitnum < 8; ++bitnum) {
        // wait for next data bit
        TBCCTL2 = OUT;
        TBCCR2 += UART_BITTIME;
        while (0 == (TBCCTL2 & CCIFG));

        rxByte |= pinRead(UART1_RX_PORT, UART1_RX_PIN) << bitnum;
    }

    // wait for the stop bit
    TBCCTL2 = OUT;
    TBCCR2 += UART_BITTIME;
    while (0 == (TBCCTL2 & CCIFG));
    // ok if stop bit is 1
    rxOk = pinRead(UART1_RX_PORT, UART1_RX_PIN);

    if (rxOk) serialRecvCb[1](rxByte);
    else redLedToggle();

    // receive next byte immediately, do not wait for the next int
    for (i = 0; i < 1000; ++i) {
        if (!pinRead(UART0_RX_PORT, UART0_RX_PIN)) {
            udelay(50);
            goto restart;
        }
    }
}
void checkPB()
{
	static bool pressed_last = 0;
	bool pb_val = pinRead(&PB_PORT, PB_PIN);
	if(!pb_val && !pressed_last)
	{
		//pushbutton pressed
		use_RB_total = !use_RB_total;
		pressed_last = 1;
	}
	else
	{
		//if(pressed_last == 1)
		//{
			pressed_last = 0;
		//}
	}	
}
Exemple #7
0
uint8_t syncByte(Pin SCK_PIN,
                 Pin MOSI_PIN,
                 Pin MISO_PIN,
                 uint8_t byte) {

    uint8_t byteIn = 0x00;

    for (uint8_t i = 0; i<8; ++i) {
        pinLow(SCK_PIN);
        if (byte & 0x80) {
            pinHigh(MOSI_PIN);
        } else {
            pinLow(MOSI_PIN);
        }
        byteIn = (byteIn << 1 ) | pinRead(MISO_PIN);
        pinHigh(SCK_PIN);
    }
    return byteIn;
}
Exemple #8
0
// Reset to known state (as per what the DS3231 datasheet says)
void i2c_resetState()
{
	bit_clr(TWCR, TWEN); // Disable TWI
	pinMode(SDA, INPUT);
	pinPullup(SDA, PULLUP_ENABLE);
	delay(1);

	// Toggle SDL until SDA goes HIGH or times out
	byte count = 64; // 64 * 1ms = 64ms timeout
	while(!pinRead(SDA) && count--)
	{
		delay(1);
		pinWrite(SDL, TOGGLE);
	}

	// Back to normal
	pinMode(SDA, OUTPUT);
	pinMode(SDL, OUTPUT);
	pinWrite(SDA, HIGH);
	pinWrite(SDL, HIGH);
}
Exemple #9
0
/*----------------------------------------------------------------------------*/
void pinToggle(struct Pin pin)
{
  pinWrite(pin, !pinRead(pin));
}