本文整理汇总了C++中delay_us函数的典型用法代码示例。如果您正苦于以下问题:C++ delay_us函数的具体用法?C++ delay_us怎么用?C++ delay_us使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了delay_us函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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;
}
示例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;
//.........这里部分代码省略.........
示例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;
}
示例11: mouse_sens_wait
/**
* wartet 100 us
*/
static void mouse_sens_wait(void) {
delay_us(100);
}
示例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);
}
}
示例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);
}
}
示例14: delay_ms
void delay_ms(int count) {
delay_us(count*1000);
}
示例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...
//.........这里部分代码省略.........