output to part of port

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

output to part of port

1,829 Views
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
Labels (1)
0 Kudos
3 Replies

315 Views
ernestsnaith
Contributor I
thank you both
0 Kudos

315 Views
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 Kudos

315 Views
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 Kudos