예제 #1
0
파일: mag.c 프로젝트: KyleAshley/quadcopter
void m_setup(float gauss)
{
  unsigned int regValue = 0x00;
	I2C_Write_Byte(m_ID, m_CONFIG1, 0x70);

  if(gauss == 0.88)
  {
      regValue = 0x00;
      m_scale = 0.73;
  }
  else if(gauss == 1.3)
  {
      regValue = 0x20;
      m_scale = 0.92;
  }
  else if(gauss == 1.9)
  {
      regValue = 0x40;
      m_scale = 1.22;
  }
  else if(gauss == 2.5)
  {
      regValue = 0x60;
      m_scale = 1.52;
  }
  else if(gauss == 4.0)
  {
      regValue = 0x80;
      m_scale = 2.27;
  }
  else if(gauss == 4.7)
  {
      regValue = 0xA0;
      m_scale = 2.56;
  }
  else if(gauss == 5.6)
  {
      regValue = 0xC0;
      m_scale = 3.03;
  }
  else if(gauss == 8.1)
  {
      regValue = 0xE0;
      m_scale = 4.35;
  }
  else
  {
    regValue = 0xA0;
    m_scale = 2.56;
  }

   // Setting is in the top 3 bits of the register.
  I2C_Write_Byte(m_ID, m_CONFIG2, regValue);

  // Set Continuous mode
  I2C_Write_Byte(m_ID, m_MODE, M_CONTINUOUS);

	delay_LCD_DATA(600);
}
예제 #2
0
void I2C_Write(uint8_t Slave_Addr, uint8_t REG_Address,uint8_t REG_data)
{
    I2C_Start();
    I2C_Write_Byte(Slave_Addr);
    I2C_Write_Byte(REG_Address);
    I2C_Write_Byte(REG_data);
    I2C_Stop();
}
예제 #3
0
void write_RTC_I2c()
{
    I2C_Idle();
    I2C_Start(); // Inicializa a comunicação I2c
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_Write_Byte(0xD0); // End. fixo para DS1307: 1101000X, onde x = 0 é para gravação.
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_Write_Byte(0x00); // End. onde começa a programação do relógio, end. dos segundos.
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
     
    //I2C_Write_Byte(0x00); // Inicializa com 00 segundos.
    I2C_Write_Byte(0x00);
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    //I2C_Write_Byte(0x08); // Inicializa com 8 minutos.
    I2C_Write_Byte(0x30);
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    //I2C_Write_Byte(0x08); // Inicializa com 08:00hs (formato 24 horas).
    I2C_Write_Byte(0x14); //19 horas
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    //I2C_Write_Byte(0x04); // Inicializa com terça
    I2C_Write_Byte(0x04);
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    //I2C_Write_Byte(0x17); // Inicializa com dia 17
    I2C_Write_Byte(0x22);// dia 20 do mês
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    //I2C_Write_Byte(0x04); // Inicializa com mês 04
    I2C_Write_Byte(0x01); //mês 1, janeiro
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    //I2C_Write_Byte(0x13); // Inicializa com ano 13
    I2C_Write_Byte(0x16); //ano 16
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_Stop(); // Finaliza a comunicação I2c
}
예제 #4
0
void BH1750_init() 
{ 
    delay_us(100000);  
   	I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x46);
    I2C_Get_Ack(I2C1);
	  
		I2C_Write_Byte(I2C1,POWER_DOWN);
    I2C_Get_Ack(I2C1);
		I2C_Stop(I2C1);
} 
예제 #5
0
uint8_t I2C_Read(uint8_t Slave_Addr, uint8_t REG_Address)
{
    uint8_t REG_data;
    I2C_Start();
    I2C_Write_Byte(Slave_Addr);
    I2C_Write_Byte(REG_Address);
    I2C_Start();
    I2C_Write_Byte(Slave_Addr+1);
    REG_data=I2C_Read_Byte();
    Sendack(1);
    I2C_Stop();
    return REG_data;
}
예제 #6
0
// initializes the gyro modules
void setupGyro(int scale)
{
  // enable x, y, z, power-on
  I2C_Write_Byte(g_ID, g_CTRL_REG1, 0x0F);
  
  // HPF stuff
  I2C_Write_Byte(g_ID, g_CTRL_REG2, 0x00);
  
  // data read interrupt on INT 2
  I2C_Write_Byte(g_ID, g_CTRL_REG3, 0x08);  //08
  
  // full-scale range control
  if(scale == 250)
  {
    I2C_Write_Byte(g_ID, g_CTRL_REG4, 0x00);
  }
  else if(scale == 500)
  {
    I2C_Write_Byte(g_ID, g_CTRL_REG4, 0x10);  
  }
  else
  {
    I2C_Write_Byte(g_ID, g_CTRL_REG4, 0x30);
  }
  
  // HPF output stuff
  I2C_Write_Byte(g_ID, g_CTRL_REG5, 0x00);
}
예제 #7
0
void read_RTC_I2c(unsigned char pos_memoria)
{
    I2C_Idle();
    I2C_Start();
    I2C_Idle();
    I2C_Write_Byte(0xD0); //address of DS1307.
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_Write_Byte(pos_memoria); // Position the address pointer to 0.
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_ReStart();
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_Write_Byte(0xD1); // Direction bit set to read.
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    leitura = I2C_Read_Byte();
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_Send_NACK();
    I2C_Stop();
}
예제 #8
0
void Multiple_Read_HMC5883(HMC5883_DATA *dat)
{
    uint8_t f;
    I2C_Start();
    I2C_Write_Byte(HMC5883_SLAVE_ADDR);
    I2C_Write_Byte(0x03);
    I2C_Start();
    I2C_Write_Byte(HMC5883_SLAVE_ADDR+1);
    for (f=0; f<6; f++)
    {
        ((uint8_t *)dat)[f] = I2C_Read_Byte();
        if (f == 5)
        {
            Sendack(1);
        }
        else
        {
            Sendack(0);
        }
    }
    I2C_Stop();
}
예제 #9
0
파일: menu.c 프로젝트: nowhard/IRDA
uint8_t menuKey(msg_par par) {
	switch (par) 
	{
		case 0: 
		{
			return 1;
		}
		//------------------------
		case KEY_LEFT: 
		{
			switch(SELECT)//пункт меню
			{			
				case MENU_TUNE_TIME://определяем поведение кнопок в этом меню
				{
					time_tune_state=0;
				}
				break;

				case MENU_TUNE_DATE:
				{
					date_tune_state=0;
				}
				break;
				
				default:
				{
					menuChange(PREVIOUS);
				}
				break;				
			}
		}
		break;

		//------------------------
		case KEY_RIGHT: 
		{
			switch(SELECT)//пункт меню
			{			
				case MENU_TUNE_TIME:
				{
					time_tune_state=1;
				}
				break;

				case MENU_TUNE_DATE:
				{
					date_tune_state=1;
				}
				break;
				
				default:
				{
					menuChange(NEXT);
				}
				break;				
			}

		}
		break;
		//------------------------
		case KEY_UP:
		{ 
			switch(SELECT)//пункт меню
			{			
				case MENU_TUNE_BRIGHTNESS:
				{	
					if(brightness>=0xF)
					{
						brightness=0xF;	
					}
					else
					{
						brightness=(brightness+1)&0xF;	
						I2C_Write_Byte(SLA_ADDR,0x0,brightness);
					}
				}
				break;

				case MENU_TUNE_TIME:
				{
					if(time_tune_state)
					{
						if(clk.hour<23)
						{
							clk.hour++;
						}
						else
						{
							clk.hour=23;	
						}
					}
					else
					{
						if(clk.minute<59)
						{
							clk.minute++;
						}
						else
						{
							clk.minute=59;
						}
					}
				}
				break;

				case MENU_TUNE_DATE:
				{
					if(date_tune_state)
					{
						if(clk.month<12)
						{
							clk.month++;
						}
					}
					else
					{
						if(clk.day<31)
						{
							clk.day++;
						}
					}
				}
				break;

				case MENU_TUNE_YEAR:
				{
					if(clk.year>=99)
					{
						clk.year=99;
					}
					else
					{
						clk.year++;	
					}
				}
				break;
				
				default:
				{
					//menuChange(NEXT);
				}
				break;				
			}			
		}
		break;
		//------------------------
		case KEY_DOWN:
		{
			switch(SELECT)//пункт меню
			{			
				case MENU_TUNE_BRIGHTNESS:
				{

					if(brightness<=0x1)
					{
						brightness=0x1;	
					}
					else
					{
						brightness=(brightness-1)&0xF;	
						I2C_Write_Byte(SLA_ADDR,0x0,brightness);					
					}
				}
				break;

				case MENU_TUNE_TIME:
				{
					if(time_tune_state)
					{
						if(clk.hour>0)
						{
							clk.hour--;
						}
					}
					else
					{
						if(clk.minute>0)
						{
							clk.minute--;
						}
					}				
				}
				break;

				case MENU_TUNE_DATE:
				{
					if(date_tune_state)
					{
						if(clk.month>1)
						{
							clk.month--;
						}
					}
					else
					{
						if(clk.day>1)
						{
							clk.day--;
						}
					}
				}
				break;

				case MENU_TUNE_YEAR:
				{	
					if(clk.year<=0)
					{
						clk.year=0;
					}
					else
					{
						clk.year--;	
					}
				}
				break;
				
				default:
				{
					
				}
				break;				
			}
		}
		break;
			
		//------------------------
		case KEY_OK:
		{ // выбор пункта
			switch(SELECT)//пункт меню
			{			
				case MENU_TUNE_TIME:
				{
					StoreTime(&clk,0);
					menuChange(PARENT);
				}
				break;

				case MENU_TUNE_DATE:
				{
					StoreTime(&clk,1);
					menuChange(PARENT);
				}
				break;

				case MENU_TUNE_YEAR:
				{	
					StoreTime(&clk,2);
					menuChange(PARENT);
				}
				break;
				
				default:
				{
					menuChange(CHILD);	
				}
				break;				
			}		
		}
		break;
		//------------------------
		case KEY_GND:// отмена выбора (возврат)
		{
			menuChange(PARENT);
		}
		break;
		//------------------------
		default:
		{
		}
		break;
	}
	//dispMenu(0);
	return (1);
}
예제 #10
0
uint16_t read_bh1750()
{
	
		_DATA=0x0;
	
	  //Chon POWER_ON
	  I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x46);
    I2C_Get_Ack(I2C1);
	
		I2C_Write_Byte(I2C1,POWER_ON);
    I2C_Get_Ack(I2C1);
		I2C_Stop(I2C1);
	  delay_us(15000);
	
	  //Chon mode 
		I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x46);
    I2C_Get_Ack(I2C1);
	
		I2C_Write_Byte(I2C1,CONTINUOUS_HIGH_RES_MODE_1);
    I2C_Get_Ack(I2C1);
		I2C_Stop(I2C1);
		delay_us(15000);
	
		//Doc du lieu
		I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x47);
    I2C_Get_Ack(I2C1);
	
		_BYTE_DATA_H=I2C_Read_Byte(I2C1);
	  I2C_Give_Ack(I2C1);
		_BYTE_DATA_L=I2C_Read_Byte(I2C1);
		I2C_Give_Ack(I2C1);
		I2C_Stop(I2C1);
		delay_us(15000);
		
		_DATA|=_BYTE_DATA_H<<8;
		_DATA|=_BYTE_DATA_L;
		
		
		//RESET
		I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x46);
    I2C_Get_Ack(I2C1);
	  
		I2C_Write_Byte(I2C1,RESET);
    I2C_Get_Ack(I2C1);
		I2C_Stop(I2C1);
	  delay_us(15000);
		
		
		//POWER_DOWN
		I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x46);
    I2C_Get_Ack(I2C1);
	  
		I2C_Write_Byte(I2C1,POWER_DOWN);
    I2C_Get_Ack(I2C1);
		I2C_Stop(I2C1);
	  delay_us(15000);
		
		return _DATA;
}
예제 #11
0
파일: mag.c 프로젝트: KyleAshley/quadcopter
void m_setMeasurementMode(unsigned int mode)
{
   I2C_Write_Byte(m_ID, m_MODE, mode);
}