Proton

allocating variables to i/o ports

For PIC's - also known as PDS. Language: PICBasic

allocating variables to i/o ports

Postby Picman » Tue Jul 27, 2010 10:40 pm

Is there anyway, using PicBasic, to generate a variable (ie for to next loop) then activate an i/o pin corresponding to the variable value..( eg if x=3 then I want to send portb.3 high...what I want to do is send portb.x high however this doesn't work. If there is a way I'd be really grateful to know it :)
Cheers :?
User avatar
Picman
Active Member
Active Member
 
Posts: 2
Joined: Tue Jul 27, 2010 10:18 pm

Re: allocating variables to i/o ports

Postby Jon Chandler » Tue Jul 27, 2010 11:34 pm

One option may be to set the port equal to a number. This is easiest to understand in binary:

PortB = %00001000 would make pin 3 high and all others low.

There may be a way to alias bits but I don't recall.

A select-case statement might work well:

Select x
case 0
PortB = %00000000
case 1
PortB = %00000001
case 2
PortB = %00000010

etc....
User avatar
Jon Chandler
Moderator
Moderator
 
Posts: 350
Joined: Thu Oct 22, 2009 6:16 am
Location: Seattle WA, USA

Re: allocating variables to i/o ports

Postby Picman » Tue Jul 27, 2010 11:54 pm

Thanks Jon...First time I've ever come across a select-case statement but I intuit that it may work...hmmm...I'll try it and see if I can puzzle it out.
Cheers
:)
User avatar
Picman
Active Member
Active Member
 
Posts: 2
Joined: Tue Jul 27, 2010 10:18 pm


Return to Proton

Site Login