PDA

View Full Version : Assign different port bits to an array?



vamtbrider
- 29th November 2010, 18:55
I have several outputs that are on different ports. I would like to use an array to cycle through the outputs, turning then on and off one at a time.

Is there a way to assign different port bits to an array?
Something like this: (I know this won't work but this kind of shows what I want to do)


'***********************************************
'* Configure Variables for Lights
'***********************************************
Lights VAR Bit[NoLights]
Lights[0] VAR PORTB.1
Lights[1] VAR PORTE.2
Lights[2] VAR PORTE.1
Lights[3] VAR PORTE.0
Lights[4] VAR PORTA.5
Lights[5] VAR PORTA.4

Then I would do something like this:


'turn off all the lights
for x = 0 to NoLights
Lights[x] = 0
next x

Thanks

Archangel
- 29th November 2010, 19:29
Hi vamtbrider,
read these posts for your answer:
http://www.picbasic.co.uk/forum/showthread.php?t=1339
http://www.picbasic.co.uk/forum/showthread.php?t=4074&p=22065

Use this tool to search this forum, it is a special Google engine, and you can also search 2 or 2 letter items:
http://www.google.com/custom?hl=en&cof=AH%3Aleft%3BS%3Ahttp%3A%2F%2Fwww.picbasic.co.u k%2Fforum%3BL%3Ahttp%3A%2F%2Fwww.crownhill.co.uk%2 Flogo.gif%3BLH%3A37%3BLW%3A174%3B&domains=picbasic.co.uk&q=&btnG=Search&sitesearch=

vamtbrider
- 29th November 2010, 19:43
Joe S.

Thanks for the link, that was exactly what I was looking for. I haven't played with marcos much but this will be a good start.

I have been searching for a couple hours using the forum search and wasn't finding any leads.

I will now use the google link you sent.

Thanks again for pointing me in the right direction.

Archangel
- 29th November 2010, 22:21
<h1>Super !</h1>
Happy it helped ! So many times, it seems my help isn't, but I try.

"Trying is the first step toward failure". Homer Simpson

Charles Linquis
- 30th November 2010, 02:40
This should also work for what you are trying to do.



' PORT OFFSETS
'
'
'"A.0",0
'"A.1",1
'"A.2",2
'"A.3",3
'"A.4",4
'"A.5",5
'"A.6",6
'"A.7",7
'"B.0",8
'"B.1",9
'"B.2",10
'"B.3",11
'"B.4",12
'"B.5",13
'"B.6",14
'"B.7",15
'"C.0",16
'"C.1",17
'"C.2",18
'"C.3",19
'"C.4",20
'"C.5",21
'"C.6",22
'"C.7",23
'"D.0",24
'"D.1",25
'"D.2",26
'"D.3",27
'"D.4",28
'"D.5",29
'"D.6",30
'"D.7",31
'"E.0",32
'"E.1",33
'"E.2",34
'"E.3",35
'"E.4",36
'"E.5",37
'"E.6",38
'"E.7",39
'"F.0",40
'"F.1",41
'"F.2",42
'"F.3",43
'"F.4",44
'"F.5",45
'"F.6",46
'"F.7",47
'"G.0",48
'"G.1",49
'"G.2",50
'"G.3",51
'"G.4",52
'"G.5",53
'"G.6",54
'"G.7",55
'"H.0",56
'"H.1",57
'"H.2",58
'"H.3",59
'"H.4",60
'"H.5",61
'"H.6",62
'"H.7",63
'"J.0",64
'"J.1",65
'"J.2",66
'"J.3",67
'"J.4",68
'"J.5",69
'"J.6",70
'"J.7",71

For X = 0 to 10

Lookup X,[0,1,2,5,9,10,11,12,13,15,19,70],PortValue ; Put the bits you want to modify here, use table above

Lookup X,[1,1,0,1,1,0,1,0,0,0,0],State ; put a 1 or a 0 here to determine state.

TRISA.0(PortValue) = 0 ;Make it an output
PORTA.0(PortValue) = State ;Set/Clear the bit
Next X