CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Fastest SW SPI code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
thomasn101
Guest







Fastest SW SPI code
PostPosted: Tue Feb 24, 2004 2:26 pm     Reply with quote

Hi everyone,

I want to speed up my software SPI code. With the crystal freq at 20Mhz, the transfer rate of the code below is about 270Khz. Is there anything I can do to speed it up?

Regards,
Thomas
Code:

int SW_SPI_TXRX(int dataout)
{
     int Spi_Bit_Count, Datain;

     #Asm
     Bcf       Porte, 0            // Clock Low
     Clrf      Spi_Bit_Count
     
Next_Bit:
     Bcf       Porte, 1            // Clear Data_Out Pin
     Rlf       Dataout, F
     Btfsc     Status, 0
     Bsf       Porte, 1            // Set Data_Out Pin
     
     Bsf       Porte, 0            // Clock High
     Bcf       Porte, 0            // Clock Low
     
     Bcf       Status, 0           // Clear C
     Btfsc     Portd, 3            // Check Data_In Pin
     Bsf       Status, 0           // Set C
     Rlf       Datain, F
     
     Incf      Spi_Bit_Count, F
     Movlw     8
     Subwf     Spi_Bit_Count,W
     Btfss     Status, 2           // Check Status, Z Flag
     Goto      Next_Bit
     
     Movf      Datain, W
     Movwf     _Return_
     #Endasm
}
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Feb 24, 2004 2:31 pm     Reply with quote

Of these two lines one is marginaly faster. This should help shave a few instructions off of your code.

for(x=8;x>0;x--)

for(x=0;x<8;x++)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group