Exemple #1
0
int main(void)
{
    _U08 u8Config;

    ANCON0 = 0XFF;  /*Desactivamos las entradas analógicas*/
    ANCON1 = 0XFF;  /*Desactivamos las entradas analógicas*/

    Gpios_PinDirection(GPIOS_PORTD, 0, GPIOS_INPUT);  /*SCL2*/
    Gpios_PinDirection(GPIOS_PORTD, 1, GPIOS_INPUT);  /*SDA2*/
    Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*puerto de tx uart como salida*/

    (void)Uart_Init(UART_PORT1, 115200);   /*velocidad a 115200 bauds*/
    xdev_out(putChar);                     /*funcion Uart_PutChar como salida estandar*/

    I2c_Init(I2C_PORT2, 100000);           /*puerto I2C 2 a 100KHz de velocidad*/

    I2c_Start(I2C_PORT2);                                   /*generamos condicion start*/
    (void)I2c_bTxByte(I2C_PORT2, ADDR_WRITE(0b1001101));    /*madamos direccion del sensor en modo escritura*/
    (void)I2c_bTxByte(I2C_PORT2, 0x01);                     /*mandamos direccion a leer*/
    I2c_RepeatedStart(I2C_PORT2);                           /*repetimos señal start*/
    (void)I2c_bTxByte(I2C_PORT2, ADDR_READ(0b1001101));     /*madmaos direccion del sensor en modo lectura*/
    u8Config = I2c_u8RxByte(I2C_PORT2, I2C_NACK);           /*leemos dato leido y contestamos NACK*/
    I2c_Stop(I2C_PORT2);                                    /*indicamos fin de comunicacion*/

    /*mostramos por serial el byte leido el cual tendra el valor de 0x40, indica sensor listo*/
    xprintf("Registro config: 0x%X\r\n", (_U16)u8Config);

    while (1)
    {
        /*Escribe aqui tu aplicacion*/
    }
}
void bsp_init(void)
{
  SystemInit(); //系统时钟初始化
	Timer3_init();
	Systick_Init();
	LED_GPIO_Config();//LED引脚初始化
	Moto_Init();	//电机初始化
	I2c_Init();		//IIC初始化
	Delay_ms(50);

}
Exemple #3
0
//==============================================================================
int main(void)
//==============================================================================
{  // variables
  u8t  error = 0;              //variable for error code. For codes see system.h
 // u8t  userRegister;           //variable for user register
 // bt   endOfBattery;           //variable for end of battery

  nt16 sRH;                    //variable for raw humidity ticks
  ft   humidityRH;             //variable for relative humidity[%RH] as float
  nt16 sT;                     //variable for raw temperature ticks
  ft   temperatureC;           //variable for temperature[°C] as float
  //u8t  SerialNumber_SHT2x[8];  //64bit serial number

  Grace_init();
  //Init_HW();                   //initializes Hardware (osc, watchdog,...)
  I2c_Init();                  //initializes uC-ports for I2C
  DelayMicroSeconds(15000);    //wait for sensor initialization t_powerUp (15ms)

  //note: The following code segments show how to use the different functions
  //      of SHT2x. The loop does not show a typical sequence in an application

  while(1)
  { error = 0;                                       // reset error status
   /* // --- Reset sensor by command ---
    error |= SHT2x_SoftReset();

    // --- Read the sensors serial number (64bit) ---
    error |= SHT2x_GetSerialNumber(SerialNumber_SHT2x);

    // --- Set Resolution e.g. RH 10bit, Temp 13bit ---
    error |= SHT2x_ReadUserRegister(&userRegister);  //get actual user reg
    userRegister = (userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;
    error |= SHT2x_WriteUserRegister(&userRegister); //write changed user reg
*/
    // --- measure humidity with "Polling Mode" (no hold master) ---
    error |= SHT2x_MeasurePoll(HUMIDITY, &sRH);
    // --- measure temperature with "Polling Mode" (no hold master) ---
    error |= SHT2x_MeasurePoll(TEMP, &sT);

    //-- calculate humidity and temperature --
    temperatureC = SHT2x_CalcTemperatureC(sT.u16);
    humidityRH   = SHT2x_CalcRH(sRH.u16);

 /*   // --- check end of battery status (eob)---
    // note: a RH / Temp. measurement must be executed to update the status of eob
    error |= SHT2x_ReadUserRegister(&userRegister);  //get actual user reg
    if( (userRegister & SHT2x_EOB_MASK) == SHT2x_EOB_ON ) endOfBattery = true;
    else endOfBattery = false;
*/

  }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Name     I2C_EEPROM_Init
// Author   Dorin Muica
// Brief    Init I2C Module
// Param    none
//          none
// Return   none 
////////////////////////////////////////////////////////////////////////////////////////////////////
void I2C_EEPROM_Init (void)
{
  Gpio_SetPinFunction(GPIO_EEPROM_WP , gGpioNormalMode_c);  
  Gpio_SetPinDir( GPIO_EEPROM_WP, gGpioDirOut_c );
  EEPROM_WRITE_DISABLE();
  
  Gpio_SetPinFunction( gGpioPin12_c, gGpioAlternate1Mode_c ); // Peripheral Control Mode of pin #22 SCL
  Gpio_SetPinFunction( gGpioPin13_c, gGpioAlternate1Mode_c ); // Peripheral Control Mode of pin #21 SDA
  
  I2c_Init();
  I2c_Enable();
  I2c_SetConfig(&stI2cConfig);
}
Exemple #5
0
bool_t BuzzerInit(void)
{
  TmrConfig_t tmrConfig;
  TmrStatusCtrl_t tmrStatusCtrl;
  TmrComparatorStatusCtrl_t tmrComparatorStatusCtrl;
  /* Enable hw timer 1 */
  TmrEnable(gBeepTimer_c);
  /* Don't stat the timer yet */ 
  if (gTmrErrNoError_c != TmrSetMode(gBeepTimer_c, gTmrNoOperation_c)) /*set timer mode no operation*/
  {
    return FALSE;
  }
  /* Register the callback executed when an interrupt occur */
  if(gTmrErrNoError_c != TmrSetCallbackFunction(gBeepTimer_c, gTmrComp1Event_c, BuzzerTimerCallBack))
  {
    return FALSE;
  }
  tmrStatusCtrl.uintValue = 0x0000;
  tmrStatusCtrl.bitFields.OEN = 1;    //output enable
  if (gTmrErrNoError_c != TmrSetStatusControl(gBeepTimer_c, &tmrStatusCtrl))
  {
    return FALSE;
  }  
  tmrComparatorStatusCtrl.uintValue = 0x0000;
  tmrComparatorStatusCtrl.bitFields.TCF1EN = TRUE; /* Enable Compare 1 interrupt */
  if (gTmrErrNoError_c != TmrSetCompStatusControl(gBeepTimer_c, &tmrComparatorStatusCtrl))
  {
    return FALSE;
  }
  tmrConfig.tmrOutputMode = gTmrToggleOF_c; 
  tmrConfig.tmrCoInit = FALSE;  /*co-chanel counter/timers can not force a re-initialization of this counter/timer*/
  tmrConfig.tmrCntDir = FALSE;  /*count-up*/
  tmrConfig.tmrCntLen = TRUE;  /*count until compare*/
  tmrConfig.tmrCntOnce = FALSE;   /*count repeatedly*/
  tmrConfig.tmrSecondaryCntSrc = gTmrSecondaryCnt0Input_c;    /*secondary count source not needed*/
  tmrConfig.tmrPrimaryCntSrc = gTmrPrimaryClkDiv1_c;    /*primary count source is IP BUS clock divide by 1 prescaler*/
  if (gTmrErrNoError_c != TmrSetConfig(gBeepTimer_c, &tmrConfig))  /*set timer configuration */
  {
    return FALSE;
  }
  /* Config timer to raise interrupts each 0.1 ms */
  SetComp1Val(gBeepTimer_c, mToggleCompareValue_c);
  /* Config timer to start from 0 after compare event */
  SetLoadVal(gBeepTimer_c, 0);
  I2c_Init();
  Gpio_SetPinFunction(gGpioBeepTimer_c, gGpioAlternate1Mode_c); 
  Gpio_SetPinFunction(gGpioPin12_c, gGpioAlternate1Mode_c);
  Gpio_SetPinFunction(gGpioPin13_c, gGpioAlternate1Mode_c);
  return TRUE;
}
Exemple #6
0
void InitADS1115()
{
	I2c_Init();
	uint8_t conf[2];
	//Request
	I2C_StartTransmission(I2C1,I2C_Direction_Transmitter,0x90);
	I2C_Write_Data(I2C1,0x01);
	I2C_GenerateSTOP(I2C1,ENABLE);
	//Response
	I2C_StartTransmission(I2C1,I2C_Direction_Receiver,0x90);
	conf[0] = I2C_Read_ack(I2C1);
	conf[1] = I2C_Read_nack(I2C1);
	I2C_GenerateSTOP(I2C1,ENABLE);
}
Exemple #7
0
//==============================================================================
int main()
{
//==============================================================================
  uint8_t error = 0; 
 uint8_t userRegister; 
 uint16_t sRH; 
 float humidityRH; 
 char humitityOutStr[21]; 
uint16_t sT;
 float temperatureC; 
 char temperatureOutStr[21]; 
 uint8_t SerialNumber_sht21[8];
 I2c_Init();   
 { 
 error = 0; 
 error |= sht21_SoftReset();
//==============================================================================
 error |= sht21_GetSerialNumber(SerialNumber_sht21);
//==============================================================================
 error |= sht21_ReadUserRegister(&userRegister); 
 userRegister = (userRegister & ~sht21_RES_MASK) | sht21_RES_10_13BIT;
 error |= sht21_WriteUserRegister(&userRegister); 
//==============================================================================
 error |= sht21_MeasureHM(HUMIDITY, &sRH);
//==============================================================================
 error |= sht21_MeasurePoll(TEMP, &sT);
//==============================================================================
temperatureC = sht21_CalcTemperatureC(sT.u16);
humidityRH = sht21_CalcRH(sRH.u16);

printf(humitityOutStr, "Humidity RH:%6.2f %% ",humidityRH);
printf(temperatureOutStr, "Temperature:%6.2f€C",temperatureC);

DelayMicroSeconds(300000); 
}

}
Exemple #8
0
int main(void)
{
    _S08 i8Temp;

    ANCON0 = 0XFF;  /*Desativamos las entradas analógicas*/
    ANCON1 = 0XFF;  /*Desativamos las entradas analógicas*/

    Gpios_PinDirection(GPIOS_PORTD, 0, GPIOS_INPUT);  /*SCL2*/
    Gpios_PinDirection(GPIOS_PORTD, 1, GPIOS_INPUT);  /*SDA2*/
    Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*puerto de tx uart como salida*/

    (void)Uart_Init(UART_PORT1, 115200);   /*velocidad a 115200 bauds*/
    xdev_out(putChar);                     /*funcion Uart_PutChar como salida estandar*/

    I2c_Init(I2C_PORT2, 100000);           /*puerto I2C 2 a 100KHz de velocidad*/

    while (1)
    {
        i8Temp = Tc74ax_ReadTemp(TC74A5);
        /*mostramos por serial el byte leido el cual tendra el valor de la temp ambiental*/
        xprintf("Temperatura ambiente: %d\r", (_S16)i8Temp);
        Delays_ms(1000);
    }
}
Exemple #9
0
  void HW_init(void) {
    remapAllPins();

    ANCON0 = 0xFF;
    ANCON1 = 0x1F;

    IRQ0_INT_TRIS = 1;
    IRQ1_INT_TRIS = 1;

    // Config IRQ Edge = Rising
    INTCON2bits.INTEDG1 = 1;
    INTCON2bits.INTEDG2 = 1;


    PHY_IRQ0 = 0; // MRF89XA
    PHY_IRQ0_En = 1; // MRF89XA
    PHY_IRQ1 = 0; // MRF89XA
    PHY_IRQ1_En = 1; // MRF89XA    

    Data_nCS = 1;
    Config_nCS = 1;

    Data_nCS_TRIS = 0;
    Config_nCS_TRIS = 0;

    SDI_TRIS = 1;
    SDO_TRIS = 0;
    SCK_TRIS = 0;

    SSP1STAT = 0xC0;
    SSP1CON1 = 0x21;

    // reset radio
    PHY_RESETn = 1;
    PHY_RESETn_TRIS = 0;
    delay_ms(1);
    PHY_RESETn = 0;
    delay_ms(10);

    LED0_TRIS = 0;
    LED0 = 0;
    LED1_TRIS = 0;
    LED1 = 0;

    //documentation page 187
    // enabled timer,as 16 bit,internal instruction cycle, edge(x), not bypass prescaler, prescale 256
    T0CON = 0b10010111;
    TMR0H = 200; //wait more while configuration done
    INTCONbits.TMR0IE = 1;
    INTCONbits.TMR0IF = 0;
    INTCON2bits.TMR0IP = 0; //use low priority on timer0 interupts 
    
    RtccInitClock();
    RtccWrOn();
    RTCCFGbits.RTCSYNC = 1;
    RTCCALbits.CAL = 10000000;
    mRtccOn();
    mRtccWrOff();
    PIE3bits.RTCCIE = 0;

    RCONbits.IPEN = 1; //enable interupt priority levels

    INTCONbits.GIEH = 1;
    INTCONbits.GIEL = 1;
    
    spieepromInit();
    Vibra_Init();
    I2c_Init();
    
/*         
    unjoinNetwork();
    while(1);
*/    
    
    
};