avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] AVR assembly for fast bit bang


From: Nigel Winterbottom
Subject: RE: [avr-gcc-list] AVR assembly for fast bit bang
Date: Wed, 9 Nov 2005 12:56:43 -0000

You'll find this modification / correction helps with speed because you don't 
have to evaluate (1<<n) each time through the loop. Only a single bit shift on 
the 16-bit value is required.


#define ADS1210_PORT PORTF
#define SDIO_BIT     0x04 /* 0b0000 0100 PORTF.2*/
#define CLK_BIT      0x02 /* 0b0000 0010 PORTF.1*/
#define SDOUT_BIT    0x01 /* 0b0000 0001 PORTF.0*/

#define SDIO_LOW    ADS1210_PORT &= ~SDIO_BIT
#define SDIO_HIGH   ADS1210_PORT |=  SDIO_BIT
#define CLK_LOW   ADS1210_PORT &= ~CLK_BIT
#define CLK_HIGH  ADS1210_PORT |=  CLK_BIT
/*----------------------------------------------------------------------------+
| Function: write_data                                                        |
|                                                                             |
| Args:     n_bits                                                            |
|                                                                             |
| Action:  Writes <n_bits> in the device SDIO input pin                       |
|                                                                             |
| Efects:                                                                     |
|                                                                             |
+----------------------------------------------------------------------------*/
void write_data (Word towrite, Byte nbits)
{
  Word mask;
  Byte bitbount;

  for(mask=0x0001, bitcount=nbits;   bitcount != 0;   mask<<=1, bitcount--)
  {

    CLK_HIGH;
    if( towrite & mask)
    {
      SDIO_HIGH;
    }
    else
    {
      SDIO_LOW;
    }
    CLK_LOW;

  }
}


Nigel Winterbottom




reply via email to

[Prev in Thread] Current Thread [Next in Thread]