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 CCS Technical Support

How does this code work?

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



Joined: 11 Nov 2008
Posts: 24

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

How does this code work?
PostPosted: Mon Feb 16, 2009 12:26 pm     Reply with quote

Can anyone tell me, how this code is run?

Code:

static byte datas;

datas = PORTB;
#define MASK_INPUT      0x10

//this code looped 64 times, on every interrupt

CARRY =  (datas & MASK_INPUT)? 0:1;   
               STAC[0] = STAC[0];                 
               
               #asm
               rlf STAC+7,f
               rlf STAC+6,f
               rlf STAC+5,f
               rlf STAC+4,f         
               rlf STAC+3,f
               rlf STAC+2,f
               rlf STAC+1,f
               rlf STAC+0,f
               #endasm
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Feb 16, 2009 12:50 pm     Reply with quote

...

Last edited by dyeatman on Tue Feb 17, 2009 5:08 am; edited 3 times in total
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Feb 16, 2009 3:13 pm     Reply with quote

Although the both codes use a similar 8-Byte-shift/rotate block, they have apparently different purpose. The first is a receiver shift register, the second does a rotate of a data rather than reading from an input. The first is intended for ISR operation, the second isn't.
Ttelmah
Guest







PostPosted: Mon Feb 16, 2009 3:41 pm     Reply with quote

Let me make a 'comment' purely on nomenclature.
#define MASK_INPUT 0x10

Is a 'macro'.
The line:
CARRY = (datas & MASK_INPUT)? 0:1;

Is a 'conditional statement'.
It sets the variable (definition not shown, but presumably an equivalent to the CCS '#bit' definition, addressing the processor carry bit), to either '0' or '1', according to the value of the selected bit in datas.

Then the rotations are done, with the carry bit being moved into the first bit of the data block.

Best Wishes
viknes1985



Joined: 11 Nov 2008
Posts: 24

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

read the input
PostPosted: Mon Feb 16, 2009 11:02 pm     Reply with quote

Thanks Ttelmah and FvM. You're right FvM, the posted code is to get the input from the device. What i don't understand is, whenever the rotation of the arrays takes place, how does the nearby arrays affected.....


Thanks again
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Feb 17, 2009 11:58 am     Reply with quote

I guess, you mean how the shifted out bit is transferred to the next register?. The instruction does rotate left through carry. Simply consult the description of RLF instruction an a PIC16xxx reference manual.
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