Best way to control port bits

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Best way to control port bits

Jump to solution
1,854 Views
Bloodhound
Contributor I
Hi all,
 
So which of the below is 'acceptable' or most code efficient? Or does it not matter?
lda   #%00000000   ; Set up Port A values before turning on.
sta   PORTA        ; Values to Port A
lda   #%11110011   ; Set up Port A pullups before turning on.
sta   PTAPUE       ; Enable some pullups
lda   #%00000000   ; Store Port A Data Directions.
sta   DDRA         ; Configures Port A[7..0] as inputs
 
OR
 
mov   #%00000000,PORTA    ; Set up Port A values before turning on.
mov   #%11110011,PTAPUE   ; Set up Port A pullups before turning on.
mov   #%00000000,DDRA     ; Store Port A Data Directions.
 
Thanks,
Ross
 


Message Edited by Bloodhound on 2007-09-25 12:23 AM
Labels (1)
0 Kudos
Reply
1 Solution
582 Views
tonyp
Senior Contributor II
In theory, it doesn't matter.  But, for port setup, specifically,

1. STA is best for dynamic changes (value in A may change periodically, but not using the immediate mode as in your example, in which case I prefer [2] below).

2. MOV is best for static initialization (always the same value is written to the port at the specific point of execution), and it is shorter than [1].

3. Best for single bit changes but only after original initialization.  Using BSET/BCLR for first time setup is risky (as it blindly copies the remaining bits with whatever random values they happen to carry), a problem with write-once registers, for example.  (Did you just edit [3] out?)

View solution in original post

0 Kudos
Reply
2 Replies
582 Views
Bloodhound
Contributor I
Thanks TonyP,
 
Yes I did Edit out point 3. Sorry about that.
 
Cheers,
Ross
 
And I edited this due to a spelling mistake :smileysad:


Message Edited by Bloodhound on 2007-09-25 12:50 AM
0 Kudos
Reply
583 Views
tonyp
Senior Contributor II
In theory, it doesn't matter.  But, for port setup, specifically,

1. STA is best for dynamic changes (value in A may change periodically, but not using the immediate mode as in your example, in which case I prefer [2] below).

2. MOV is best for static initialization (always the same value is written to the port at the specific point of execution), and it is shorter than [1].

3. Best for single bit changes but only after original initialization.  Using BSET/BCLR for first time setup is risky (as it blindly copies the remaining bits with whatever random values they happen to carry), a problem with write-once registers, for example.  (Did you just edit [3] out?)

0 Kudos
Reply