output to part of port

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

output to part of port

1,848件の閲覧回数
ernestsnaith
Contributor I
Hi
 
I am using 4 pins of an 8 bit wide output port. they are pins 1:4 and will control a BCD display. What is the simplist way of sending a number to the port.
 
If i was using pins 0:3, i would use PTAD = 5; for 5 etc but pin 0 is being used by something else.
 
cheers
ラベル(1)
0 件の賞賛
3 返答(返信)

334件の閲覧回数
ernestsnaith
Contributor I
thank you both
0 件の賞賛

334件の閲覧回数
tonyp
Senior Contributor II

ernestsnaith wrote:
Hi
I am using 4 pins of an 8 bit wide output port. they are pins 1:4 and will control a BCD display. What is the simplist way of sending a number to the port.
If i was using pins 0:3, i would use PTAD = 5; for 5 etc but pin 0 is being used by something else.
cheers





You need to read the port's current data, AND it with the inverted mask of the bits you want to use (in this case, %11100001), shift you BCD data left once so it occupies bits 4..1, instead of 3..0, then OR with the previous number, and store the whole thing back to the port. In assembly,

LDA PORT
AND #%11100001
PSHA
LDA BCD
LSLA
ORA 1,SP
STA PORT
PULA

Message Edited by tonyp on 2007-03-2905:14 PM

0 件の賞賛

334件の閲覧回数
bigmac
Specialist III
Hello,
 
Alternatively, doing a similar thing in C -
 
PTAD &= 0xE1;           // Clear bits 1-4 - does not affect other bits
PTAD |= BCDvalue << 1;  // Write new BCD value
 
Regards,
Mac
 
 
0 件の賞賛