static void CDC_Run(void) { int i; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ // LED1_Neg(); LED2_Off(); WAIT1_Waitms(10); } // LED1_Off(); LED2_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); (void)CDC1_SendString((unsigned char*)"\r\n"); } else { WAIT1_Waitms(10); } } }
void APP_Run(void) { int i; uint32_t val = 0; unsigned char buf[16]; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LED1_Neg(); LED2_Off(); WAIT1_Waitms(10); } LED2_Off(); LED1_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"val: "); UTIL1_strcatNum32u(buf, sizeof(buf), val); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); (void)CDC1_SendString(buf); val++; } else { WAIT1_Waitms(10); } } }
static bool BL_CheckBootloaderMode(void) { /* let's check if the user presses the BTLD switch. Need to configure the pin first */ /* PTB8 as input */ /* clock all port pins */ SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK; /* Configure pin as input */ #if 0 /* GPIOB_PDDR: PDD&=~0x0100 */ GPIOB_PDDR = (uint32_t)((GPIOB_PDDR & (uint32_t)~0x0100UL) | (uint32_t)0x00UL); /* Initialization of Port Control register */ /* PORTB_PCR8: ISF=0,MUX=1 */ PORTB_PCR8 = (uint32_t)((PORTB_PCR8 & (uint32_t)~0x01000600UL) | (uint32_t)0x0100UL); #else (void)BitIoLdd3_Init(NULL); /* initialize the port pin PTB8 */ /* enable internal pull-up on PTB8 */ PORT_PDD_SetPinPullSelect(PORTB_BASE_PTR, 8, PORT_PDD_PULL_UP); PORT_PDD_SetPinPullEnable(PORTB_BASE_PTR, 8, PORT_PDD_PULL_ENABLE); WAIT1_Waitms(5); /* wait get pull-up a chance to pull-up */ #endif if (!BL_SW_GetVal()) { /* button pressed (has pull-up!) */ WAIT1_Waitms(50); /* wait to debounce */ if (!BL_SW_GetVal()) { /* still pressed */ return TRUE; /* go into bootloader mode */ } } /* BTLD switch not pressed, and we have a valid user application vector */ return FALSE; /* do not enter bootloader mode */ }
void APP_Run(void) { int cnt=0; /* counter to slow down LED blinking */ for(;;) { WAIT1_Waitms(10); cnt++; if (HIDM1_App_Task()==ERR_BUSOFF) { if ((cnt%128)==0) { /* just slow down blinking */ LEDG_Off(); LEDR_Neg(); } } else { if ((cnt%128)==0) { /* just slow down blinking */ LEDR_Off(); LEDG_Neg(); } if (SW2_GetVal()==0) { /* button pressed */ WAIT1_Waitms(100); /* wait for debouncing */ if (SW2_GetVal()==0) { /* still pressed */ //(void)HIDM1_Send(0, 8, 8); /* raw move message */ //(void)HIDM1_Send(HIDM1_MOUSE_LEFT, 0, 0); /* send left mouse button */ //(void)HIDM1_Send(0, 0, 0); /* send release button message */ //(void)HIDM1_Move(-8, 0); /* moving the cursor up */ //HIDM1_Click(HIDM1_MOUSE_LEFT); /* left mouse click */ HIDM1_Click(HIDM1_MOUSE_RIGHT); /* right mouse click */ } while(SW2_GetVal()==0) {} /* wait until button is released */ } } } }
void APP_Start(void) { PL_Init(); /* platform initialization */ //TEST_Test(); EVNT_SetEvent(EVNT_INIT); /* set initial event */ #if PL_HAS_RTOS if (FRTOS1_xTaskCreate(AppTask, (signed portCHAR *)"App", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL) != pdPASS) { for(;;){} /* error */ } RTOS_Run(); #else APP_Loop(); #endif #if 0 for(;;) { #if PL_HAS_MEALY MEALY_Step(); #else LED1_On(); WAIT1_Waitms(300); LED1_Off(); LED2_On(); WAIT1_Waitms(300); LED2_Off(); LED3_On(); WAIT1_Waitms(300); LED3_Off(); #endif } #endif /* just in case we leave the main application loop */ PL_Deinit(); }
/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ /* For example: for(;;) { } */ LCD1_Clear(); WAIT1_Waitms(1000); LCD1_WriteLineStr(1, "Hello FRDM-KL25z"); for(;;) { uint8_t cnt; uint8_t buf[5]; LCD1_GotoXY(2,1); UTIL1_Num16uToStr(buf, sizeof(buf), cnt); LCD1_WriteString((char*)buf); cnt++; WAIT1_Waitms(100); } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ LED1_On(); WAIT1_Waitms(100); LED1_Off(); LED2_On(); WAIT1_Waitms(100); LED2_Off(); LED3_On(); WAIT1_Waitms(100); LED3_Off(); CDC_Run(); /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
uint8_t setup_cc2500(void) { uint8_t returnValue=0; uint8_t initial_power = 0xFB; // 0 dBm // Set-up rx_callback function do { // Changed //spi_init(); // Initialize SPI port // FIXME Add uscib0 files cc_powerup_reset(); // Reset CCxxxx // TODO implement this wait_cycles(500); // Wait for device to reset (Not sure why this is needed) if(writeRFSettings()) // Write RF settings to config reg { returnValue = 1; // Failed break; } // FIXME Add uscib0 files cc_write_burst_reg( TI_CCxxx0_PATABLE, &initial_power, 1);//Write PATABLE // FIXME Add uscib0 files cc_strobe(TI_CCxxx0_SIDLE); WAIT1_Waitms(10); cc_strobe(TI_CCxxx0_SFRX); // Flush RXFIFO WAIT1_Waitms(10); cc_strobe(TI_CCxxx0_SFTX); // Flush RXFIFO WAIT1_Waitms(10); cc_strobe(TI_CCxxx0_SRX); // Initialize CCxxxx in RX mode. returnValue = cc_read_status(TI_CCxxx0_MARCSTATE); returnValue =0; // When a pkt is received, it will // signal on GDO0 and wake CPU // FIXME // Configure GDO0 port // GDO0_PxIES |= GDO0_PIN; // Int on falling edge (end of pkt) // GDO0_PxIFG &= ~GDO0_PIN; // Clear flag // GDO0_PxIE |= GDO0_PIN; // Enable int on end of packet CC_2500_SETUP_DONE = true; }while(0); return returnValue; }
void APP_Run(void) { int value; char buffer[64]; #if 0 for(;;) { printf("Hello world!\r\n"); LEDR_On(); WAIT1_Waitms(500); LEDR_Off(); LEDG_On(); WAIT1_Waitms(500); LEDG_Off(); } #endif for(;;) { printf("Hello world!\r\n"); printf("Please enter a name:\n\r"); scanf("%s", buffer); printf(" I have received: '%s'\r\n", buffer); printf("Please enter a number:\r\n"); scanf("%i", &value); printf(" I have received: '%i'\r\n", value); } }
void APP_Run(void) { DHTxx_ErrorCode res; uint16_t temperature, humidity; CLS1_ConstStdIOType *io = CLS1_GetStdio(); uint8_t buf[48]; #if DHTxx_SENSOR_TYPE_IS_DHT11 CLS1_SendStr("DHT11 Sensor Demo:\r\n", io->stdErr); #else CLS1_SendStr("DHT22 Sensor Demo:\r\n", io->stdErr); #endif WAIT1_Waitms(1000); /* wait one second after power-up to get the sensor stable */ for(;;) { res = DHTxx_Read(&temperature, &humidity); if (res!=DHTxx_OK) { /* error */ LEDR_Neg(); /* indicate error with red LED */ /* write error message */ CLS1_SendStr("ERROR: ", io->stdErr); CLS1_SendStr(DHTxx_GetReturnCodeString(res), io->stdErr); CLS1_SendStr("\r\n", io->stdErr); } else { /* ok! */ LEDG_Neg(); /* write data values */ UTIL1_strcpy(buf, sizeof(buf), "Temperature "); UTIL1_strcatNum32sDotValue100(buf, sizeof(buf), (int32_t)temperature); UTIL1_strcat(buf, sizeof(buf), "°C, Humidity "); UTIL1_strcatNum32sDotValue100(buf, sizeof(buf), (int32_t)humidity); UTIL1_strcat(buf, sizeof(buf), "%\r\n"); CLS1_SendStr(buf, io->stdOut); } WAIT1_Waitms(DHTxx_SENSOR_PERIOD_MS); /* can only read sensor values with a certain frequency! */ } }
static void CDC_Run(void) { int i; for(;;) { reactToButton(); int j = 0; while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ //LEDR_Neg(); LEDG_Off(); reactToButton(); if(j % 50 == 0) { LED_Neg(); } j++; WAIT1_Waitms(10); } //LEDR_Off(); LEDG_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while(i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK) { switchLEDs(in_buffer[i]); i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); (void)CDC1_SendString((unsigned char*)"\r\n"); } else { WAIT1_Waitms(10); } } }
/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ #if OPTIMIZE_BIT_ACCESS GREEN_Clr(); /* turn on green LED */ WAIT1_Waitms(1000); GREEN_Set(); /* turn off green LED */ for(;;) { if (SW1_Get()==0) { /* button low level => pressed */ RED_Clr(); /* LED cathode is connected to microcontroller pin: low level turns it on */ BLUE_Set(); /* turn off blue led */ } else { RED_Set(); /* turn off red led */ BLUE_Clr(); /* turn on blue led */ } if (SW2_Get()==0) { /* switch low level => pressed */ BLUE_Clr(); /* turn on blue led */ } else { BLUE_Set(); /* turn off blue led */ } } #else GREEN_ClrVal(GREEN_DeviceData); /* turn on green LED */ WAIT1_Waitms(1000); GREEN_SetVal(GREEN_DeviceData); /* turn off green LED */ for(;;) { if (SW1_GetVal(SW1_DeviceData)==0) { /* button low level => pressed */ RED_ClrVal(RED_DeviceData); /* LED cathode is connected to microcontroller pin: low level turns it on */ BLUE_SetVal(BLUE_DeviceData); /* turn off blue led */ } else { RED_SetVal(RED_DeviceData); /* turn off red led */ BLUE_ClrVal(BLUE_DeviceData); /* turn on blue led */ } if (SW2_GetVal(SW2_DeviceData)==0) { /* switch low level => pressed */ BLUE_ClrVal(BLUE_DeviceData); /* turn on blue led */ } else { BLUE_SetVal(BLUE_DeviceData); /* turn off blue led */ } } #endif /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* ** =================================================================== ** Event : TI1_OnInterrupt (module Events) ** ** Component : TI1 [TimerInt] ** Description : ** When a timer interrupt occurs this event is called (only ** when the component is enabled - <Enable> and the events are ** enabled - <EnableEvent>). This event is enabled only if a ** <interrupt service/event> is enabled. ** Parameters : None ** Returns : Nothing ** =================================================================== */ void TI1_OnInterrupt(void) { /* Write your code here ... */ LED_VERD_Neg();WAIT1_Waitms(333); LED_AZUL_Neg();WAIT1_Waitms(333); LED_VERM_Neg();WAIT1_Waitms(333); LED_VERD_Off(); LED_AZUL_Off(); LED_VERM_Off(); AS1_SendBlock(NULL, "Serial.", 8); }
void Cpu_OnLLSWakeUpINT(void) { uint32_t tmp; tmp = Cpu_GetLLSWakeUpFlags(); if (tmp&LLWU_INT_MODULE0) { /* LPTMR */ #if 0 LED1_On(); /* red */ WAIT1_Waitms(1); LED1_Off(); /* red */ WAIT1_Waitms(100); #endif LPTMR_PDD_ClearInterruptFlag(LPTMR0_BASE_PTR); /* Clear interrupt flag */ } }
void main(void) { /* Write your local variable definition here */ int i = 0; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ /* For example: for(;;) { } */ for(;;) { i++; if ((i%5)==0) { data[0]++; /* change data */ TestFlash(); } LED1_Neg(); WAIT1_Waitms(250); } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
static void App(void) { #if PL_CONFIG_HAS_SHELL int cntr = 0; #endif EVNT_SetEvent(EVNT_STARTUP); for(;;) { #if PL_CONFIG_HAS_EVENTS #if PL_CONFIG_EVENTS_AUTO_CLEAR EVNT_HandleEvent(APP_EvntHandler, TRUE); #else EVNT_HandleEvent(APP_EvntHandler, FALSE); #endif #endif #if PL_CONFIG_HAS_KEYS KEY_Scan(); #endif #if PL_CONFIG_HAS_TETIRS WAIT1_Waitms(50); if (TETRIS_Run()==0) { TETRIS_Start(); } #else #if PL_CONFIG_HAS_SHELL #endif #endif } }
/** * \brief Method to test the flash chip. * @return void */ static void TestFlash(void) { uint8_t errCode; uint8_t test=55; uint8_t result=27; uint32_t testAddr=0x0000F300; uint8_t status=1; FLASH_Init(); WAIT1_Waitms(1000); errCode = FLASH_ReadStatusReg(&status); if(errCode!=ERR_OK) { for(;;) {} } CLS1_SendStr((const unsigned char*)"\r\nStatus: ",CLS1_GetStdio()->stdOut); CLS1_SendNum16u(status,CLS1_GetStdio()->stdOut); for(;;) {} errCode = FLASH_WriteByte(testAddr,&test); if(errCode!=ERR_OK) { for(;;) {} } errCode = FLASH_ReadByte(testAddr,&result); if(errCode!=ERR_OK) { for(;;) {} } CLS1_SendStr((const unsigned char*)"\r\nOutput: ",CLS1_GetStdio()->stdOut); CLS1_SendNum16u(result,CLS1_GetStdio()->stdOut); }
void APP_Start(void) { EVNT_SetEvent(EVNT_INIT); #if PL_HAS_RTOS if (FRTOS1_xTaskCreate( MainTask, /* pointer to the task */ "Main", /* task name for kernel awareness debugging */ configMINIMAL_STACK_SIZE, /* task stack size */ (void*)NULL, /* optional task startup argument */ tskIDLE_PRIORITY, /* initial priority */ (xTaskHandle*)NULL /* optional task handle to create */ ) != pdPASS) { /*lint -e527 */ for(;;){} /* error! probably out of memory */ /*lint +e527 */ } FRTOS1_vTaskStartScheduler(); #else for(;;) { /* application main loop */ #if PL_HAS_SHELL SHELL_Process(); #endif #if PL_HAS_KEYS && !PL_HAS_KBI /* poll keys */ KEY_Scan(); /* poll keys */ #endif EVNT_HandleEvent(APP_HandleEvent); WAIT1_Waitms(10); } #endif }
void main(void) { /* Write your local variable definition here */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ if (FRTOS1_xTaskCreate( Task1, /* pointer to the task */ (signed portCHAR *)"Task1", /* task name for kernel awareness debugging */ configMINIMAL_STACK_SIZE, /* task stack size */ /* note: 250 without 'copy' command */ (void*)NULL, /* optional task startup argument */ tskIDLE_PRIORITY+1, /* initial priority */ (xTaskHandle*)NULL /* optional task handle to create */ ) != pdPASS) { for(;;){}; /* error! probably out of memory */ } FRTOS1_vTaskStartScheduler(); for(;;) { WAIT1_Waitms(1000); LED1_Neg(); } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
static void DrawFont(void) { FDisp1_PixelDim x, y; GDisp1_Clear(); GDisp1_UpdateFull(); x = 0; y = 0; FDisp1_WriteString("Helv8", GDisp1_COLOR_BLACK, &x, &y, Helv8_GetFont()); FDisp1_WriteString(" Helv8 BOLD", GDisp1_COLOR_BLACK, &x, &y, Helv8Bold_GetFont()); x = 0; y += Helv8_GetBoxHeight(); FDisp1_WriteString("Helv10", GDisp1_COLOR_BLACK, &x, &y, Helv10_GetFont()); x = 0; y += Helv10_GetBoxHeight(); FDisp1_WriteString("Helv12", GDisp1_COLOR_BLACK, &x, &y, Helv12_GetFont()); x = 0; y += Helv12_GetBoxHeight(); FDisp1_WriteString("Cour8", GDisp1_COLOR_BLACK, &x, &y, Cour8_GetFont()); FDisp1_WriteString(" Cour8 BOLD", GDisp1_COLOR_BLACK, &x, &y, Cour8Bold_GetFont()); x = 0; y += Cour8_GetBoxHeight(); FDisp1_WriteString("Cour10", GDisp1_COLOR_BLACK, &x, &y, Cour10_GetFont()); x = 0; y += Cour10_GetBoxHeight(); FDisp1_WriteString("Cour12", GDisp1_COLOR_BLACK, &x, &y, Cour12_GetFont()); GDisp1_UpdateFull(); WAIT1_Waitms(1000); }
void APP_Start(void) { LED1_Neg(); LED2_Neg(); LED3_Neg(); LED4_Neg(); LED5_Neg(); LED6_Neg(); LED7_Neg(); LED8_Neg(); if (FRTOS1_xTaskCreate( MainTask, /* pointer to the task */ (unsigned char *)"Main", /* task name for kernel awareness debugging */ configMINIMAL_STACK_SIZE, /* task stack size */ (void*)NULL, /* optional task startup argument */ tskIDLE_PRIORITY+1, /* initial priority */ (xTaskHandle*)NULL /* optional task handle to create */ ) != pdPASS) { /*lint -e527 */ for(;;){} /* error! probably out of memory */ /*lint +e527 */ } FRTOS1_vTaskStartScheduler(); #if 0 for(;;) { LED1_Neg(); WAIT1_Waitms(200); } #endif }
/* LCD Demo with an LCD having two E lines (E1 and E2): that makes 2x2 lines */ static void LCD_Demo1(void) { uint8_t cnt; uint8_t buf[5]; LCD1_UseDisplay(1); /* switch to upper/first display */ LCD1_Clear(); LCD1_WriteLineStr(1, "LCD Line 1"); LCD1_WriteLineStr(2, "LCD Line 2"); LCD1_UseDisplay(2); /* switch to second display */ LCD1_Clear(); LCD1_WriteLineStr(1, "Hello LCD 3"); LCD1_WriteLineStr(2, "Hello LCD 4"); cnt = 0; for(;;) { UTIL1_Num16uToStr(buf, sizeof(buf), cnt); LCD1_UseDisplay(1); /* switch to first display */ LCD1_GotoXY(2,1); LCD1_WriteString((char*)buf); LCD1_UseDisplay(2); /* switch to second display */ LCD1_GotoXY(2,1); LCD1_WriteString((char*)buf); cnt++; WAIT1_Waitms(100); } }
/* ************************************************************************** */ uint16_t LSM9DS0_begin_adv( stLSM9DS0_t * stThis, gyro_scale gScl, accel_scale aScl, mag_scale mScl, gyro_odr gODR, accel_odr aODR, mag_odr mODR ) { // Default to 0xFF to indicate status is not OK uint8_t gTest = 0xFF; uint8_t xmTest = 0xFF; byte byDatas; byte byAddress = 0x1D; byte bySubAddress = 0x0F; // Wiat for a few millis at the beginning for the chip to boot WAIT1_Waitms( 200 ); // Store the given scales in class variables. These scale variables // are used throughout to calculate the actual g's, DPS,and Gs's. stThis->gScale = gScl; stThis->aScale = aScl; stThis->mScale = mScl; // Once we have the scale values, we can calculate the resolution // of each sensor. That's what these functions are for. One for each sensor calcgRes(stThis); // Calculate DPS / ADC tick, stored in gRes variable calcmRes(stThis); // Calculate Gs / ADC tick, stored in mRes variable calcaRes(stThis); // Calculate g / ADC tick, stored in aRes variable // Now, initialize our hardware interface. if (stThis->interfaceMode == MODE_I2C) // If we're using I2C initI2C(stThis); // Initialize I2C else if (stThis->interfaceMode == MODE_SPI) // else, if we're using SPI initSPI(stThis); // Initialize SPI // To verify communication, we can read from the WHO_AM_I register of // each device. Store those in a variable so we can return them. gTest = gReadByte( stThis, WHO_AM_I_G ); // Read the gyro WHO_AM_I xmTest = xmReadByte( stThis, WHO_AM_I_XM ); // Read the accel/mag WHO_AM_I // Gyro initialization stuff: initGyro(stThis); // This will "turn on" the gyro. Setting up interrupts, etc. LSM9DS0_setGyroODR(stThis, gODR); // Set the gyro output data rate and bandwidth. LSM9DS0_setGyroScale(stThis, stThis->gScale); // Set the gyro range // Accelerometer initialization stuff: initAccel(stThis); // "Turn on" all axes of the accel. Set up interrupts, etc. LSM9DS0_setAccelODR(stThis, aODR); // Set the accel data rate. LSM9DS0_setAccelScale(stThis, stThis->aScale); // Set the accel range. // Magnetometer initialization stuff: initMag(stThis); // "Turn on" all axes of the mag. Set up interrupts, etc. LSM9DS0_setMagODR(stThis, mODR); // Set the magnetometer output data rate. LSM9DS0_setMagScale(stThis, stThis->mScale); // Set the magnetometer's range. // Once everything is initialized, return the WHO_AM_I registers we read: return (xmTest << 8) | gTest; }
void APP_Start(void) { uint8_t val=0; uint8_t range, res; uint16_t ambient; CLS1_ConstStdIOType *io = CLS1_GetStdio(); VL_Init(); /* initialize sensor driver */ for(;;) { res = VL_ReadRangeSingle(&range); if (res!=ERR_OK) { CLS1_SendStr("ERROR Range: ", io->stdErr); CLS1_SendNum8u(res, io->stdErr); } else { CLS1_SendStr("Range: ", io->stdOut); CLS1_SendNum8u(range, io->stdOut); } res = VL_ReadAmbientSingle(&ambient); if (res!=ERR_OK) { CLS1_SendStr(" ERROR Ambient: ", io->stdErr); CLS1_SendNum8u(res, io->stdErr); } else { CLS1_SendStr(" Ambient: ", io->stdOut); CLS1_SendNum16u(ambient, io->stdOut); } CLS1_SendStr("\r\n", io->stdOut); LED1_Neg(); WAIT1_Waitms(500); } }
void LINHA_ISR() { WAIT1_Waitms(10); testa1(); testa2(); testa3(); testa4(); }
void BL_Run(void) { SHELL_Init(); for(;;) { SHELL_Parse(); LEDR_Neg(); WAIT1_Waitms(100); } }
/* ===================================================================*/ void AS1_OnBlockReceived(LDD_TUserData *UserDataPtr) { /* Write your code here ... */ char *TEXTO[40]; sprintf (TEXTO, "Recbido %s\n\r", UserDataPtr ); AS1_SendBlock(NULL, TEXTO, sizeof(TEXTO)); LED_VERD_On();WAIT1_Waitms(200);LED_VERD_Off(); }
void APP_Run(void) { CLS1_ConstStdIOType *io; io = CLS1_GetStdio(); if (Test()!=ERR_OK) { CLS1_SendStr("TEST failed!\r\n", io->stdErr); } else { CLS1_SendStr("TEST ok!\r\n", io->stdOut); } Restart(); WAIT1_Waitms(1000); for(;;) { CLS1_SendStr("Hello ESP8266!\r\n", io->stdOut); Test(); WAIT1_Waitms(1000); } }
void DHT11() { byte dht11_in; byte i; // output DHT_SetDir(1); // pull-down i/o pin for 18ms DHT_ClrVal(); WAIT1_Waitms(19); DHT_SetVal(); //pull-up i/o pin for 30ms WAIT1_Waitus(30); //input DHT_SetDir(0); WAIT1_Waitus(30); while(!dht11_in) { dht11_in = DHT_GetVal();//dht11_in = PINC & _BV(DHT11_PIN); } // if (dht11_in) { // printf("dht11 start condition 1 not met\r\n"); // return; // } WAIT1_Waitus(80);//delayMicroseconds(80); // dht11_in = DHT_GetVal();//dht11_in = PINC & _BV(DHT11_PIN); // if (!dht11_in) { // printf("dht11 start condition 2 not met\r\n"); // return; // } // WAIT1_Waitus(80);//delayMicroseconds(80); // now ready for data reception for (i = 0; i < 5; i++) dht11_dat[i] = read_dht11_dat(); DHT_SetDir(1);//DDRC |= _BV(DHT11_PIN); DHT_SetVal();//PORTC |= _BV(DHT11_PIN); byte dht11_check_sum = dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]; // check check_sum if (dht11_dat[4] != dht11_check_sum) { printf("DHT11 checksum error\r\n"); } printf("Current humdity = "); printf("%d",dht11_dat[0]); printf("."); printf("%d",dht11_dat[1]); printf("%%\r\n"); printf("temperature = "); printf("%d",dht11_dat[2]); printf("."); printf("%d",dht11_dat[3]); printf("C \r\n"); // WAIT1_Waitms(2000);//delay(2000); }
/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ LED2_On(); WAIT1_Waitms(1000); LED2_Off(); #if PL_HAS_LOW_POWER LP_Init(); #endif #if PL_HAS_RTOS if (FRTOS1_xTaskCreate(BlinkTask, "Blink", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL) != pdPASS) { for(;;){} /* error */ } #endif #if PL_HAS_SHELL SHELL_Init(); #endif #if PL_HAS_RTOS PEX_RTOS_START(); #endif for(;;) { LP_EnterPowerMode(LP_WAIT); LED1_On(); WAIT1_Waitms(20); LED1_Off(); } /* For example: for(;;) { } */ /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/