Exemplo n.º 1
0
unsigned int One_Wire_Reset(GPIO_TypeDef * GPIOx, u16 PINx)
{
	unsigned int tmp;
	PIN_IN(GPIOx, PINx);
	if ((PIN_SYG(GPIOx, PINx))==0)	return One_Wire_Bus_Low_Error;
	PIN_OUT_PP(GPIOx, PINx);
	PIN_OFF(GPIOx, PINx);
	delay_us(Time_Reset_Low);
	PIN_ON(GPIOx, PINx);
	PIN_IN(GPIOx, PINx);
	delay_us(Time_Pulse_Delay_High);
	if ((PIN_SYG(GPIOx, PINx))==0) tmp=One_Wire_Success;
		else tmp=One_Wire_Error_No_Echo;
	delay_us(Time_After_Reset);
	return tmp;
}
Exemplo n.º 2
0
static uint8_t ds_read_bit()
{
	uint8_t i, b = 1;
	
	/* Begin a read/write time slot
	 * pull line low for between 1us and 15us */
	PIN_LOW();
	PIN_OUT();
	_delay_us(BEGIN_TIMESLOT);
	PIN_IN();
	
	_delay_us(DELAY_TIMESLOT);
	
	/* If the sensor pulls the line low within
	 * the time slot the bit is 0 */
	for(i = 0; i < TIMESLOT - BEGIN_TIMESLOT; i++)
	{
		if(!READ_PIN()) b = 0;
		_delay_us(1);
	}
	
	_delay_us(RECOVERY);
	
	return(b);
}
Exemplo n.º 3
0
static void ds_write_bit(uint8_t b)
{
	/* Begin a read/write time slot
	 * pull line low for between 1us and 15us */
	PIN_LOW();
	PIN_OUT();
	_delay_us(BEGIN_TIMESLOT);
	
	/* "1" is written by releasing the line immediatly */
	if(b) PIN_IN();
	
	/* Wait for the write slot to end and then release the line */
	_delay_us(TIMESLOT - BEGIN_TIMESLOT);
	PIN_IN();
	
	_delay_us(RECOVERY);
}
Exemplo n.º 4
0
static void lcdPrepareRead(void)
{
    PIN_IN(LCD_D0);
    PIN_IN(LCD_D1);
    PIN_IN(LCD_D2);
    PIN_IN(LCD_D3);
    PIN_IN(LCD_D4);
    PIN_IN(LCD_D5);
    PIN_IN(LCD_D6);
    PIN_IN(LCD_D7);
    CMD_READ();
}
Exemplo n.º 5
0
unsigned char One_Wire_Read_Bit (GPIO_TypeDef * GPIOx, u16 PINx)
{
		unsigned char tmp;
	 	PIN_OUT_PP(GPIOx, PINx);
		PIN_OFF(GPIOx, PINx);
		delay_us(Time_Hold_Down);
		PIN_IN(GPIOx, PINx);
		delay_us(Time_Pulse_Delay_Low);
		if ((PIN_SYG(GPIOx, PINx))!=0)	tmp = 1;
			else tmp = 0;
		delay_us(Time_Pulse_Delay_High);
		return tmp;
}
Exemplo n.º 6
0
void One_Wire_Write_Bit (unsigned char Bit,GPIO_TypeDef * GPIOx, u16 PINx)
{
	PIN_OUT_PP(GPIOx, PINx);
	PIN_OFF(GPIOx, PINx);
	if (Bit==0)
	{
		delay_us(Time_Pulse_Delay_High);
		PIN_ON(GPIOx, PINx);
		delay_us(Time_Pulse_Delay_Low);
	}
	else
	{
		delay_us(Time_Pulse_Delay_Low);
		PIN_ON(GPIOx, PINx);
		delay_us(Time_Pulse_Delay_High);
	}
	PIN_IN(GPIOx, PINx);
}
Exemplo n.º 7
0
static int ds_reset()
{
	/* Reset pulse - pull line low for at least 480us */
	PIN_LOW();
	PIN_OUT();
	_delay_us(RESET_PULSE);
	PIN_IN();
	
	/* The sensor should respond by pulling the line low
	 * after 15us to 60us for 60us to 240us. Wait for
	 * 80us for the line to go low */
	_delay_us(RESET_WAIT_LOW);
	if(READ_PIN()) return(DS_TIMEOUT);
	
	_delay_us(RESET_PULSE - RESET_WAIT_LOW);
	if(!READ_PIN()) return(DS_TIMEOUT);
	
	return(DS_OK);
}