Best way to control port bits

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Best way to control port bits

跳至解决方案
1,857 次查看
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
标签 (1)
0 项奖励
回复
1 解答
585 次查看
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 项奖励
回复
2 回复数
585 次查看
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 项奖励
回复
586 次查看
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 项奖励
回复