Re: Accessing general I/O addresses



On Wed, 26 Dec 2007 21:35:00 -0800, ssylee wrote:

I apologize in advance if I didn't cross-post properly.

Apparently not -- I only see comp.arch.embedded mentioned in the
headers. Google is _not_ a good newsreader!

I want to write
a .c and .h file controlling a DS1302 real-time clock using a PIC18F2620
microcontroller. I want to keep my RTC code's pin usage flexible, so I
want to write an initialization routine that reads in the pins that the
whole program wants to use in main.c and have RTC.c and RTC.h refer to
the wanted pins. I am having trouble finding the address of the pins,
let's say RA1, RA2, ..., in the data***. I've posted a similar thread
in Microchip forums and got an example shown in
http://www.htsoft.com/forum/all/showflat.php/Cat/0/Number/31232/an/0/
page/0#Post31232
. However, due to the typical response time I get on that forum, I'm
trying my luck in other places as well as for second opinion. Thank you
for any comments in advance.

RA0 - RA7 are pins on PORTA, RB0 - RB7 are pins on PORTB, etc. You can
find the port addresses in the data *** quickly enough with some
searching.

You cannot address individual pins directly -- you have to read or write
the whole port. If you want a means of 'virtually' writing to single
pins you have to cook it up yourself, or find someone's method.

Generally the methods I've seen store a port address and offset to get to
the pin, then have some means of guaranteeing reentrancy, at least on a
system that supports multiple threads.

--
Tim Wescott
Control systems and communications consulting
http://www.wescottdesign.com

Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
.