[Top][All Lists]
[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
- Re: [avr-gcc-list] AVR assembly for fast bit bang, (continued)
- Re: [avr-gcc-list] AVR assembly for fast bit bang, David Kelly, 2005/11/08
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Mike S., 2005/11/09
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Daniel O'Connor, 2005/11/09
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Peter Fuhrmann, 2005/11/09
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Jesper Hansen, 2005/11/09
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Nils Springob, 2005/11/09
- Re: [avr-gcc-list] AVR assembly for fast bit bang, David Brown, 2005/11/10
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Mike S., 2005/11/16
- Re: [avr-gcc-list] AVR assembly for fast bit bang, Dave Hansen, 2005/11/09
- RE: [avr-gcc-list] AVR assembly for fast bit bang,
Nigel Winterbottom <=