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: Nils Springob
Subject: Re: [avr-gcc-list] AVR assembly for fast bit bang
Date: Wed, 09 Nov 2005 16:29:48 +0100
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)

Hi,

I think there are two problems with the code:
- using 16 bit data
- shifting by a variable number of bits
An optimization would be to write a funktion which only shifts up to 8 bit, and to shift the data every time by one bit.

Regards,
Nils

original code:

void write_data (Word towrite, Byte nbits)
{
 Byte n;

 for(n = 0; n < nbits; n++)
 {

   CLK_HIGH;
   if( towrite & (0x0001 << n))
   {
     SDIO_HIGH;
   }
   else
   {
     SDIO_LOW;
   }
   CLK_LOW;

 }
}
my version:

void write_data_byte (Byte towrite, Byte nbits)
{
 while(nbits--)
 {
   CLK_HIGH;
   if (towrite&0x01)
   {
     SDIO_HIGH;
   }
   else
   {
     SDIO_LOW;
   }
   CLK_LOW;
   towrite = towrite>>1; // shift by constant value
 }
}

void write_data (Word towrite, Byte nbits)
{
 if (nbits>8)
 {
   write_data_byte((Byte)towrite, 8);
   write_data_byte((Byte)(towrite>>8), nbits-8);
 }
 else
 {
   write_data_byte((Byte)towrite, nbits);
 }
}





reply via email to

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