PDA

View Full Version : Making Array of two ports



John7
- 25th February 2005, 12:21
Hi all PBP Artists!
i'm trying to create an array of two ports -porta and portc (16f630)

Output VAR bit[9]

SYMBOL Output[0] = PORTA.0
SYMBOL Output[1] = PORTA.1
SYMBOL Output[2] = PORTA.2
SYMBOL Output[3] = PORTA.3
SYMBOL Output[4] = PORTA.4
SYMBOL Output[5] = PORTC.0
SYMBOL Output[6] = PORTC.1
SYMBOL Output[7] = PORTC.2
SYMBOL Output[8] = PORTC.3
SYMBOL Output[9] = PORTC.4

for x = o to 9
Output[x] = 1
next x

it doesn't work! where is my mistake?

Acetronics2
- 25th February 2005, 13:22
May be help on the thread " Word arrays and EEPROM"

Alain

mister_e
- 26th February 2005, 00:15
3 things:

your Array size must be 10 instead of 9
for to next loop=o or loop=0 ?
you didn't set your TRIS register. TRISC=0 : TRISA=0


BUT i don't know if you can address i/o in array... :(

Darrel Taylor
- 5th March 2005, 02:20
Hi John,

There's no way to do that with standard PBP commands. Normal PBP arrays must be completely contiguous. However, we can create a new command with a little assembly language.

This isn't exactly what you were looking for, but it does accomplish the exact same thing.

Put this code near the top of your program.
'------[ PortOut macro ]----------------
Temp_idx VAR byte
Temp_State VAR BIT

ASM
PortOut macro idx, state
MOVE?BB idx, _Temp_idx
MOVE?CT state, _Temp_State
EndASM
if Temp_idx < 5 then
PORTA.0[Temp_idx] = Temp_State
else
Temp_idx = Temp_idx - 5
PORTC.0[Temp_idx] = Temp_State
endif
@ endm
'---------------------------------------Then you can simply do this...
for x = 0 to 9
@ PortOut _X, 1
next x
With this code, the state("1" in this case) must be a constant. I did it that way just to be consistant with your request.

If you wanted to use a variable instead, simply change this line in the PortOut routine...

MOVE?CT state, _Temp_State

-- changed to --

MOVE?TT state, _Temp_State

HTH,
&nbsp;&nbsp;&nbsp;Darrel