View previous topic :: View next topic |
Author |
Message |
viknes1985
Joined: 11 Nov 2008 Posts: 24
|
How does this code work? |
Posted: Mon Feb 16, 2009 12:26 pm |
|
|
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: 1934 Location: Norman, OK
|
|
Posted: Mon Feb 16, 2009 12:50 pm |
|
|
...
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
|
|
Posted: Mon Feb 16, 2009 3:13 pm |
|
|
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
|
|
Posted: Mon Feb 16, 2009 3:41 pm |
|
|
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
|
read the input |
Posted: Mon Feb 16, 2009 11:02 pm |
|
|
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
|
|
Posted: Tue Feb 17, 2009 11:58 am |
|
|
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. |
|
|
|