void toggle(){ if(GPIOPinRead(GPIO_PORTF_BASE, GREEN_LED)){ GPIOPinWrite(GPIO_PORTF_BASE, GREEN_LED, 0); }else{ GPIOPinWrite(GPIO_PORTF_BASE, GREEN_LED, GREEN_LED); } }
//get Digit from IR int getDigit () // determine binary number from pulse delay { waitTime=0; while(!GPIOPinRead(GPIO_PORTB_BASE,GPIO_PIN_1)) { } if(waitTime >6) return 2; waitTime=0; while(GPIOPinRead(GPIO_PORTB_BASE,GPIO_PIN_1)) { } if(waitTime>14) return 1; else return 0; }
unsigned char Pin_Read(tPinName pin) { // Check for valid pin name if (pin == NONE || pin == ERR) return -1; // Return 1 or 0 return GPIOPinRead(pins[pin].port.base, pins[pin].offset) == 0 ? 0 : 1; }
int main(void) { //initialize the GPIO ports PortFunctionInit(); // turn LED D1 on at the beginning GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x02); bool button_first_time_pressed = false; bool button_pressed = false; float delay = 16000000/3/4; // half a second delay int turn_led_on = 1; // // Loop forever. // while(1) { if(GPIOPinRead(GPIO_PORTJ_AHB_BASE, GPIO_PIN_1)==0x00) //SW2 is pressed { button_first_time_pressed = true; button_pressed = true; } else { button_pressed = false; } // after button is pressed for the first time if(button_first_time_pressed) { if(button_pressed) { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x00); // turn off D1 SysCtlDelay(delay); // half a second delay turn_led_on = 1 - turn_led_on; // toggle between 0 and 1 if (turn_led_on) GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x01); // turn on D2 else GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x00); // turn off D2 } else // toggle LED D1 { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x00); // turn off D2 SysCtlDelay(delay); // half a second delay turn_led_on = 1 - turn_led_on; // toggle between 0 and 1 if (turn_led_on) GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x02); // turn on D1 else GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x00); // turn off D1 } } } }
// ******** OS_DownSwitch_Handler ************ // Check if time since last down press >.3s, for debouncing, call buttontask appropriately // input: none, // output: none, void EvalDirBtnsHandler(){ IntDisable(INT_GPIOE); GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_1); while(OS_MsTime() - btndown_time < 500); // Wait for 10 ms if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1) == 0){ //BUTTONTASK(); //supposed to trigger the function that button task points to // Toggle Debug LED if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) == 0) GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0); else GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0); } btndown_time=OS_MsTime(); IntEnable(INT_GPIOE); }
// ******** OS_SelectSwitch_Handler ************ // Check if time since last switch press >.3s, for debouncing, call buttontask appropriately // input: none, // output: none, void SelectBtnHandler(){ IntDisable(INT_GPIOF); GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_1); //currentTime=OS_MsTime(); while(OS_MsTime() - SDEBOUNCEPREV < 500); // Wait for 10 ms if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1) == 0){ // Toggle Debug LED if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) == 0) GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0); else GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0); BUTTONTASK(); //supposed to trigger the function that button task points to } SDEBOUNCEPREV=OS_MsTime(); IntEnable(INT_GPIOF); }
void interrupt_handler(void) { GPIOIntClear(GPIO_PORTB_BASE, GPIO_INT_PIN_2); if(GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_2) == 0x0) { isr_flag = 1; } }
char CheckSwitches() { long lSwt1; long lSwt2; chSwtPrev = chSwtCur; lSwt1 = GPIOPinRead(SWT1Port, SWT1); lSwt2 = GPIOPinRead(SWT2Port, SWT2); chSwtCur = (lSwt1 | lSwt2) >> 6; if(chSwtCur != chSwtPrev) { fClearOled = true; } return chSwtCur; }
void brakeHandler(){ GPIOIntClear(GPIO_PORTB_BASE, GPIO_INT_PIN_0); if(GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_0) == 0x0) { enableSys = 0; } }
bool Board::getLed(int32_t led) { int32_t value; if (led == LED_RED) { value = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1); if (value) return true; } if (led == LED_BLUE) { value = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2); if (value) return true; } if (led == LED_GREEN) { value = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_3); if (value) return true; } return false; }
//======================== uint8 RD_6963() { uint8 read_data; GPIOPinTypeGPIOInput(PORT_DATA6963, WHOLE_PORT ); //DATA 至数 GPIOPinWrite(PORT_SET6963 ,PIN_CE6963,0); GPIOPinWrite(PORT_SET6963,PIN_RD6963,0); read_data=(uint8)GPIOPinRead(PORT_DATA6963, WHOLE_PORT ); GPIOPinWrite(PORT_SET6963,PIN_CE6963|PIN_RD6963,PIN_CE6963|PIN_RD6963); return(read_data); }
//! With this setup it would seem like main() must be the first function in this file, otherwise //! the wrong function gets called on reset. void main(void) { volatile INT32U ulLoop; volatile INT16U event; volatile INT16U push; //Hardware upstarts initHW(); //! Start the OLED display and write a message on it RIT128x96x4Init(ulSSI_FREQUENCY); RIT128x96x4StringDraw("EMP", 15, 42, mainFULL_SCALE); RIT128x96x4StringDraw("enter the code.....", 5, 49, mainFULL_SCALE); RIT128x96x4StringDraw("SW2 SW3 SW4 SW5 SW6", 15, 57, mainFULL_SCALE); // Entry Password see under inputs // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1)); // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)); // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)); // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)); // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)); // Clean the OLED display. RIT128x96x4Clear(); // // Loop forever. // while (1) { // Statmashine function // This is where a statemachine could be added event = GetKeyEvents(); push = select_button(); statemashine(event , push); //all functions the } }
void interrupt_handler(void) { GPIOIntClear(GPIO_PORTF_BASE, GPIO_INT_PIN_2 | GPIO_INT_PIN_3); if(GPIOPinRead(port_F, GPIO_PIN_2) == 0x0) { display_flag = 1; } }
void Timer0IntHandler(void) { int i; // Limpia el flag de interrupcion TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); /* //Escribo el comando en el YEI for(i=0; i<sizeof(todos_normalizados); i++){ UARTCharPut(UART4_BASE, todos_normalizados[i]);}*/ /* //Escribo el comando en el YEI for(i=0; i<sizeof(giroscopo); i++){ UARTCharPut(UART4_BASE, giroscopo[i]);}*/ //Escribo el comando en el YEI for(i=0; i<sizeof(aceleracion); i++){ UARTCharPut(UART4_BASE, aceleracion[i]);} /* //Escribo el comando en el YEI for(i=0; i<sizeof(magnetometro); i++){ UARTCharPut(UART4_BASE, magnetometro[i]);}*/ //Escribo el comando en el YEI for(i=0; i<sizeof(orientacion); i++){ UARTCharPut(UART4_BASE, orientacion[i]);} cThisChar='0'; int contador2=0; int contador_end_lines=0; do{ cThisChar=UARTCharGet(UART4_BASE); BuffYEI[contador2]=cThisChar; contador2=contador2+1; if((cThisChar == '\n')) contador_end_lines=contador_end_lines+1; } while(contador_end_lines != 2); rc = f_open(&Fil, "BuffGPS.TXT", FA_WRITE | FA_OPEN_ALWAYS); //abre o crea un archivo rc = f_lseek(&Fil, Fil.fsize); rc = f_write(&Fil, &BuffYEI, contador2, &bw); rc = f_sync(&Fil); rc = f_close(&Fil); if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); } else { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4); } }
void displayScore () { char scoreStr[8]; if(score<0)score=0; //Dont wanna mock the user with negative scores if (score>highScore) { OrbitOledClear(); drawPusheen (); //Pusheen drawn on the right //Code for displaying high score on the left (columns 0 - 7) OrbitOledMoveTo(92, 0); OrbitOledDrawString("NEW"); OrbitOledMoveTo(88, 8); OrbitOledDrawString("HIGH"); OrbitOledMoveTo(84, 16); OrbitOledDrawString("SCORE"); OrbitOledMoveTo(84,24); sprintf(scoreStr, "%05d", score); OrbitOledDrawString (scoreStr); OrbitOledUpdate(); highScore=score; } else{ OrbitOledClear();; //Display the current score OrbitOledSetCursor (3, 2); OrbitOledPutString ("SCORE:"); OrbitOledSetCursor (10, 2); sprintf(scoreStr, "%05d", score); OrbitOledPutString (scoreStr); } long lBtn1; lBtn1 = GPIOPinRead(BTN1Port, BTN1); while(lBtn1!=BTN1){ updateLED(4); delay(100); updateLED(0); delay(100); lBtn1 = GPIOPinRead(BTN1Port, BTN1); } }
//Initialize as a master void TwoWire::begin(void) { if(i2cModule == NOT_ACTIVE) { i2cModule = BOOST_PACK_WIRE; } SysCtlPeripheralEnable(g_uli2cPeriph[i2cModule]); //Configure GPIO pins for I2C operation GPIOPinConfigure(g_uli2cConfig[i2cModule][0]); GPIOPinConfigure(g_uli2cConfig[i2cModule][1]); GPIOPinTypeI2C(g_uli2cBase[i2cModule], g_uli2cSDAPins[i2cModule]); GPIOPinTypeI2CSCL(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); I2CMasterInitExpClk(MASTER_BASE, F_CPU, false);//max bus speed=400kHz for gyroscope //force a stop condition if(!GPIOPinRead(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule])) forceStop(); //Handle any startup issues by pulsing SCL if(I2CMasterBusBusy(MASTER_BASE) || I2CMasterErr(MASTER_BASE) || !GPIOPinRead(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule])){ uint8_t doI = 0; GPIOPinTypeGPIOOutput(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); unsigned long mask = 0; do{ for(unsigned long i = 0; i < 10 ; i++) { SysCtlDelay(F_CPU/100000/3);//100Hz=desired frequency, delay iteration=3 cycles mask = (i%2) ? g_uli2cSCLPins[i2cModule] : 0; GPIOPinWrite(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule], mask); } doI++; }while(I2CMasterBusBusy(MASTER_BASE) && doI < 100); GPIOPinTypeI2CSCL(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule]); if(!GPIOPinRead(g_uli2cBase[i2cModule], g_uli2cSCLPins[i2cModule])) forceStop(); } }
//***************************************************************************** // // Called by the NVIC as a SysTick interrupt, which is used to generate the // sample interval // //***************************************************************************** void SysTickIntHandler() { // // Blink the blue LED to indicate data read from BMP180. // MAP_GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_4, ((GPIOPinRead(GPIO_PORTQ_BASE, GPIO_PIN_4)) ^ GPIO_PIN_4)); BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); }
void GpioOut::toggle(void) { // Read the old status of the pin uint32_t status = GPIOPinRead(gpio_.port, gpio_.pin); // Change the status of the pin status = (~status) & gpio_.pin; // Set the new status of the pin GPIOPinWrite(gpio_.port, gpio_.pin, status); }
/* Whether the selected button is pressed. @param button which button - must be ANY_BUTTON or BUTTON_1 or BUTTON_2 on this implementation. @return > 0 if the selected button is pressed, otherwise 0. */ uint8_t buttonIsPressed(uint8_t button) { uint32_t buttonState = GPIOPinRead(GPIO_PORTF_BASE, ALL_BUTTONS); uint32_t buttonState2 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4); if (button == ANY_BUTTON) return (((~buttonState) & LEFT_BUTTON) || ((~buttonState) & RIGHT_BUTTON) || ((~buttonState2) & GPIO_PIN_4)); if (button == BUTTON_0) return ((~buttonState) & LEFT_BUTTON); if (button == BUTTON_1) return ((~buttonState) & RIGHT_BUTTON); if (button == BUTTON_2) return ((~buttonState2) & GPIO_PIN_4); // invalid buttonId, so return false return 0; }
void Timer0IntHandler(void) { // Clear the timer interrupt TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Read the current state of the GPIO pin and // write back the opposite state if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, 0xFF); }
int button2Pressed() { if(GPIOPinRead(GPIO_PORTJ_BASE,GPIO_PIN_1) == 0) { // *shifter = 0; return 1; } /* if(GPIOPinRead(GPIO_PORTJ_BASE,GPIO_PIN_1) == 0) { // *shifter = 1; return 1; } */ return 0; }
//! With this setup it would seem like main() must be the first function in this file, otherwise //! the wrong function gets called on reset. int main(void) { volatile unsigned long ulLoop; volatile int event; //Hardware upstarts initHW(); //! Start the OLED display and write a message on it RIT128x96x4Init(ulSSI_FREQUENCY); RIT128x96x4StringDraw("Home App Control", 5, 42, mainFULL_SCALE); RIT128x96x4StringDraw("enter the code.....", 5, 49, mainFULL_SCALE); // Entry Password see under inputs // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1)); // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)); // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)); // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)); // Wait for the select key to be pressed while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)); // Clean the OLED display. RIT128x96x4Clear(); // // Loop forever. // while (1) { // This is where a statemachine could be added // Statmashine function // This is where a statemachine could be added // event = GetKeyEvents(); statemashine(GetKeyEvents()); //all functions the } }
//ISR HANDLER CTL_ISR_FN_t buttons_isr_handler(void) { int32u int_status; int_status = GPIOPinIntStatus( PUSHBUTTON_PORT, 1 ); GPIOPinIntClear( PUSHBUTTON_PORT, int_status ); if(int_status & LEFT_SWITCH) { if(GPIOPinRead(PUSHBUTTON_PORT, LEFT_SWITCH) == LEFT_SWITCH) ctl_events_set_clear(&button_events,0,L_BTN_PUSHED); else ctl_events_set_clear(&button_events,L_BTN_PUSHED,0); } if(int_status & RIGHT_SWITCH) { if(GPIOPinRead(PUSHBUTTON_PORT, RIGHT_SWITCH) == RIGHT_SWITCH) ctl_events_set_clear(&button_events,0, R_BTN_PUSHED); else ctl_events_set_clear(&button_events,R_BTN_PUSHED,0); } }
void ELEVATOR_readSwitches(){ unsigned long pressed_data; pressed_data = ( GPIOPinRead( GPIO_PORTE_BASE , (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3) ) ); g_ucKeypadSwitches = pressed_data; }
void ELEVATOR_readSelect(void){ unsigned long pressed_data; pressed_data = ( GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1) ); g_ucSelectSwitch = pressed_data; }
bool is_switch2() { if (GPIOPinRead(SWT2Port, SWT2)) { return true; } else { return false; } }
int checkProtocol(){ // skip repeating pulse sequences while(GPIOPinRead(GPIO_PORTB_BASE,GPIO_PIN_1)) { }//90 if(waitTime <80) return 0; waitTime=0; while(!GPIOPinRead(GPIO_PORTB_BASE,GPIO_PIN_1)) { } waitTime=0; while(GPIOPinRead(GPIO_PORTB_BASE,GPIO_PIN_1)) { }//24 if(waitTime <20) return 0; else return 1; }
//--------------------------------------------------------------------------- // ledToggle() // // toggles LED on Tiva-C LaunchPad //--------------------------------------------------------------------------- void ledToggle(char l) { // LED values - 2=RED, 4=BLUE, 8=GREEN if(GPIOPinRead(GPIO_PORTF_BASE, l)) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); } else { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, l); } }
void flipPancake(void) { GPIOPinIntDisable(GPIO_PORTA_BASE, GPIO_PIN_2); WaitUS(2000); GPIOPinIntClear(GPIO_PORTA_BASE, GPIO_PIN_2); if(!GPIOPinRead(GPIO_PORTA_BASE,GPIO_PIN_2)) { UARTprintf("Triggered.\n"); SetServoPosition(PANCAKE_POSITION,100*pancake); pancake = !pancake; } GPIOPinIntEnable(GPIO_PORTA_BASE, GPIO_PIN_2); }
void SonarGPIOIntHandler(void) { GPIOPinIntClear(GPIO_PORTD_BASE, GPIO_PIN_3); if (GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_3)) { status = TIMING; TIME(MAX_SONAR_TIME); } else { Sonar_Value = TimerValueGet(TIMER2_BASE, TIMER_A); status = DELAY; (*callback)(Sonar_Value); TIME(MS(10)); } }