BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:30 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Specifying an input through a constant or variable
PostPosted: Tue Dec 27, 2011 11:21 pm 
Offline
Citizen

Joined: Fri May 06, 2011 8:19 am
Posts: 11
Is there a way to specify a pin to read through a constant or variable?

I'd like to write a program where I setup the pin assignments through constants or variables.
For example, you can write something like:

sda con p18
scl con p19

and then latter reference:

"high sda" instead of typing "high p18"

What I can't figure out is how to read a pin setup as an input in a similar way.
From what I can tell the pin variables "inxx" where xx is the pin number have to explicitly reference the pin number. I'd like to use something like "in(sda)" which would be equivalent to "in18" in this example.

Is there a way to do this that I'm missing? My goal is to declare the pin assignments at the beginning of a program and then have the rest of the program reference these assignments.


Top
 Profile  
 
 Post subject: Re: Specifying an input through a constant or variable
PostPosted: Thu Dec 29, 2011 9:03 am 
Offline
Citizen

Joined: Fri May 06, 2011 8:19 am
Posts: 11
After playing around a little bit, I found the following method...

Lets say you want to read SDA on pin 16. You can read INL0 (contains input values for pins 0 to 31) into a variable and shift right 16 digits and always read bit 0 of the result.

SDA_Read = INL0 >> SDA
SDA_Value = SDA_Read.Bit0

It works, but the overhead makes my overall bit banged I2C function* take about 2.5 times longer than an otherwise slow I2C read. Any ideas on how to lessen the overhead or another approach?

* This is being done to support a non-standard slow sensor which doesn't work with the built-in SW I2C functions and probably wouldn't even work with HW I2C because of the speed. The sensor also has a complete inability to change its address, and there is a desire to support 2 of these sensors which requires they be placed on different input pins.


Top
 Profile  
 
 Post subject: Re: Specifying an input through a constant or variable
PostPosted: Fri Dec 30, 2011 11:22 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
You can also use individual IN# variables which access the individual pins(eg IN16)

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO