output to part of port

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

output to part of port

2,318 次查看
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 回复数

804 次查看
ernestsnaith
Contributor I
thank you both
0 项奖励
回复

804 次查看
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 项奖励
回复

804 次查看
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 项奖励
回复