• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ delay_us函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中delay_us函数的典型用法代码示例。如果您正苦于以下问题:C++ delay_us函数的具体用法?C++ delay_us怎么用?C++ delay_us使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了delay_us函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: i2c_bus_reset

/**
 * @brief Reset an I2C bus.
 *
 * Reset is accomplished by clocking out pulses until any hung slaves
 * release SDA and SCL, then generating a START condition, then a STOP
 * condition.
 *
 * @param dev I2C device
 */
void i2c_bus_reset(i2c_dev *dev) {

    //unsigned clock_count;
    //unsigned stretch_count;

    i2c_deinit(dev);

    /* Release both lines */
    i2c_master_release_bus(dev);

    /*
     * Make sure the bus is free by clocking it until any slaves release the
     * bus.
     */
    while (!gpio_read_bit(dev->gpio_port, dev->sda_pin)) {
        /* Wait for any clock stretching to finish */
        while (!gpio_read_bit(dev->gpio_port, dev->scl_pin))
            ;
        delay_us(10);

        /* Pull low */
        gpio_write_bit(dev->gpio_port, dev->scl_pin, 0);
        delay_us(10);

        /* Release high again */
        gpio_write_bit(dev->gpio_port, dev->scl_pin, 1);
        delay_us(10);
    }

    /* Generate start then stop condition */
    gpio_write_bit(dev->gpio_port, dev->sda_pin, 0);
    delay_us(10);
    gpio_write_bit(dev->gpio_port, dev->scl_pin, 0);
    delay_us(10);
    gpio_write_bit(dev->gpio_port, dev->scl_pin, 1);
    delay_us(10);
    gpio_write_bit(dev->gpio_port, dev->sda_pin, 1);

    i2c_init(dev, 0, I2C_400KHz_SPEED);
}
开发者ID:136048599,项目名称:vrbrain,代码行数:49,代码来源:i2c.c


示例2: s_transstart

//----------------------------------------------------------------------------------
void s_transstart(void)
//----------------------------------------------------------------------------------
// generates a transmission start 
//       _____         ________
// DATA:      |_______|
//           ___     ___
// SCK : ___|   |___|   |______
{  
   SDA_OUT(1); SCL_OUT(0);                   //Initial state
   delay_us(2);
   SCL_OUT(1);
   delay_us(2);
   SDA_OUT(0);
   delay_us(2);
   SCL_OUT(0);  
   delay_us(6);
   SCL_OUT(1);
   delay_us(2);
   SDA_OUT(1);		   
   delay_us(2);
   SCL_OUT(0);		   
}
开发者ID:tigerer611,项目名称:smart-yanghu-cotroller,代码行数:23,代码来源:复件+SHT10.c


示例3: lcd_send_data

void lcd_send_data(const char data)
{
	if (lcd_mode_data == LCD_MODE_DATA_4)
	{
		LCD_PORT |=  (1<<LCD_RS);
		LCD_PORT &= ~(1<<LCD_RW);

		LCD_DDR  |=  0xf0;
		LCD_PORT = ( LCD_PORT & 0x0f) | (data & 0xf0);

		LCD_PORT |=  (1<<LCD_EN);
		delay_us(20);
		LCD_PORT &= ~(1<<LCD_EN);

		delay_us(20);
		LCD_PORT = ( LCD_PORT & 0x0f) | ((data<<4));// & 0xf0);

		LCD_PORT |=  (1<<LCD_EN);
		delay_us(20);
		LCD_PORT &= ~(1<<LCD_EN);

		delay_us(100);
	}
	else if (lcd_mode_data == LCD_MODE_DATA_8)
	{
		LCD_CPORT |=  (1<<LCD_RS);
		LCD_CPORT &= ~(1<<LCD_RW);

		LCD_DDDR  |= 0xff;
		LCD_DPORT = data;

		LCD_CPORT |=  (1<<LCD_EN);
		delay_us(20);
		LCD_CPORT &= ~(1<<LCD_EN);

		delay_us(100);
	}
}
开发者ID:nalamat,项目名称:smscontroller,代码行数:38,代码来源:lcd.cpp


示例4: ds18b20_write_bit

void ds18b20_write_bit(uint8_t bit)
{
  if(bit)
  {
    /*Write bit 1*/
    output_high();
    delay_us(1);//1us
    output_low();
    delay_us(5);
    output_high();
    delay_us(45);
  }
  else
  {
    /*Write bit 0*/
    output_high();
    delay_us(1);//1us
    output_low();
    delay_us(45);
    output_high();
    delay_us(10);
  }
}
开发者ID:hungicviet,项目名称:stm32-ds18b20,代码行数:23,代码来源:ds18b20.c


示例5: one_byte_w

void one_byte_w(uint8_t cmd, uint8_t msb)
{
	TWCR = 0x00;
	TWBR = 64;
	//TWSR = (1 << TWPS1);
	cbi(TWCR, TWEA);	
	sbi(TWCR, TWEN);
	delay_us(10);
	
	//Send start condition 
	i2cSendStart();		
    i2cWaitForComplete();
	delay_us(10);	
	printf("TWSR is: %x\n", (TWSR & 0xFC));
	
	
	// send slave device address with write
	i2cSendByte(SLA_W);	
	i2cWaitForComplete();
	delay_us(10);
	printf("TWSR is: %x\n", (TWSR & 0xFC));
	
	TWDR = cmd;
	TWCR = (1<<TWINT)|(1<<TWEN);	
	i2cWaitForComplete();
	delay_us(10);
	
	TWDR = msb;
	TWCR = (1<<TWINT)|(1<<TWEN);	
	i2cWaitForComplete();
	delay_us(10);

	
	delay_us(10);
    i2cSendStop();
	
}
开发者ID:JoshAshby,项目名称:Atmega328p-Dev-board-code,代码行数:37,代码来源:DS1077v2.c


示例6: display

void display(char tipo,char dado)
{
 char temp;
 if(tipo == true)
    {
     temp=(dado & 0xf0) | set_bit1;
     PORTB = temp;
     PORTB |= set_bit0;
     delay_us(5);
     PORTB &= clear_bit0;
//   delay_us(50);
     temp=(dado << 4) | set_bit1;
     PORTB = temp;
     PORTB |= set_bit0;
     delay_us(5);
     PORTB &= clear_bit0;
     delay_us(50);

    }
 else
    {
     temp=(dado & 0xf0);
     PORTB = temp;
     PORTB |= set_bit0;
     delay_us(5);
     PORTB &= clear_bit0;
//   delay_us(50);
     temp=(dado << 4);
     PORTB = temp;
     PORTB |= set_bit0;
     delay_us(5);
     PORTB &= clear_bit0;
     delay_us(50);
    }

}
开发者ID:jeanfbrito,项目名称:TemperatureController,代码行数:36,代码来源:lcd_generico.c


示例7: main

int main(void) {
	volatile int16_t* samples;
	unsigned int i;
	DISABLE_GLOBAL_INT();
	/* stop watchdog timer */
	WDTCTL = WDTPW +WDTHOLD;
	/* SET CPU to 5MHz */
	/* max DCO
	   MCLK = DCOCLK
	   SMCLK = DCOCLK
	   ACLK = 8KHz
	*/
	DCOCTL = DCO0 + DCO1 + DCO2;
	BCSCTL1 = RSEL0 + RSEL1 + RSEL2 + XT2OFF;
	BCSCTL2 = 0x00;

	delay_us(10000);

	/* activate Active Mode */
	__bic_SR_register(LPM4_bits);

	/* set LEDs when loaded */
	P5SEL = 0x00;
	P5DIR = 0x70;
	LED_RED_ON();
	LED_GREEN_OFF();
	LED_BLUE_OFF();

	check_for_clock();
	init_usb_serial();
#ifdef USE_DMA
	init_dma(&g_sample_flag);
#endif

#ifdef TX
	init_adc(&g_sample_flag);
#else
	init_dac();
#endif
	init_rf(RF_CHANNEL, PAN_ID, NODE_ADDR, &g_sample_flag);

	debug_print("Successfully booted.\n");
	/* set LEDS to signalize finished initilizing */
	LED_RED_OFF();
	ENABLE_GLOBAL_INT();

#ifdef TX
	/* TX */
	while(1) {
		if(g_sample_flag == 1) {
			g_sample_flag = 0;
#ifdef USE_DMA
			/* get samples */
			samples = get_samples_dma();
#else
			/* get samples */
			samples = get_samples();
#endif
			/* send oder radio, 2*num_words */
			send_rf_data(RF_RX_ADDR, (uint8_t*) samples, NUM_SAMPLES*2);
		}
		/* reset WDT */
		WDTCTL = WDTPW + WDTCNTCL;

	}
#else
	/* RX */
	while(1) {
		if(g_sample_flag == 1) {
			g_sample_flag = 0;
			samples = get_samples_rf();
#if 0
			uint8_t err = 0;
			for(i = 0; i < NUM_SAMPLES; ++i) {
				//samples[i] = 4095-7*i;
				usb_printf("%d\n", samples[i]);
				//if( ((uint16_t) samples[i]) > 4095) {
				//	usb_printf("i=%u\n", i);
				//	++err;
				//}
			}
			usb_printf("#error: %u\n", err);
			usb_printf("\n\n");
#endif			
			set_dma_data(samples, NUM_SAMPLES);
		}
		/* reset WDT */
		WDTCTL = WDTPW + WDTCNTCL;
	}
#endif
	return 0;
}
开发者ID:jarn0ld,项目名称:smeagol-walkie-talkie,代码行数:92,代码来源:main.c


示例8: refresh_outputs

void refresh_outputs (void)
{
	unsigned int output_sequence_buffer;
	unsigned char mask = 0;
	unsigned char i = 0;
	
	#ifndef T3_8IN16OUT
		unsigned char mux0, mux1, mux2;
		//signed int output_buffer;

		// if we are in digital mode, statement is false thus we skip the following part
		if(!digital_mode)
		{
			//disable the input MUX
			MUX_OFF1 = 1;
			// Save the current MUX channel.
			mux0 = CARDA0;
			mux1 = CARDA1;
			mux2 = CARDA2;
		
			// Set the channel for the output MUX
			CARDA0 = output_channel & 0x01;
			CARDA1 = output_channel & 0x02;
			CARDA2 = output_channel & 0x04;

			MUX_OFF2 = 0;
			delay_us(500);			
			MUX_OFF2 = 1;	// Disable the Output MUX
			
			//Restore the MUX channel and enable the input MUX
			CARDA0 = mux0;
			CARDA1 = mux1;
			CARDA2 = mux2;
			MUX_OFF1 = 0;
		}
	#else
		bit led_drive1_buf, led_drive2_buf, led_drive3_buf, led_drive4_buf;
		unsigned char output_state[2], P0_buffer;
	#endif
//	 output_channel ++ ;
//	 if(output_channel== MAX_OUTPUT_CHANNELS ) 	 output_channel = 0 ;

	 //Switch to the next channel
	output_channel = (output_channel+1)%MAX_OUTPUT_CHANNELS  ;    //increment the output_channel

	// Set the PWM for the testing sequence case
	if(output_sequence == 0)		// july 22 Ron
	{	
		if(digital_mode)
		{	// August Ron
			// testing sequence when in digital mode
			if(Enable_set_output)
			{	// set modbus.registers one channel at a time to test one output at a time
				if (output_sequence_count == 12)
				{	// set a different channel each time we get into this if statemen
					output_sequence_channel = (output_sequence_channel+1)%MAX_OUTPUT_CHANNELS;
		
					Enable_set_output = 0;	// stop setting outputs, wait till reading is done
					Enable_read_input = 1;	// given output is stopped, can now start reading inputs
	
					if(incrementing)
					{	// in this case set output to a high
						modbus.registers[output_sequence_channel] = 1000;
						// once we have reached a full cycle, start setting output to low
						if(output_sequence_channel==7)
							incrementing = 0;
						// reset counter
						output_sequence_count = 0;
						// turn LEDs off and now start testing SOP
						if ( startup_flag != 0)
							startup_flag--;

					}
					else
					{	// in this case set output to a low
						modbus.registers[output_sequence_channel] = 0;
						// once we have reached a ful cycle, start settign output to high
						if(output_sequence_channel==7)
							incrementing = 1;
						// reset counter
						output_sequence_count = 0;
						// turn LEDs off and now start testing SOP
						if ( startup_flag != 0)
							startup_flag--;
					}			
				}

				output_sequence_count++;
			}
		}
		else
			if (Enable_set_output)		// in SOP mode and do nothing if reading inputs
			{							// testing the analog mode
				// add a buffer value so that adjacent switches do not have same value
				// at every even switch add 500mV
				// august 9 Ron
				if ( output_channel%2 )
					output_sequence_buffer = 1000 - testing_increment_init;
				else
					output_sequence_buffer = testing_increment_init;
//.........这里部分代码省略.........
开发者ID:GuoxinyouTemco,项目名称:T3-Modules,代码行数:101,代码来源:read_outputs.c


示例9: main

void main(void)
{
   const unsigned char *mas="\r\n---------------MASTER DEVICE-----------------\r\n";

   const unsigned char * arr1 = "\r\nTaking in the text \r\n";

   const unsigned char *arr2="\r\nEnter your choice \r\n 1.Slave 1(Address:0xAA\r\n2.Slave 2(Address:0xBB)\r\n3.Slave 3(Address:0xCC\r\n";

   const unsigned char *arr3= "You have entered:\r\n";

   const unsigned char *arr4= "\r\nUART Initialised\r\n";

   const unsigned char *arr5= "\r\nI2C initialised:\r\n";

   const unsigned char *msg1="\r\nSending to Slave 1 (Address 0xAA)\r\n";

   const unsigned char *msg2="\r\nSending to Slave 2 (Address 0xBB)\r\n";

   const unsigned char *msg3="\r\nSending to Slave 3 (Address 0xCC)\r\n";

   const unsigned char *msg4="\r\nAddress sent\r\n";

   const unsigned char *msg5="\r\nData sent\r\n";

    

   const unsigned char *err="\r\nNo message will be sent since no slave no entered\r\n";
     const unsigned char *fin="\r\nClosing Communication!\r\n";

   const unsigned char *msgm="\r\nYou have entered choice number:\r\n";

   unsigned char choice;

   OSCCONbits.IRCF = 0x07;  // Configure Internal OSC for 8MHz Clock

    while(!OSCCONbits.HTS);   // Wait Until Internal Osc is Stable

    INTCON=0;   // purpose of disabling the interrupts.

    UART_Init(baud_rate);

    UART_Write_Text(mas);

    UART_Write_Text(arr4);

    delay_ms(500);

    I2C_init();

    UART_Write_Text(arr5);
     //Initialisation done

    while(1)
    {
        UART_Write_Text(arr1);

        i2c_idle();

  //receive the characters until ENTER is pressed (ASCII for ENTER = 13)

         is=UART_Read_Text();

         UART_Write_Text(arr3);

         UART_Write_Text(is);

         UART_Write_Text(arr2);

         choice=UART_Read();

         UART_Write_Text(msgm);

         UART_Write(choice);

    switch(choice)
    {
        case 0x31:
        {
            UART_Write_Text(msg1);
            
            I2C_Start();

            if(I2C_address_send())//device address
           {   
           	delay_us(20);//clock settle and then send
                I2C_Write_Text(is);
           }
            
              else
                  break;
             I2C_Stop();
              break;
        }

        case 0x32:

          {
            UART_Write_Text(msg2);

            I2C_Start();
//.........这里部分代码省略.........
开发者ID:Abhi8861,项目名称:Implementation-of-Ciphering-Technique-on-communication,代码行数:101,代码来源:Masterst1.c


示例10: set_serial_clk

static __u32 set_serial_clk(__u32 mmu_flag)
{
	__u32 			src_freq = 0;
	__u32 			p2clk = 0;
	volatile unsigned int 	*reg = (volatile unsigned int 	*)(0);
	__ccmu_reg_list_t 	*ccu_reg = (__ccmu_reg_list_t 	*)(0);	
	__u32 port = 0;
	__u32 i = 0;

	ccu_reg = (__ccmu_reg_list_t   *)mem_get_ba();
	//check uart clk src is ok or not.
	//the uart clk src need to be pll6 & clk freq == 600M?
	//so the baudrate == p2clk/(16*div)
	switch(ccu_reg->Apb1_Cfg.bits.apb1_clk_src_sel){
		case 0:
			src_freq = 24000000;	//24M
			break;
		case 1:
			src_freq = 960000000;	//FIXME: need confirm the freq!
			break;
		default:
			break;
	}

	//calculate p2clk.
	p2clk = src_freq/((ccu_reg->Apb1_Cfg.bits.clk_rat_m + 1) * (1<<(ccu_reg->Apb1_Cfg.bits.clk_rat_n)));

	/*notice:
	**	not all the p2clk is able to create the specified baudrate.
	**	unproper p2clk may result in unacceptable baudrate, just because
	**	the uartdiv is not proper and the baudrate err exceed the acceptable range. 
	*/
	if(mmu_flag){
		//backup apb2 gating;
		backup_ccu_uart = *(volatile unsigned int *)(IO_ADDRESS(AW_CCU_UART_PA));
		//backup uart reset 
		backup_ccu_uart_reset = *(volatile unsigned int *)(IO_ADDRESS(AW_CCU_UART_RESET_PA));

		//config uart clk: apb2 gating.
		reg = (volatile unsigned int *)(IO_ADDRESS(AW_CCU_UART_PA));
		*reg &= ~(1 << (16 + port));
		for( i = 0; i < 100; i++ );
		*reg |=  (1 << (16 + port));
		change_runtime_env();
		delay_us(1);	
		//de-assert uart reset
		reg = (volatile unsigned int *)(IO_ADDRESS(AW_CCU_UART_RESET_PA));
		*reg &= ~(1 << (16 + port));
		for( i = 0; i < 100; i++ );
		*reg |=  (1 << (16 + port));

	}else{
		//config uart clk
		reg = (volatile unsigned int *)(AW_CCU_UART_PA);
		*reg &= ~(1 << (16 + port));
		for( i = 0; i < 100; i++ );
		*reg |=  (1 << (16 + port));
		change_runtime_env();
		delay_us(1);	
		//de-assert uart reset
		reg = (volatile unsigned int *)(AW_CCU_UART_RESET_PA);
		*reg &= ~(1 << (16 + port));
		for( i = 0; i < 100; i++ );
		*reg |=  (1 << (16 + port));

	}

	return p2clk;
	
}
开发者ID:925outer,项目名称:BPI-M2P-bsp,代码行数:70,代码来源:mem_serial.c


示例11: mouse_sens_wait

/**
 * wartet 100 us
 */
static void mouse_sens_wait(void) {
	delay_us(100);
}
开发者ID:lenchen-88,项目名称:ct-bot,代码行数:6,代码来源:mouse.c


示例12: display_alarm_time

//Displays current alarm time
//Brightness level is an amount of time the LEDs will be in - 200us is pretty dim but visible.
//Amount of time during display is around : [ BRIGHT_LEVEL(us) * 5 + 10ms ] * 10
//Roughly 11ms * 10 = 110ms
//Time on is in (ms)
void display_alarm_time(uint16_t time_on)
{
	uint16_t bright_level = 50;
	
	//time_on /= 11; //Take the time_on and adjust it for the time it takes to run the display loop below

	for(uint16_t j = 0 ; j < time_on ; j++)
	{
		amMark2++;
		//Display normal hh:mm time
		if(hours_alarm > 9)
		{
			display_number(hours_alarm / 10, 1); //Post to digit 1
			delay_us(bright_level);
		}

		display_number(hours_alarm % 10, 2); //Post to digit 2
		delay_us(bright_level);

		display_number(minutes_alarm / 10, 3); //Post to digit 3
		delay_us(bright_level);

		display_number(minutes_alarm % 10, 4); //Post to digit 4
		delay_us(bright_level);

		
		//During debug, display mm:ss
		/*display_number(minutes_alarm / 10, 1); 
		delay_us(bright_level);

		display_number(minutes_alarm % 10, 2); 
		delay_us(bright_level);

		display_number(seconds_alarm / 10, 3); 
		delay_us(bright_level);

		display_number(seconds_alarm % 10, 4); 
		delay_us(bright_level);

		display_number(10, 5); //Display colon
		delay_us(bright_level);*/
		
		//Flash colon for each second
		if(flip == 1) 
		{
			display_number(10, 5); //Post to digit COL
			delay_us(bright_level);
		}
		
		//Check whether it is AM or PM and turn on dot
		if((ampm_alarm == AM)&&(amMark2 >= 10))
		{	
			amMark2 = 0;
			display_number(12, 6); //Turn on dot on apostrophe
			delay_us(bright_level);
		}

		clear_display();
		delay_ms(1);
	}
	
}
开发者ID:elpapais,项目名称:ClockIt,代码行数:67,代码来源:clockit-v11.c


示例13: display_time

//Displays current time
//Brightness level is an amount of time the LEDs will be in - 200us is pretty dim but visible.
//Amount of time during display is around : [ BRIGHT_LEVEL(us) * 5 + 10ms ] * 10
//Roughly 11ms * 10 = 110ms
//Time on is in (ms)
void display_time(uint16_t time_on)
{
	//uint16_t bright_level = 1000;
	uint16_t bright_level = 50;
	//uint16_t bright_level = 100;
	
	//time_on /= 11; //Take the time_on and adjust it for the time it takes to run the display loop below
	
	for(uint16_t j = 0 ; j < time_on ; j++)
	{
		amMark++;

#ifdef NORMAL_TIME
		//Display normal hh:mm time
		if(hours > 9)
		{
			display_number(hours / 10, 1); //Post to digit 1
			delay_us(bright_level);
		}

		display_number(hours % 10, 2); //Post to digit 2
		delay_us(bright_level);

		display_number(minutes / 10, 3); //Post to digit 3
		delay_us(bright_level);

		display_number(minutes % 10, 4); //Post to digit 4
		delay_us(bright_level);
#else
		//During debug, display mm:ss
		display_number(minutes / 10, 1); 
		delay_us(bright_level);

		display_number(minutes % 10, 2); 
		delay_us(bright_level);

		display_number(seconds / 10, 3); 
		delay_us(bright_level);

		display_number(seconds % 10, 4); 
		delay_us(bright_level);
#endif
		
		//Flash colon for each second
		if(flip == 1) 
		{
			display_number(10, 5); //Post to digit COL
			delay_us(bright_level);
		}
		
		//Indicate wether the alarm is on or off
		if( (PINB & (1<<BUT_ALARM)) != 0)
		{
			display_number(11, 4); //Turn on dot on digit 4
			delay_us(bright_level);

			//If the alarm slide is on, and alarm_going is true, make noise!
			if(alarm_going == TRUE && flip_alarm == 1)
			{
				clear_display();
				siren(500);
				flip_alarm = 0;
			}
		}
		else
		{
			snooze = FALSE; //If the alarm switch is turned off, this resets the ~9 minute addtional snooze timer
			
			hours_alarm_snooze = 88; //Set these values high, so that normal time cannot hit the snooze time accidentally
			minutes_alarm_snooze = 88;
			seconds_alarm_snooze = 88;
		}
		
		//Check whether it is AM or PM and turn on dot
		if((ampm == AM)&&(amMark>=5))
		{
			amMark = 0;	// This variable is used to help dim the am/pm dot
			display_number(12, 6); //Turn on dot on apostrophe
			delay_us(bright_level);
		}

		clear_display();
		delay_us(bright_level);
	}
}
开发者ID:elpapais,项目名称:ClockIt,代码行数:90,代码来源:clockit-v11.c


示例14: delay_ms

void delay_ms(int count) {
        delay_us(count*1000);
}
开发者ID:jiyeonroh,项目名称:W7500,代码行数:3,代码来源:main.c


示例15: txChar

uint8_t txChar(int data, int channel) {
  uint8_t x;
  uint8_t parity_bit = 0;
  uint16_t tx_timeout;

  /*
   * Clear errors from previous transmissions.
   */
  tx_parity_error = FALSE;

  /*
   * Let neighbor know you want to talk to it.
   * Then wait for an acknowledgement.  Timeout
   * if necessary.
   */
  //these 3 lines take about 7 us
  setDataLine(channel, 1); //to avoid capacitive noise from clock line
  setClockLine(channel, 0);
  releaseDataLine(channel); // allow neighbor to respond

  tx_timeout = (TX_WAIT_FOR_NEIGHBOR_RELOAD + handshake_retry_addition);

  while(pollDataLine(channel)) {
    tx_timeout--;
    if(tx_timeout == 0) {
      // Communication timed out... no one listening on this channel.
      // This counts as an unsuccessful transmission.
      releaseClockLine(channel); // Set clock line back to an input.
      return FALSE;
    }
  }



  /*
   * Once acknowledged, wait for the receiving neighbor to
   * relinquish control of the data line, then assert control
   * over both clock and data.
   */
  tx_timeout = TX_TIMEOUT_RELOAD;
  while(!pollDataLine(channel)) {
    tx_timeout--;
    if(tx_timeout == 0) {
      // Communication timed out... no one listening on this channel.
      // This counts as an unsuccessful transmission.
      releaseClockLine(channel); // Set clock line back to an input.
      //if (goodChannels & (0x01 << (channel - 1))) {  // if the current channel is good, then...
      //blinkGreen(1);  // meme
      //blinkRed(1);
      //}
      //      debugLog(RECEIVER_DIDNT_RELEASE_CLOCK_LINE);
      return FALSE;
    }
  }
  setClockLine(channel, 1);
  setDataLine(channel, 1);

  sei();

  /*
   * Both parties are agreed on who is sending and who is receiving,
   * so start transmission of the byte, bit by bit.
   */
  for(x = 0; x < 8; x++) {
    /*
     * Send out the LSB.
     */
    setDataLine(channel, (data & 0x01));
    setClockLine(channel, 0);
	
    /*
     * Give the receiver time to process the outgoing bit.
     */
    delay_us(BIT_LOW_TIME);
	
    /*
     * Modify the parity bit to reflect the bit just sent and
     * prepare the data to send the next bit.
     */
    parity_bit ^= (data & 0x01);
    data >>= 1;
	
    /*
     * Return communication channel to idle state to let
     * the receiver know that a new bit is coming.
     */
    setClockLine(channel, 1);
    setDataLine(channel, 1);
    delay_us(BIT_HIGH_TIME);
  }

  /*
   * Send parity bit for error detection.
   */
  setDataLine(channel, parity_bit);
  setClockLine(channel, 0);
  delay_us(BIT_LOW_TIME);
  releaseDataLine(channel);

  //just testing here...
//.........这里部分代码省略.........
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:101,代码来源:comm.c


示例16: rxChar

uint8_t rxChar(uint8_t channel) {
  uint8_t x;
  uint8_t parity_bit = 0;
  uint8_t rx_parity_bit = 0;
  uint8_t data = 0x00;
  uint8_t bitplace = 0x1;

  /*
   * Check for a handshake initialization.  Timeout if necessary.
   */
  rx_timeout = RX_TIMEOUT_RELOAD;
  while(pollClockLine(channel)) {
    if(rx_timeout-- == 0) {
      failed_to_rx = TRUE;
      return 0;
    }
  }
   
  //topobo tried to receive a msg from another active that was connected
  debugLog(INIT_RX);

  /*
   * Return the handshake and give the transmitter time to respond.
   */
  setDataLine(channel, 0);
  delay_us(BIT_LOW_TIME);

  /*
   * Relinquish control of the data line by setting it as an input.
   */
  releaseDataLine(channel);

  /*
   * Look for the first bit.  Timeout if necessary.
   */
  rx_timeout = RX_TIMEOUT_RELOAD;
  while(! pollClockLine(channel)) {
    if(rx_timeout-- == 0) {
      failed_to_rx = TRUE;
      debugLog(NO_FIRST_BIT);
      return 0;
    }
  }
  //uart_putchar('h');
  for(x = 0; x < 8; x++) {
    //uart_putchar('0'+x);
    /*
     * Watch the clock line for a sign that a bit is ready
     * to be read.  Timeout if necessary.
     */
    rx_timeout = RX_TIMEOUT_RELOAD;
    while(pollClockLine(channel)) {
      if(rx_timeout-- == 0) {
	failed_to_rx = TRUE;
	debugLog(NO_START_OF_BIT);
	return 0;
      }
    }
    /*
     * Once the bit is ready, read it.
     */
    if(pollDataLine(channel)) {
      data |= bitplace;
      parity_bit ^= 0x01;
    }
    bitplace <<= 1;

    /*
     * Once a bit has been received, wait for the
     * the transmitter to declare the end of the bit.
     * Timeout if necessary.
     */
    rx_timeout = RX_TIMEOUT_RELOAD;
    // meme : something is happening here.
    while(! pollClockLine(channel)) {
      if(rx_timeout-- == 0) {
	failed_to_rx = TRUE;
	debugLog(NO_END_OF_BIT);
	return 0;
      }
    }
  }

  /*
   * Read in the parity bit.
   */
  rx_timeout = RX_TIMEOUT_RELOAD;
  while(pollClockLine(channel)) {  // Wait until bit is ready to read.
    if(rx_timeout-- == 0) {
      failed_to_rx = TRUE;
      debugLog(NO_PARITY_BIT);
      return 0;
    }
  }

  // Read the bit and store it. (initially = 0)
  if(pollDataLine(channel)) { 
    rx_parity_bit = 1;
  }

//.........这里部分代码省略.........
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:101,代码来源:comm.c


示例17: Lcd_Init

void Lcd_Init(void)
{
  LCD_REST_1;
  delay_us(5);	
  LCD_REST_0;
  delay_us(5);
  LCD_REST_1;
  LCD_CS_1;
  LCD_RD_1;
  LCD_WR_1;
  delay_us(5);
  LCD_CS_0;  //打开片选使能
  Lcd_Write_Com_Data(0x00,0x0000);		
  Lcd_Write_Com_Data(0x00,0x0000);		
  Lcd_Write_Com_Data(0x00,0x0000);	
  Lcd_Write_Com_Data(0x00,0x0001);	
  Lcd_Write_Com_Data(0xA4,0x0001);		
  delay_us(10); 
  Lcd_Write_Com_Data(0x60,0x2700);			
  Lcd_Write_Com_Data(0x08,0x0808);		
  Lcd_Write_Com_Data(0x30,0x0214);
  Lcd_Write_Com_Data(0x31,0x3715);
  Lcd_Write_Com_Data(0x32,0x0604);
  Lcd_Write_Com_Data(0x33,0x0E16);
  Lcd_Write_Com_Data(0x34,0x2211);
  Lcd_Write_Com_Data(0x35,0x1500);
  Lcd_Write_Com_Data(0x36,0x8507);
  Lcd_Write_Com_Data(0x37,0x1407);
  Lcd_Write_Com_Data(0x38,0x1403);
  Lcd_Write_Com_Data(0x39,0x0020);
  Lcd_Write_Com_Data(0x90,0x0015);
  Lcd_Write_Com_Data(0x10,0x0410);
  Lcd_Write_Com_Data(0x11,0x0237);
  Lcd_Write_Com_Data(0x29,0x0046);
  Lcd_Write_Com_Data(0x2A,0x0046);
  Lcd_Write_Com_Data(0x07,0x0000);
  Lcd_Write_Com_Data(0x12,0x0189);
  Lcd_Write_Com_Data(0x13,0x1100);
  delay_us(150);
  Lcd_Write_Com_Data(0x12,0x01B9);
  Lcd_Write_Com_Data(0x01,0x0100);
  Lcd_Write_Com_Data(0x02,0x0200);
  Lcd_Write_Com_Data(0x03,0x1030);
  Lcd_Write_Com_Data(0x09,0x0001);
  Lcd_Write_Com_Data(0x0A,0x0000);
  Lcd_Write_Com_Data(0x0D,0x0000);
  Lcd_Write_Com_Data(0x0E,0x0030);
  Lcd_Write_Com_Data(0x50,0x0000);
  Lcd_Write_Com_Data(0x51,0x00EF);
  Lcd_Write_Com_Data(0x52,0x0000);
  Lcd_Write_Com_Data(0x53,0x013F);
  Lcd_Write_Com_Data(0x61,0x0001);
  Lcd_Write_Com_Data(0x6A,0x0000);
  Lcd_Write_Com_Data(0x80,0x0000);
  Lcd_Write_Com_Data(0x81,0x0000);
  Lcd_Write_Com_Data(0x82,0x005F);
  Lcd_Write_Com_Data(0x92,0x0100);
  Lcd_Write_Com_Data(0x93,0x0701);
  delay_us(80);
  Lcd_Write_Com_Data(0x07,0x0100);
  Lcd_Write_Com_Data(0x20,0x0000);
  Lcd_Write_Com_Data(0x21,0x0000);
  Lcd_Write_Com(0x0022);
  LCD_CS_1;  //关闭片选使能
}
开发者ID:jonathan-wu,项目名称:test,代码行数:65,代码来源:TFT.c


示例18: wait_reset

static void wait_reset(void) {
  delay_us(RESET_DELAY);
  nvic_sys_reset();
}
开发者ID:bitcynth,项目名称:Arduino_STM32,代码行数:4,代码来源:usb_serial.cpp


示例19: run_gloc_4inputs_xor_test

/**
 * \brief Test GLOC Logic module with 4 Inputs XOR.
 *
 * This tests check the capabilty of the Glue Logic driver to handle 4
 * inputs XOR operation.
 *
 * \param test Current test case.
 */
static void run_gloc_4inputs_xor_test(const struct test_case *test)
{
	bool out;

	/* Configure pins for changing GLOC input */
	ioport_set_pin_dir(CONF_TEST_GLOC_IN0, IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(CONF_TEST_GLOC_IN1, IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(CONF_TEST_GLOC_IN2, IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(CONF_TEST_GLOC_IN3, IOPORT_DIR_OUTPUT);

	/* Set the 4 inputs XOR truth table value in LUT0. */
	gloc_lut_get_config_defaults(&lut_config);
	lut_config.truth_table_value = XOR_TRUTH_TABLE_FOUR_INPUT;
	gloc_lut_set_config(&dev_inst, 0, &lut_config);

	/* Test GLOC with different input */
	ioport_set_pin_level(CONF_TEST_GLOC_IN0, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN1, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN2, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN3, LOW);
	/** Ensure a minimum propagation delay to read the port pin. */
	delay_us(50);
	out = ioport_get_pin_level(CONF_TEST_GLOC_OUT0);
	test_assert_true(test, out == false, "4 inputs XOR failed at 1");

	ioport_set_pin_level(CONF_TEST_GLOC_IN0, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN1, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN2, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN3, LOW);
	/* Ensure a minimum propagation delay to read the port pin. */
	delay_us(50);
	out = ioport_get_pin_level(CONF_TEST_GLOC_OUT0);
	test_assert_true(test, out == true, "4 inputs XOR failed at 2");

	ioport_set_pin_level(CONF_TEST_GLOC_IN0, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN1, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN2, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN3, LOW);
	/* Ensure a minimum propagation delay to read the port pin. */
	delay_us(50);
	out = ioport_get_pin_level(CONF_TEST_GLOC_OUT0);
	test_assert_true(test, out == true, "4 inputs XOR failed at 3");

	ioport_set_pin_level(CONF_TEST_GLOC_IN0, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN1, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN2, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN3, LOW);
	/* Ensure a minimum propagation delay to read the port pin. */
	delay_us(50);
	out = ioport_get_pin_level(CONF_TEST_GLOC_OUT0);
	test_assert_true(test, out == false, "4 inputs XOR failed at 4");

	ioport_set_pin_level(CONF_TEST_GLOC_IN0, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN1, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN2, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN3, LOW);
	/* Ensure a minimum propagation delay to read the port pin. */
	delay_us(50);
	out = ioport_get_pin_level(CONF_TEST_GLOC_OUT0);
	test_assert_true(test, out == true, "4 inputs XOR failed at 5");

	ioport_set_pin_level(CONF_TEST_GLOC_IN0, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN1, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN2, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN3, LOW);
	/* Ensure a minimum propagation delay to read the port pin. */
	delay_us(50);
	out = ioport_get_pin_level(CONF_TEST_GLOC_OUT0);
	test_assert_true(test, out == false, "4 inputs XOR failed at 6");

	ioport_set_pin_level(CONF_TEST_GLOC_IN0, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN1, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN2, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN3, LOW);
	/* Ensure a minimum propagation delay to read the port pin. */
	delay_us(50);
	out = ioport_get_pin_level(CONF_TEST_GLOC_OUT0);
	test_assert_true(test, out == false, "4 inputs XOR failed at 7");

	ioport_set_pin_level(CONF_TEST_GLOC_IN0, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN1, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN2, HIGH);
	ioport_set_pin_level(CONF_TEST_GLOC_IN3, LOW);
	/* Ensure a minimum propagation delay to read the port pin. */
	delay_us(50);
	out = ioport_get_pin_level(CONF_TEST_GLOC_OUT0);
	test_assert_true(test, out == true, "4 inputs XOR failed at 8");

	ioport_set_pin_level(CONF_TEST_GLOC_IN0, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN1, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN2, LOW);
	ioport_set_pin_level(CONF_TEST_GLOC_IN3, HIGH);
//.........这里部分代码省略.........
开发者ID:InSoonPark,项目名称:asf,代码行数:101,代码来源:unit_tests.c


示例20: toggle_clock

static void toggle_clock() {
    delay_us(BIT_TIME_US);
    gpio_write(CLK, 0);
    delay_us(BIT_TIME_US);
    gpio_write(CLK, 1);
}
开发者ID:ericscrum,项目名称:cs107e.github.io,代码行数:6,代码来源:keyboard-emulator.c



注:本文中的delay_us函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ delayacct_tsk_free函数代码示例发布时间:2022-05-30
下一篇:
C++ delay_ms函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap