Example #1
0
uint8_t gyroscopeInit(void) {
	deviceData.handle = I2C1_Init(&deviceData);
	printf("gyroscopeInit\r\n");

	/* F_READ: Fast read mode, data format limited to single byte (auto increment counter will skip LSB)
	 * ACTIVE: Full scale selection
	 */

	L3GD20_WriteReg(L3GD20_REGISTER_CTRL_REG1, 0x0F);

	uint8_t range = 2;

	switch (range) {
	case 0:
		L3GD20_WriteReg(L3GD20_REGISTER_CTRL_REG4, 0x00);
		break;
	case 1:
		L3GD20_WriteReg(L3GD20_REGISTER_CTRL_REG4, 0x10);
		break;
	default:
		L3GD20_WriteReg(L3GD20_REGISTER_CTRL_REG4, 0x20);
		break;
	}

	return L3GD20_WriteReg(L3GD20_CTRL_REG_1,
			L3GD20_F_READ_BIT_MASK | L3GD20_ACTIVE_BIT_MASK);
}
Example #2
0
void init() {
    // Clock Initialize
    Clock_Init();    
    Timer_Init();
    _NSTDIS = 1;  //Interrupt Nesting Disable    
            
    // Digital Communication Initialize
    //UART1_Init(); 
    ADC_Init();
    I2C1_Init();    
            
    // Peripherals Initialize
    LCD_Init();
     
    // Interrupt 3 Initialize    
    SW_TRIS = TRIS_INPUT; // RA2/INT3 as input;
    
    _INT3IP = 1;
    _INT3IF = 0;
    _INT3IE = 1;
    _INT3EP = 1; //Interrupt on negative edge
    
    // Make relay drive port as output
    RELAY_SOURCE_TRIS = TRIS_OUTPUT; 
    RELAY_LED_TRIS = TRIS_OUTPUT;
    
    // Select battery as voltage source and turn on LED light
    RELAY_SOURCE = SOURCE_BATTERY; 
    RELAY_LED = TURN_OFF_LED;
    
    SDC_Start();
}
/*
void sendCoefThroughUART(void) {
signed int AC1, AC2, AC3, AC4, AC5, AC6, B1, B2, MB, MC, MD;

     AC1 = coefficients(BMP085_CAL_AC1);
     IntToStr(AC1, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     
     AC2 = coefficients(BMP085_CAL_AC2);
     IntToStr(AC2, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');

     return;
}
*/
void main() {

     genericInit();
     I2C1_Init(100000);      // Initiate I2C @ 100 kHz
     initMPU6050();
     //CallibrateMPU6050raw(); // Measures the offset values of both accelerometer and gyroscope
     initHMC5883L();
/*
     initTimer0();
     startTimer0();
     Delay_ms(1000);         // Maximum allowable time
     stopTimer0();
*/

     Delay_ms(100);                   // Wait for UART module to stabilize
     
     while(1) {
        do {} while(UART1_Read() != 's'); // Wait until start signal is received
        do {
           readAccMPU6050();
           readGyrMPU6050();
           readTmpMPU6050();
           readUTBMP085();
           readUPBMP085();
           readHMC5883Lraw();
           sendThroughUARTtoMSVS();
           //Delay_ms(1000);
        } while(UART1_Read() != 'e'); // Do until end signal is received
     }//while

     return;
}
//***********************************************************
void InitBrd(void)
{
     CLRWDT();
     OSCCON=0x70;        // $70 - Primary Clock 8MHz.
     OSCTUNE=0x40;        // 4xPLL enable, 8MHz x 4xPLL=32MHz
                          // $0 - Enabled the External Oscillator.
     TRISA=0xFF;         // PortA Register = All PortA are Inputs.
     TRISB=0xFD;         // PortB Register = RB1=Output(SW_OFF) RB0=Input(LED).
     PortB=0;            // Set the voltage to the Cellular Module.
     TRISC=0xBF;         // PortC Register = RC6-Input, Other-Outputs.
     TRISD=0x00;         // PortD Register = All PortD are Outputs.
     PortD=0;            // Set PortD output = Zero.
     TRISE=0x00;         // PortE Register = All PortE are Outputs.
     PortE=0;            // Set PortE output = Zero.
     TRISF=0x06;         // PortF Register = RF1,RF2-Input, Other-Outputs.
     PortF=0;            // Set PortF output = Zero.
     TRISG=0xFD;         // PortG Register = RG1-Output, Other-Inputs.
     ADCON0=0x00;        // A/D Control Register = A/D Off.
     ADCON1=0x0f;        // Analog Select Register = All Ports are Digital.
     I2C1_Init(100000);   // initialize clock=100kHz.
     Uart1_init(9600);  // initialize USART1 module - GSM Serial Com.
     Uart2_init(9600);  // initialize USART2 module - User Serial Com.
     PortD=0x80;         // Power-up the Cellular Module.
     Delay_ml(3000);
     PortD=0x0;
     //Soft_Uart_Init(PORTA, 0, 2, 9600, 0);
     Delay_ml(9000);
}//InitBrd
Example #5
0
/**
  * @brief  Manages error callback by re-initializing I2C.
  * @param  None
  * @retval None
  */
static void I2C1_Error(void)
{
  /* De-initialize the I2C communication BUS */
  HAL_I2C_DeInit(&heval_I2c1);
  
  /* Re-Initiaize the I2C communication BUS */
  I2C1_Init();
}
Example #6
0
int main(){
	SystemInit();
	I2C1_Init();
	BH1750_Init();
	while(1){
		uint16_t x = BH1750_Read();
		delay_ms(200);
	}
}
Example #7
0
static void serviceI2C1(void) // service the I2C
{
    if (_I2C1EN == 0)                   // I2C is off
    {
        I2C1_state = &I2C1_idle;        // disable response to any interrupts
        I2C1_Init();                    // turn the I2C back on
        // Put something here to reset state machine.  Make sure attached servies exit nicely.
    }
}
Example #8
0
/**
  * @brief  BSP of the 4 digits 7 Segment Display shield for Arduino Nano - Gravitech.
            init
  * @retval HAL_StatusTypeDef
  */
HAL_StatusTypeDef BSP_DIGIT4_SEG7_Init(void)
{
  uint8_t control[1] = {0x47};

  /* Init I2C */
  I2C1_Init();
  
  /* Configure the SAA1064 component */
  return I2C1_WriteBuffer(0x70, 0, 1, control, sizeof(control));
}
Example #9
0
void main(){
  I2C1_Init(100000);
  lcdInit();
  while(1)
  {
    Lcd_out(1,1,"Time:");
    Lcd_out(1,6,getTime());
    Lcd_out(2,1,"Date:");
    Lcd_out(2,6,getDate());
  }
}
Example #10
0
void main(void)
{

    ENTR_CRT_SECTION();
    /* Setup STM32 system (clock, PLL and Flash configuration) */
    SystemInit();

    /* Set the Vector Table base location at 0x08000000 */
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

    // SysTick end of count event each 0.5s with input clock equal to 9MHz (HCLK/8, default)
    SysTick_Config(1500000);
    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);

    // Step motor init
    StepMotorInit();
    // I2C1 init
    I2C1_Init();

    EXT_CRT_SECTION();

    // GLCD init
    GLCD_PowerUpInit((pInt8U)IAR_Logo.pPicStream); //(
    GLCD_Backlight(BACKLIGHT_ON);
    GLCD_SetFont(&Terminal_9_12_6,0x000F00,0x00FF0);
    GLCD_SetWindow(10,104,131,131);

    // Init Accl sensor
    if(FALSE == Accl_Init())
    {
        // Initialization fault
        GLCD_TextSetPos(0,0);
        GLCD_print("\fLIS3LV020 Init.\r\nfault\r\n");
        while(1);
    }
    Car_Init();
    while(1)
    {
        A=position();
        /*   A = accX[1];
           B = velX[1];
           C = posX[1]; */

        if(SysTickFl) //
        {
            SysTickFl = FALSE;
            GLCD_TextSetPos(0,0);
            GLCD_print("\f%d Deg\r\n",A);
        }

        GoCar(Test, TestTurn);
    }
}
Example #11
0
char BMP180_Init(void) {
	double c3,c4,b1;
	
	if (BMP180_I2C_PORT_NUM == 0) {
		I2C0_Init(FALSE);
	} else if (BMP180_I2C_PORT_NUM == 1) {
		I2C1_Init(FALSE);
	} else {
		I2C2_Init();
	}

	if (BMP180_I2C_ReadRegister(BMP180_ID_REGISTER) == BMP180_ID) {
		if (BMP180_ReadInt(0xAA, &AC1) &&
		BMP180_ReadInt(0xAC, &AC2) &&
		BMP180_ReadInt(0xAE, &AC3) &&
		BMP180_ReadUInt(0xB0, &AC4) &&
		BMP180_ReadUInt(0xB2, &AC5) &&
		BMP180_ReadUInt(0xB4, &AC6) &&
		BMP180_ReadInt(0xB6, &VB1) &&
		BMP180_ReadInt(0xB8, &VB2) &&
		BMP180_ReadInt(0xBA, &MB) &&
		BMP180_ReadInt(0xBC, &MC) &&
		BMP180_ReadInt(0xBE, &MD)) {
			// All reads completed successfully!

			// Compute floating-point polynominals

			c3 = 160.0 * pow(2,-15) * AC3;
			c4 = pow(10,-3) * pow(2,-15) * AC4;
			b1 = pow(160,2) * pow(2,-30) * VB1;
			c5 = (pow(2,-15) / 160) * AC5;
			c6 = AC6;
			mc = (pow(2,11) / pow(160,2)) * MC;
			md = MD / 160.0;
			x0 = AC1;
			x1 = 160.0 * pow(2,-13) * AC2;
			x2 = pow(160,2) * pow(2,-25) * VB2;
			Y0 = c4 * pow(2,15);
			Y1 = c4 * c3;
			Y2 = c4 * b1;
			p0 = (3791.0 - 8.0) / 1600.0;
			p1 = 1.0 - 7357.0 * pow(2,-20);
			p2 = 3038.0 * 100.0 * pow(2,-36);
			
			return 1;
		}
	}
	
	return 0;
}
//***********************************************************
void MemWrt(unsigned int address,unsigned char data_m)
 {
   unsigned char Add_H,Add_L;
   Add_H=((address&0xFF00)>>8);
   Add_L=(address&0x00FF);
   I2C1_Init(100000);
   I2C1_Start();
   I2C1_Wr(0xA0);
   I2C1_Wr(Add_H);
   I2C1_Wr(Add_L);
   I2C1_Wr(data_m);
   I2C1_Stop();
   Delay_ml(20);
 }//MemWrt
//***********************************************************
unsigned char MemRd(unsigned int address)
 {
  unsigned char data_m,Add_H,Add_L;
  Add_H=((address&0xff00)>>8);
  Add_L=(address&0x00FF);
  I2C1_Init(100000);
  I2C1_Start();
  I2C1_Wr(0xA0);
  I2C1_Wr(Add_H);
  I2C1_Wr(Add_L);
  I2C1_Repeated_Start();
  I2C1_Wr(0xA1);
  data_m = I2C1_Rd(0u);
  I2C1_Stop();
  return data_m;
 }//MemRd
Example #14
0
/**
  * @brief  Initializes CEC low level.
  * @param  None
  * @retval None
  */
void HDMI_CEC_IO_Init (void) 
{
  GPIO_InitTypeDef  GPIO_InitStruct;

  /* Enable CEC clock */
  __CEC_CLK_ENABLE();
  
  /* Enable CEC LINE GPIO clock */
  HDMI_CEC_LINE_CLK_ENABLE();

  /* Configure CEC LINE GPIO as alternate function open drain */
  GPIO_InitStruct.Pin = HDMI_CEC_LINE_PIN; 
  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStruct.Pull  = GPIO_NOPULL;
  GPIO_InitStruct.Alternate = HDMI_CEC_LINE_AF;
  HAL_GPIO_Init(HDMI_CEC_LINE_GPIO_PORT, &GPIO_InitStruct);    

  /* CEC IRQ Channel configuration */
  HAL_NVIC_SetPriority((IRQn_Type)HDMI_CEC_IRQn, 0xF, 0x0);
  HAL_NVIC_EnableIRQ((IRQn_Type)HDMI_CEC_IRQn); 

  /* Enable CEC HPD SINK GPIO clock */
  HDMI_CEC_HPD_SINK_CLK_ENABLE();
  
  /* Configure CEC HPD SINK GPIO as output push pull */
  GPIO_InitStruct.Pin = HDMI_CEC_HPD_SINK_PIN; 
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Pull  = GPIO_PULLDOWN;
  HAL_GPIO_Init(HDMI_CEC_HPD_SINK_GPIO_PORT, &GPIO_InitStruct); 
  
  I2C1_Init();

  /* Enable CEC HPD SOURCE GPIO clock */
  HDMI_CEC_HPD_SOURCE_CLK_ENABLE();

  /* Configure CEC HPD SOURCE GPIO as output push pull */
  GPIO_InitStruct.Pin = HDMI_CEC_HPD_SOURCE_PIN; 
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Pull  = GPIO_PULLDOWN;
  HAL_GPIO_Init(HDMI_CEC_HPD_SOURCE_GPIO_PORT, &GPIO_InitStruct); 
  
  I2C2_Init();
}
Example #15
0
void initialize()
{
  CMCON = 7; // desable comparator
  ADCON1 = 6 ; // all PORTA pins as digital I/O
  TRISA = 0;                           // all PORTA pins as digital outputs
  TRISB = 0;                          // designate PORTB pins as output
  TRISC = 0b00100111;
  //PORTC.B5 = 1 ;
  I2C1_Init(100000);
 // UART1_Init(115200);
 // Delay_ms(100);                  // Wait for UART module to stabilize
  setup_ds1621();
  get_date_time_temp();
 /* UART1_Write_Text("Start Clock, Calendar and Temperature Program");
  UART1_Write(13);
  UART1_Write(10);
   */
}
Example #16
0
void Main() 
{
  Setup();
  
  I2C_Master_Init();
  
  I2C1_Init(100000);

  while(1){
    I2C1_Start();
    I2C1_Wr(8 << 1);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(100);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Stop();
    
    Delay_ms(500);
    
    I2C1_Start();
    I2C1_Wr(8 << 1);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Wr(0);
    I2C1_Stop();
    
    Delay_ms(500);
  }
}
Example #17
0
void main(){

Lcd_init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);               // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
I2C1_Init(100000);
TRISB.F0=0;
TRISB.F1=0;

while(1){

   Read_Compass();
   WordToStr(angle,to_LCD);
   Lcd_Out(1,1,to_LCD);
   straight();
   // delay_ms(500);
  // Lcd_Out(1,1,"Piyumal");
   //delay_ms(1000);
   
}



}
Example #18
0
uint8_t LIS2DH12TR_init(void){
	int8_t data, res;
	deviceData.handle = I2C1_Init(&deviceData);
	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_ReadReg(0x0f, &data, sizeof(data));	// I2C test line 1
		if (res!=ERR_OK) {
			return;
		} else if(data != 0x33){
			res = 0xff;	// eifach öppis
			return;
		}
	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x20, 0b10001111);
	if(res != ERR_OK){
		return;
	}
	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x23, 0b00100000);
	if(res!=ERR_OK) {
		return;
	}
	WAIT1_WaitCycles(25);
	return res;
}
Example #19
0
/*---------------------------------------------------------------------------------------------------------*/
 I2C_Loopback (void)
{
    uint32_t i;

    /* Init System, IP clock and multi-function I/O */
    SysInit();

    /* Init UART to 115200-8n1 for print message */
    UART_Open(UART0, 115200);

    printf("+-------------------------------------------------------+\n");
    printf("|      Nano1x2 Series I2C Cross Test Sample Code        |\n");
    printf("+-------------------------------------------------------+\n");
    printf("  I/O Configuration:\n");
    printf("  SCK: GPC0 <--> GPC2\n");
    printf("  SDA: GPC1 <--> GPC3\n");
    printf("\n\n");
    printf("..... Press a key to continue ...\n");
    UART_GetChar();


    /* Configure I2C0 as master and I2C1 as slave */
    I2C0_Init();
    I2C1_Init();

    for (i = 0; i < 0x100; i++) {
        g_u8SlvData[i] = 0;
    }

    /* I2C function to Slave receive/transmit data */
    s_I2C1HandlerFn = (I2C_FUNC)I2C_SlaveTRx;

    g_u8DeviceAddr = SLAVE_ADDRESS;

    printf("Test Loop =>");
    for (i = 0; i < 0x100; i++) {
        printf("%d..", i);
        g_au8MasterTxData[0] = (uint8_t)((i & 0xFF00) >> 8);
        g_au8MasterTxData[1] = (uint8_t)(i & 0x00FF);
        g_au8MasterTxData[2] = (uint8_t)(g_au8MasterTxData[1] + 3);

        g_u8MasterDataLen = 0;
        g_u8EndFlag = 0;

        /* I2C function to write data to slave */
        s_I2C0HandlerFn = (I2C_FUNC)I2C_MasterTx;

        /* I2C as master sends START signal */
        I2C_SET_CONTROL_REG(I2C0, I2C_STA);

        /* Wait I2C Tx Finish */
        while (g_u8EndFlag == 0);
        g_u8EndFlag = 0;

        /* I2C function to read data from slave */
        s_I2C0HandlerFn = (I2C_FUNC)I2C_MasterRx;

        g_u8MasterDataLen = 0;
        g_u8DeviceAddr = SLAVE_ADDRESS;

        /* I2C as master sends START signal */
        I2C_SET_CONTROL_REG(I2C0, I2C_STA);

        /* Wait I2C Rx Finish */
        while (g_u8EndFlag == 0);

        /* Compare Tx and Rx data */
        if (g_u8MasterRxData != g_au8MasterTxData[2]) {
            printf("I2C Byte Write/Read Failed, Data 0x%x\n", g_u8MasterRxData);
            return -1;
        }
        printf("[OK]\n");
    }

    printf("\nTest Completely !!\n");
    while(1);
}
Example #20
0
void Peripherals_Init(void)
{
#ifdef NVIC_AUTOINIT
  NVIC_Init();
#endif /* NVIC_AUTOINIT */
#ifdef SIM_AUTOINIT
  SIM_Init();
#endif /* SIM_AUTOINIT */

#ifdef MCM_AUTOINIT
  MCM_Init();
#endif /* MCM_AUTOINIT */
#ifdef PMC_AUTOINIT
  PMC_Init();
#endif /* PMC_AUTOINIT */
#ifdef PORTA_AUTOINIT
  PORTA_Init();
#endif /* PORTA_AUTOINIT */
#ifdef PORTB_AUTOINIT
  PORTB_Init();
#endif /* PORTB_AUTOINIT */
#ifdef PORTC_AUTOINIT
  PORTC_Init();
#endif /* PORTC_AUTOINIT */
#ifdef PORTD_AUTOINIT
  PORTD_Init();
#endif /* PORTD_AUTOINIT */
#ifdef PORTE_AUTOINIT
  PORTE_Init();
#endif /* PORTE_AUTOINIT */

#ifdef ADC0_AUTOINIT
  ADC0_Init();
#endif /* ADC0_AUTOINIT */
#ifdef ADC1_AUTOINIT
  ADC1_Init();
#endif /* ADC1_AUTOINIT */
#ifdef AIPS0_AUTOINIT
  AIPS0_Init();
#endif /* AIPS0_AUTOINIT */
#ifdef AIPS1_AUTOINIT
  AIPS1_Init();
#endif /* AIPS1_AUTOINIT */
#ifdef AXBS_AUTOINIT
  AXBS_Init();
#endif /* AXBS_AUTOINIT */
#ifdef CAN0_AUTOINIT
  CAN0_Init();
#endif /* CAN0_AUTOINIT */
#ifdef CMP0_AUTOINIT
  CMP0_Init();
#endif /* CMP0_AUTOINIT */
#ifdef CMP1_AUTOINIT
  CMP1_Init();
#endif /* CMP1_AUTOINIT */
#ifdef CMP2_AUTOINIT
  CMP2_Init();
#endif /* CMP2_AUTOINIT */
#ifdef CMT_AUTOINIT
  CMT_Init();
#endif /* CMT_AUTOINIT */
#ifdef CRC_AUTOINIT
  CRC_Init();
#endif /* CRC_AUTOINIT */
#ifdef DAC0_AUTOINIT
  DAC0_Init();
#endif /* DAC0_AUTOINIT */
#ifdef DMAMUX_AUTOINIT
  DMAMUX_Init();
#endif /* DMAMUX_AUTOINIT */
#ifdef DMA_AUTOINIT
  DMA_Init();
#endif /* DMA_AUTOINIT */
#ifdef ENET_AUTOINIT
  ENET_Init();
#endif /* ENET_AUTOINIT */
#ifdef EWM_AUTOINIT
  EWM_Init();
#endif /* EWM_AUTOINIT */
#ifdef FB_AUTOINIT
  FB_Init();
#endif /* FB_AUTOINIT */
#ifdef FMC_AUTOINIT
  FMC_Init();
#endif /* FMC_AUTOINIT */
#ifdef FTFE_AUTOINIT
  FTFE_Init();
#endif /* FTFE_AUTOINIT */
#ifdef FTM0_AUTOINIT
  FTM0_Init();
#endif /* FTM0_AUTOINIT */
#ifdef FTM1_AUTOINIT
  FTM1_Init();
#endif /* FTM1_AUTOINIT */
#ifdef FTM2_AUTOINIT
  FTM2_Init();
#endif /* FTM2_AUTOINIT */
#ifdef FTM3_AUTOINIT
  FTM3_Init();
#endif /* FTM3_AUTOINIT */
#ifdef I2C0_AUTOINIT
  I2C0_Init();
#endif /* I2C0_AUTOINIT */
#ifdef I2C1_AUTOINIT
  I2C1_Init();
#endif /* I2C1_AUTOINIT */
#ifdef I2C2_AUTOINIT
  I2C2_Init();
#endif /* I2C2_AUTOINIT */
#ifdef I2S0_AUTOINIT
  I2S0_Init();
#endif /* I2S0_AUTOINIT */
#ifdef LLWU_AUTOINIT
  LLWU_Init();
#endif /* LLWU_AUTOINIT */
#ifdef LPTMR0_AUTOINIT
  LPTMR0_Init();
#endif /* LPTMR0_AUTOINIT */
#ifdef MPU_AUTOINIT
  MPU_Init();
#endif /* MPU_AUTOINIT */
#ifdef PDB0_AUTOINIT
  PDB0_Init();
#endif /* PDB0_AUTOINIT */
#ifdef PIT_AUTOINIT
  PIT_Init();
#endif /* PIT_AUTOINIT */
#ifdef PTA_AUTOINIT
  PTA_Init();
#endif /* PTA_AUTOINIT */
#ifdef PTB_AUTOINIT
  PTB_Init();
#endif /* PTB_AUTOINIT */
#ifdef PTC_AUTOINIT
  PTC_Init();
#endif /* PTC_AUTOINIT */
#ifdef PTD_AUTOINIT
  PTD_Init();
#endif /* PTD_AUTOINIT */
#ifdef PTE_AUTOINIT
  PTE_Init();
#endif /* PTE_AUTOINIT */
#ifdef RCM_AUTOINIT
  RCM_Init();
#endif /* RCM_AUTOINIT */
#ifdef RNG_AUTOINIT
  RNG_Init();
#endif /* RNG_AUTOINIT */
#ifdef RTC_AUTOINIT
  RTC_Init();
#endif /* RTC_AUTOINIT */
#ifdef SDHC_AUTOINIT
  SDHC_Init();
#endif /* SDHC_AUTOINIT */
#ifdef SMC_AUTOINIT
  SMC_Init();
#endif /* SMC_AUTOINIT */
#ifdef SPI0_AUTOINIT
  SPI0_Init();
#endif /* SPI0_AUTOINIT */
#ifdef SPI1_AUTOINIT
  SPI1_Init();
#endif /* SPI1_AUTOINIT */
#ifdef SPI2_AUTOINIT
  SPI2_Init();
#endif /* SPI2_AUTOINIT */
#ifdef SystemControl_AUTOINIT
  SystemControl_Init();
#endif /* SystemControl_AUTOINIT */
#ifdef SysTick_AUTOINIT
  SysTick_Init();
#endif /* SysTick_AUTOINIT */
#ifdef UART0_AUTOINIT
  UART0_Init();
#endif /* UART0_AUTOINIT */
#ifdef UART1_AUTOINIT
  UART1_Init();
#endif /* UART1_AUTOINIT */
#ifdef UART2_AUTOINIT
  UART2_Init();
#endif /* UART2_AUTOINIT */
#ifdef UART3_AUTOINIT
  UART3_Init();
#endif /* UART3_AUTOINIT */
#ifdef UART4_AUTOINIT
  UART4_Init();
#endif /* UART4_AUTOINIT */
#ifdef UART5_AUTOINIT
  UART5_Init();
#endif /* UART5_AUTOINIT */
#ifdef USB0_AUTOINIT
  USB0_Init();
#endif /* USB0_AUTOINIT */
#ifdef USBDCD_AUTOINIT
  USBDCD_Init();
#endif /* USBDCD_AUTOINIT */
#ifdef VREF_AUTOINIT
  VREF_Init();
#endif /* VREF_AUTOINIT */
#ifdef WDOG_AUTOINIT
  WDOG_Init();
#endif /* WDOG_AUTOINIT */
}
Example #21
0
int main()
{
    char carac;
    
    TRISD = 0;
    TRISE = 0;
    TRISA = 0;
    TRISB = 0b00000111;
    TRISC = 0b00000001;

    I2C1_Init(100000);
    Delay_ms(100);
    UART1_Init(19200);
    Delay_ms(100);

    escreve(0,11);

    init_timer();//começa a escutar as teclas

    adcon1 = 0x0F;

    preenche_mapa_digitos();
    limpa_display();
        
    Sound_Init(&PORTC, 2);//PORTC.F2

    limpa_display();
    popula_displays_palavra("CLIC");
    carac = le_carac();
    while(carac == 255)
    {
       semente++;
       carac = le_carac();
    }
    limpa_display();

    if (carac == '1')
    {
       escreve(127, 0);
       pontuacao_record = 0;
       popula_displays_palavra("NO");
       Delay_ms(1000);
       popula_displays_palavra("RECO");
       Delay_ms(1500);
    }
    else
    {
       pontuacao_record = le(127);
       popula_displays_palavra("RECO");
       Delay_ms(1000);
       limpa_display();
       Delay_ms(500);
       popula_displays_num(pontuacao_record);
       Delay_ms(1500);
    }
    
    srand(semente);
    limpa_display();
    Delay_ms(500);
    popula_displays_palavra("PLAY");
    Delay_ms(1500);
       
    while(!errou)
    {
       sequencia_num[nivel_atual] = rand() & 0b00000011;
       imprime_sequencia_num();
       errou = !le_sequencia_jogador();

       if (errou)
       {
         limpa_display();
         popula_displays_palavra("FAIL");
         toca_som(300, 450);
         toca_som(600, 450);
         Delay_ms(2000);
         
         popula_displays_palavra("SCOR");
         Delay_ms(1500);
         popula_displays_num(nivel_atual);
         Delay_ms(1500);
         limpa_display();
         
         if (nivel_atual > pontuacao_record)
         {
          escreve(127, nivel_atual);//novo record
          popula_displays_palavra("UHUL");
          Delay_ms(1000);
          popula_displays_palavra("NOVO");
          Delay_ms(1000);
          popula_displays_palavra("RECO");
          Delay_ms(1000);
          limpa_display();
         }
       }
       else
       {
         nivel_atual++;
         limpa_display();
         popula_displays_palavra("GOOD");
         Delay_ms(1000);
       }
    }
}
Example #22
0
File: main.c Project: jdaheron/GHB
/*------------------------------------------------------------------------------------------------*/
int main(void)
{
	Bool_e NouveauMode;
	Horodatage_s Time = {
			.Heure = 0,
			.Minute = 0,
			.Seconde = 0,
	};


	// ------------------------------------------------------------------------
	// --- INIT DU SYSTEME
	// --- Initialisations uC, Peripheriques, Fonctions et Interfaces
	BSP_Init();									// Init carte
	SysTick_Config(SystemCoreClock / 1000);		// Init Tick 1ms
	HAL_Console_Init(115200);
	RTC_StartInit(TRUE);						// Start Init RTC
	I2C1_Init(100 * 1000);						// 100kHz
	ADC1_Init();

	_CONSOLE(0, "\n");
	_CONSOLE(LogId, "--- START - ALJ%s ---\n", VERSION_SW);

	//AM23xx_Test();

	REGLAGE_RTC();

	//----------------------------------
	// FONCTIONNALITES
	MemoireFAT_Init((Diskio_drvTypeDef*) &SdCard_SPI_Driver);
	#if USE_TEMP_HYGRO
		TempHygro_Init(TEMPERATURE_PERIODE_ACQUISITION_ms);
	#endif
	Delay_ms(50);

//	Hygrometre_Init();
	ConfIni_Init();
	Arrosage_Init(USE_CONF_INI_FILE);
	Chauffage_Init(USE_CONF_INI_FILE);
	Ventilation_Init(USE_CONF_INI_FILE);
	Logs_Init();

	PC_Init();
	Terminal_Init();
	Terminal_Cmd_Init();

	//_CONSOLE(LogId, "MODE_FCT_SERVEUR\n");
	ModeFct = MODE_FCT_SERVEUR;
	//MemoireFAT_PrintFileList("httpserver");
	Ethernet_Init(USE_CONF_INI_FILE);

	if (RTC_BkpRegister_Read(0) != 0)
	{
		_CONSOLE(LogId, "MODE_FCT_USB\n");
		ModeFct = MODE_FCT_USB;
		//USB_Init((Diskio_drvTypeDef*) &SdCard_SPI_Driver);
		RTC_BkpRegister_Write(0, 0);
	}

	// Lancement des timers
	TSW_Start(&TmrAffichTempHygro, 3000);


	//Mode_Test();

	WDG_InitWWDG(10000);

	while (RTC_Main() != RTC_ETAPE_READY);
	TSW_Start(&Tmr_RTC, 10000);
	RTC_Lire(&StartTime);
	RTC_Lire(&Time);


	//--------------------------------------------------------------------------------
	_CONSOLE(LogId, "--------------------------\n");
	_CONSOLE(LogId, "StartupTime=%dms\n", TSW_GetTimestamp_ms());
	_CONSOLE(LogId, "--------------------------\n\n");
		while(1)
	{
		WDG_Refresh();

//		if (PC_Read((uint8_t*) BufferIn, NULL) == TRUE)
//		{
//			Terminal_Parser(BufferIn, BufferOut, 1024);
//			if (strlen(BufferOut) > 0)
//				PC_Write(BufferOut, strlen(BufferOut));
//		}

		// Choix du mode de fonctionnement
		// WKUP = ACTIF -> USB  -  WKUP = INACTIF -> WebServer
		//if (GPIO_Get(PORT_WKUP) == Etat_ACTIF)
		//{
		//	RTC_BkpRegister_Write(0, 1);
		//	while (GPIO_Get(PORT_WKUP) == Etat_ACTIF)
		//		TSW_Delay(100);
		//	GOTO(0);
		//}

		//----------------------------------
		// PROCESSUS
		LifeBit_Main();
		MemoireFAT_Main();
		#if USE_TEMP_HYGRO
			TempHygro_Thread();
		#endif

		if (Mode != MODE_DEMARRAGE)
		{
			Arrosage_Management();
			Chauffage_Management();
			Ventilation_Management();
			Hygrometrie_Management();
		}

		if (ModeFct == MODE_FCT_SERVEUR)
		{
			Ethernet_Management();
		}

		Logs_Management();


		//----------------------------------
		// LECTURE TEMPERATURE
		if ((TempHygro_IsValide() == FALSE)
		&&	(Mode != MODE_DEMARRAGE))
		{
			Mode = MODE_DEFAUT;
		}
		else
		{
			Temperature = TempHygro_GetTemperature();
			Hygrometrie = TempHygro_GetHygrometrie();
		}

		//----------------------------------
		// RTC
		if (TSW_IsFinished(&Tmr_RTC))
		{
			RTC_Lire(&Time);
			TSW_ReStart(&Tmr_RTC);

			//_CONSOLE(LogId, "RTC = %d-%02d-%02d %02d:%02d:%02d;%08d;",
			//				Time.Annee, Time.Mois, Time.Jour,
			//				Time.Heure, Time.Minute, Time.Seconde,
			//				TSW_GetTimestamp_ms());
		}


		//----------------------------------
		// AFFICHAGE TEMPERATURE
/*		if (TSW_IsRunning(&TmrAffichTempHygro) == FALSE)
		{
			_CONSOLE(LogId, "TempHygro = ");
			if (TempHygro_IsValide() == FALSE)
				_CONSOLE(LogId, "Non valide\n");
			else
			{
				_CONSOLE(LogId, "%.01f %c\t%.01f %c\n",
						Temperature, '°',
						Hygrometrie, '%');
			}

			TSW_Start(&TmrAffichTempHygro, 2500);
		}
*/


		//----------------------------------
		// GESTION DES MODES
		NouveauMode = FALSE;
		if (LastMode != Mode)
		{
			LastMode = Mode;
			NouveauMode = TRUE;
		}

		switch (Mode)
		{
			//--------------------------------------------------------------
			case MODE_DEMARRAGE :

				if (NouveauMode)
				{
					_CONSOLE(LogId, "----- MODE_DEMARRAGE -----\n");
					Logs_Data();
				}

				if (Mode_Demarrage() == Status_Fini)
				{
					Mode = MODE_SURVEILLANCE;
				}

				break;


			//--------------------------------------------------------------
			case MODE_SURVEILLANCE :

				if (NouveauMode)
				{
					_CONSOLE(LogId, "----- MODE_SURVEILLANCE -----\n");
					Logs_Data();

					GPIO_Set(PORT_IHM_LED1, Etat_ACTIF);
					GPIO_Set(PORT_IHM_LED2, Etat_INACTIF);
					GPIO_Set(PORT_IHM_LED3, Etat_INACTIF);

					EtatVentillation	= Etat_INACTIF;
					EtatChauffage		= Etat_INACTIF;

					TSW_Start(&Tmr_ATTENTE, 1000 * 30); // On reste au moins 30sec en mode attente
				}

				if (TSW_IsRunning(&Tmr_ATTENTE) == TRUE)
				{
					break;
				}

				// Pas de chauffage dessuite après l'extraction
				if ((TSW_IsRunning(&Tmr_EXT) == FALSE)
				&&	(Temperature < Chauffage_Get()->Cfg_SeuilStart_DegC))
				{
					Mode = MODE_CHAUFFAGE;
				}

				// Pas d'extraction dessuite après le chauffage
				if ((TSW_IsRunning(&Tmr_CH) == FALSE)
				&&	(Temperature >= Ventilation_Get()->Cfg_SeuilStart_DegC))
				{
					Mode = MODE_VENTILLATION;
				}

				break;


			//--------------------------------------------------------------
			case MODE_CHAUFFAGE :

				if (NouveauMode)
				{
					_CONSOLE(LogId, "----- MODE_CHAUFFAGE -----\n");
					Logs_Data();

					GPIO_Set(PORT_IHM_LED1, Etat_INACTIF);
					GPIO_Set(PORT_IHM_LED2, Etat_ACTIF);
					GPIO_Set(PORT_IHM_LED3, Etat_INACTIF);

					if (Ventilation_Get()->Cfg_ActiverPendantChauffage)
						EtatVentillation = Etat_ACTIF;
					else
						EtatVentillation = Etat_INACTIF;
					EtatChauffage = Etat_ACTIF;
				}

				// Attente franchissement seuil
			if (Temperature >= Chauffage_Get()->Cfg_SeuilStop_DegC)
				{
					EtatChauffage = Etat_INACTIF;

					TSW_Start(&Tmr_CH, 1000 * Chauffage_Get()->Cfg_TempoApresCh_s);
					Mode = MODE_SURVEILLANCE;
				}

				break;

			//--------------------------------------------------------------
			case MODE_VENTILLATION :

				if (NouveauMode)
				{
					_CONSOLE(LogId, "----- MODE_VENTILLATION -----\n");
					Logs_Data();

					GPIO_Set(PORT_IHM_LED1, Etat_ACTIF);
					GPIO_Set(PORT_IHM_LED2, Etat_ACTIF);
					GPIO_Set(PORT_IHM_LED3, Etat_INACTIF);

					EtatChauffage = Etat_INACTIF;
					EtatVentillation = Etat_ACTIF;
				}

				if (Temperature < Ventilation_Get()->Cfg_SeuilStop_DegC)
				{
					EtatVentillation = Etat_INACTIF;

					TSW_Start(&Tmr_EXT, 1000 * Ventilation_Get()->Cfg_TempoApresEXT_s);
					Mode = MODE_SURVEILLANCE;
				}

				break;

			//--------------------------------------------------------------
			case MODE_DEFAUT :

				if (NouveauMode)
				{
					_CONSOLE(LogId, "----- MODE_DEFAUT -----\n");
					Logs_Data();

					GPIO_Set(PORT_IHM_LED1, Etat_INACTIF);
					GPIO_Set(PORT_IHM_LED2, Etat_INACTIF);
					GPIO_Set(PORT_IHM_LED3, Etat_ACTIF);

					EtatVentillation 	= Etat_INACTIF;
					EtatChauffage		= Etat_INACTIF;
					//Arrosage_Stop();

					TSW_Start(&Tmr_DEFAULT, 60 * 1000);
					TSW_Start(&Tmr_DEFAULT_Max, 600 * 1000);
				}

				if (TempHygro_IsValide() == TRUE)
				{
					Mode = MODE_VENTILLATION;
					break;
				}

				if ((TSW_IsRunning(&Tmr_DEFAULT) == FALSE)
				&&	(REBOOT_ON_DEFAULT_MODE == TRUE)
				&&	(Arrosage_IsActive() == FALSE))
				{
					if ((Telnet_GetNbActiveConnection() == 0)
					||	(TSW_IsRunning(&Tmr_DEFAULT_Max) == FALSE))
					{
						_CONSOLE(LogId, "REBOOT...\n");
						MemoireFAT_DeInit();
						TSW_Delay(5000);
						GOTO(0);
						Mode = MODE_DEMARRAGE;
					}
				}
				break;

		}

		//----------------------------------
		// MAJ DES SORTIES
		if (GPIO_Get(PORT_RELAIS_V_EXT) != EtatVentillation)
		{
			_CONSOLE(LogId, "Ventillation = %d\n", EtatVentillation);
			GPIO_Set(PORT_RELAIS_V_EXT, EtatVentillation);
			Logs_Data();
		}
		if (GPIO_Get(PORT_RELAIS_CH) != EtatChauffage)
		{
			_CONSOLE(LogId, "Chauffage = %d\n", EtatChauffage);
			GPIO_Set(PORT_RELAIS_CH, EtatChauffage);
			Logs_Data();
		}
	}

	return 0;

}


/*------------------------------------------------------------------------------------------------*/
extern void SdCard_SPI_timerproc (void);

void ApplicationTickHook (void) {

	static uint8_t ucTick_10ms=0;
	static uint8_t ucTick_100ms=0;


	/* Gestion du Tick Timer Software */
	TSW_Refresh();

	/* Tick 10ms */
	ucTick_10ms++;
	if (ucTick_10ms >= 10){
		ucTick_10ms = 0;
		ADC1_Tick();
		SdCard_SPI_timerproc();
	}

	/* Tick 100ms */
	ucTick_100ms++;
	if (ucTick_100ms >= 10){
		ucTick_100ms = 0;

	}
}


/*------------------------------------------------------------------------------------------------*/
void Delay(uint32_t nCount)
{
  /* Capture the current local time */
  uint32_t timingdelay = TSW_GetTimestamp_ms() + nCount;

  /* wait until the desired delay finish */
  while(timingdelay > TSW_GetTimestamp_ms())
  {
  }
}
Example #23
0
File: main.c Project: ADTL/ARMWork
int main(void) {
	uint16_t bits;
	uint32_t intval = 40;
	uint32_t tnow;
	char tmp[92];
	RCC_ClocksTypeDef RCC_Clocks;
	uint16_t i;
	
	TIM2_timer_start();

	usart_begin(&USerial3, USART3, PC11, PC10, 19200);

	usart_print(&USerial3, 
			"Happy are those who know they are spiritually poor; \n"
			"The kingdom of heaven belongs to them!\n");
	usart_flush(&USerial3);
	
	RCC_GetClocksFreq(&RCC_Clocks);

	sprintf(tmp, "SYSCLK = %ul\n", RCC_Clocks.SYSCLK_Frequency);
	usart_print(&USerial3, tmp);
	sprintf(tmp, "PCLK1 = %ul\n", RCC_Clocks.PCLK1_Frequency);
	usart_flush(&USerial3);

	GPIOMode(PinPort(PD12),
			(PinBit(PD12) | PinBit(PD13) | PinBit(PD14) | PinBit(PD15)), OUTPUT,
			FASTSPEED, PUSHPULL, NOPULL);
			/*
	spi_begin(SPI2, PB13, PB14, PB15, PB12);
	digitalWrite(PB12, HIGH);
*/
	I2C1_Init();
/*
	i2c_begin(&Wire1, PB9, PB8, 100000);
	lcd.init(&Wire1);
	lcd.begin();
	lcd.setContrast(46);
	lcd.print("Yappee!");       // Classic Hello World!
*/
	bits = GPIO_ReadOutputData(GPIOD );
	GPIOWrite(GPIOD, PinBit(PD13) | (bits & 0x0fff));
	delay_ms(intval);
	tnow = millis() / 1000;
	while (tnow == millis() / 1000)
		;
	tnow = millis() / 1000;

	while (1) {
		bits = GPIO_ReadOutputData(GPIOD );

		GPIOWrite(GPIOD, PinBit(PD13) | (bits & 0x0fff));
		delay_ms(intval);
		GPIOWrite(GPIOD, PinBit(PD14) | (bits & 0x0fff));
		delay_ms(intval);
		GPIOWrite(GPIOD, PinBit(PD15) | (bits & 0x0fff));
		delay_ms(intval);
		GPIOWrite(GPIOD, PinBit(PD12) | (bits & 0x0fff));
		delay_ms(intval);
		//
		bits &= 0x0fff;
		switch ((tnow % 60) / 15) {
		case 3:
			bits |= PinBit(PD12);
		case 2:
			bits |= PinBit(PD15);
		case 1:
			bits |= PinBit(PD14);
		case 0:
		default:
			bits |= PinBit(PD13);
			break;
		}
		GPIOWrite(GPIOD, bits);

		while (tnow == millis() / 1000);
		tnow = millis() / 1000;

		//Serial3.print(tmp);
		sprintf(tmp, "%04ld\n", millis());
		usart_print(&USerial3, tmp);

		/*
		digitalWrite(PB12, LOW);
		spi_transfer(SPI2, (uint8_t *) tmp, 8);
		digitalWrite(PB12, HIGH);
*/
		i = 0;
		if (usart_available(&USerial3) > 0) {
			while (usart_available(&USerial3) > 0 && i < 92) {
				tmp[i++] = (char) usart_read(&USerial3);
			}
			tmp[i] = 0;
			usart_print(&USerial3, "> ");
			usart_print(&USerial3, tmp);
			usart_print(&USerial3, "\n");
		}

	}
	return 0;
}
Example #24
0
/**
  * @brief  Initializes peripherals used by the I2C EEPROM driver.
  * @param  None
  * @retval None
  */
void EEPROM_IO_Init(void)
{
  I2C1_Init();
}
Example #25
0
/**
  * @brief  Initializes peripherals used by the I2C Temperature Sensor driver.
  * @param  None
  * @retval None
  */
void TSENSOR_IO_Init(void)
{
  I2C1_Init();
}
Example #26
0
/**
  * @brief  Initializes IOE low level.
  * @param  None
  * @retval None
  */
void MFX_IO_Init(void)
{
  I2C1_Init();
}
Example #27
0
void InitDriverI2C() {
    I2C1_Init(800000);
}
Example #28
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main (void)
{
    uint32_t i;

    /* Init System, IP clock and multi-function I/O */
    SYS_Init();     

    /* Init UART0 for printf */
    UART0_Init();

    /* Init I2C1 to access EEPROM */ 
    I2C1_Init();
    /*
        This sample code sets I2C bus clock to 100kHz. Then, accesses EEPROM 24LC64 with Byte Write 
        and Byte Read operations, and check if the read data is equal to the programmed data.
    */
   
    printf("+-------------------------------------------------------+\n");
    printf("|    NUC200 I2C Driver Sample Code with EEPROM 24LC64   |\n");
    printf("+-------------------------------------------------------+\n");
        
    g_u8DeviceAddr = 0x50;
        
    for (i = 0; i < 0x100; i++)
    {
        g_au8TxData[0] = (uint8_t)((i & 0xFF00) >> 8);
        g_au8TxData[1] = (uint8_t)(i & 0x00FF);
        g_au8TxData[2] = (uint8_t)(g_au8TxData[1] + 3);
        
        g_u8DataLen = 0;
        g_u8EndFlag = 0;
        
        /* I2C function to write data to slave */
        s_I2C1HandlerFn = (I2C_FUNC)I2C_MasterTx;
        
        /* I2C as master sends START signal */
        _I2C_SET_CONTROL_BITS(I2C1, I2C_I2CON_STA);

        /* Wait I2C Tx Finish */
        while (g_u8EndFlag == 0);
        g_u8EndFlag = 0;

        /* I2C function to read data from slave */
        s_I2C1HandlerFn = (I2C_FUNC)I2C_MasterRx;

        g_u8DataLen = 0;
        g_u8DeviceAddr = 0x50;

        _I2C_SET_CONTROL_BITS(I2C1, I2C_I2CON_STA);
        
        /* Wait I2C Rx Finish */
        while (g_u8EndFlag == 0);

        /* Compare data */
        if (g_u8RxData != g_au8TxData[2])
        {
            printf("I2C Byte Write/Read Failed, Data 0x%x\n", g_u8RxData);
            return -1;
        }           
    }
    printf("I2C1 Access EEPROM Test OK\n");

    s_I2C1HandlerFn = NULL;
    
    /* Close I2C1 */
    I2C1_Close();

	while(1);
}
Example #29
0
 void main(void)
{

  ENTR_CRT_SECTION();
  /* Setup STM32 system (clock, PLL and Flash configuration) */
  SystemInit();

  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
  


  // I2C1 init
  I2C1_Init();

  EXT_CRT_SECTION();

  // GLCD init
  GLCD_PowerUpInit(0x0); //(
  GLCD_Backlight(BACKLIGHT_ON);
  GLCD_SetFont(&Terminal_9_12_6,0x000F00,0x00FF0);
  GLCD_SetWindow(10,10,131,131);

  // Init Accl sensor
  if(FALSE == Accl_Init())
  {
    // Initialization fault
    GLCD_TextSetPos(0,0);
    GLCD_print("\fLIS3LV020 Init.\r\nfault\r\n");
    while(1);
  }
    //Init CarControl and Delay
  Car_Init();
  DWT_Init();
  HCSR04_Init();
    // SysTick end of count event each 0.5s with input clock equal to 9MHz (HCLK/8, default)
  SysTick_Config(150000);
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);

  DWT_Delayms(1000);
  while(1)
  {

    //while(1){GLCD_print("Current state: %d \r",GPIO_ReadInputDataBit(JS_LEFT_PORT, JS_LEFT_MASK));} 
    //car_feedback=accl_feedback();
 /*   A = accX[1];
    B = velX[1];
    C = posX[1]; */
if(SysTickF1)
{
        SysTickF1 = FALSE;
        //GLCD_TextSetPos(0,0);
            GLCD_print("%d, %d \r", get_Xvel(), accl_feedback());
            DWT_Delayms(500);
            
}
    if(NewInstr) //
    {
      DWT_Delayms(1000);
      NewInstr = FALSE;
    
    //GoCar(Test, TestTurn);
    // 1. Give command (desired state)
    //desiredState;

    // 2. Run machine learning to test action
    action = goToState(car_instr);
    GoCars(action);
    //  testExp();
    int runTime = 0;
    while (runTime < 1){
        DWT_Delayms(700);
        runTime++;
    }
            GLCD_TextSetPos(0,0);
            GLCD_print("\f%d,%d;%d,%d\r\n", get_X_accFeedback(0), get_Y_accFeedback(0), get_X_vel(0), get_Y_vel(0));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(1), get_Y_accFeedback(1), get_X_vel(1), get_Y_vel(1));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(2), get_Y_accFeedback(2), get_X_vel(2), get_Y_vel(2));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(3), get_Y_accFeedback(3), get_X_vel(3), get_Y_vel(3));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(4), get_Y_accFeedback(4), get_X_vel(4), get_Y_vel(4));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(5), get_Y_accFeedback(5), get_X_vel(5), get_Y_vel(5));
            GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(6), get_Y_accFeedback(6), get_X_vel(6), get_Y_vel(6));
      //      GLCD_print("%d,%d;%d,%d\r\n", get_X_accFeedback(7), get_Y_accFeedback(7), get_X_vel(7), get_Y_vel(7));
                car_instr=car_stop;
    GoCars(car_instr);
            DWT_Delayms(2000);
    }
    //GoCars(3); //Stopping the car
    
    
    // 3. Wait x ms
    //Wait in ML-method testAllActions
    
    // 4. Return value from accelerometer
    //Return value from accelerometer in ML-method testAllActions
    
    // 5. Evaluate action compared to state
    //Already implemented in ML-file. No need to alter (probably)
    
    // 6. Repeat 3-5 until all actions has been tested
    //Already implemented in ML-file. No need to alter (probably)
    
    // 7. Choose the correct state
    //Already implemented in ML-file. No need to alter (probably)
  }
}
Example #30
0
void main()
{
    Time *time;
    ADCON0 = 0;
    ADCON1 = 0x06;              // All ports are digital

    I2C1_Init(100000);          // initialize I2C

    PORTB = 0xFF;
    TRISB = 0;

    // Comment following line for debugging
    OPTION_REG = 0x40;        // Assign prescaler to TMR0 (1/2)
    TMR0  = 12;              // Timer0 initial value
    INTCON = 0xA0;           // Enable TMRO interrupt

    ALARM_COLD_TRIS = 0;

    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);
    Lcd_Out(1, 1, "Started!");
    PORTC = 0;

    turnOffFeeder();
    loadFeederData();
    getCustomAlarm(&minTemp, &maxTemp);
    displayEdited(2, 1);

    while(1)
    {
        TRISC = TRISC|BUTTONS_MASK;
        state = PORTC & BUTTONS_MASK;

        if(state != lastState)
        {
          lastState = state;
          if(state & (1<<BUTTON_PREVIOUS))
          {
            if(mode == MODE_EDIT_FEED1_HH || mode == MODE_EDIT_FEED1_MN)
                previousEditFeed1(mode, 0, 2, 1);
            else if(mode == MODE_EDIT_FEED2_HH || mode == MODE_EDIT_FEED2_MN)
                previousEditFeed1(mode, 1, 2, 1);
            else if(mode == MODE_EDIT_MIN || mode == MODE_EDIT_MAX)
                previousEdited(2, 1);
            else
            {
                if(--mode < 0)
                    mode = MODE_COUNT -1;
                displayMode(2, 1);
            }
          }
          else if(state & (1<<BUTTON_NEXT))
          {
            if(mode == MODE_EDIT_FEED1_HH || mode == MODE_EDIT_FEED1_MN)
                nextEditFeed1(mode, 0, 2, 1);
            else if(mode == MODE_EDIT_FEED2_HH || mode == MODE_EDIT_FEED2_MN)
                nextEditFeed1(mode, 1, 2, 1);
            else if(mode == MODE_EDIT_MIN || mode == MODE_EDIT_MAX)
                nextEdited(2, 1);
            else
            {
                if(++mode >= MODE_COUNT)
                    mode = 0;
                displayMode(2, 1);
            }
          }

          if(state & (1<<BUTTON_OK))
            handleOKButton(state);
        }

        if (timerCounter >= 20000)
            handleCounterEvent();
    }
}