PDA

View Full Version : noobie to PICs and PBPro... Programming question.



mcphill
- 24th October 2007, 22:03
I am trying to use an array to achieve an end goal. If I use binary only for ports a, b, c, my program does what I want. However, it should work with this code as well:

'Initialize



porta = %00000000
portb = %00000000
portc = %00000000

TRISA = %11111000
TRISB = %10001111
TRISC = %11111000

x var byte
y var byte
led var bit[9]

x=30
y=x*2

porta.2 = led[1]
porta.1 = led[2]
porta.0 = led[3]
portb.4 = led[4]

Main:

high led[1]
pause 300
low led[1]
pause 300

high led[2]
pause 300
low led[2]
pause 300

high led[3]
pause 300
low led[3]
pause 300

high led[4]
pause 300
low led[4]
pause 300

goto main

What am I doing wrong that it doesn't work? What I am trying to do is use an array to designate specific bit in the output. The bits are not sequential - the array would effective "rearrange" them. What am I doing wrong, or will this simply not work?

paul borgmeier
- 25th October 2007, 03:03
>>high led[1]

led[1] is a bit which means that it can be either 1 or 0 (led[8] also can be only 1 or 0 so it does the same thing). When led[1] is used with High command this equates to

High 0 ' RB0 = 1 (if led[1] = 0)
or
High 1 ' RB1 = 1 (if led[1] = 1)

no matter what element from your LED array you use, they all are either 0 or 1, which means they only change RB0 or RB1. Further, you have RB0 and RB1 set as inputs so i am sure you are not seeing outputs. You also have not initialized the values of led[X] so you do not know if they are 1's or 0's.

This thread might help you do what you want (after you blink a few LEDs first using variables and values):

http://www.picbasic.co.uk/forum/showthread.php?t=4074

mcphill
- 25th October 2007, 19:02
OK, I think I follow your points, but the suggestions are no along the lines I wanted to go. Let me restate the question this way...

I have 8 I/O pins that are NOT in succession.

I want to assign names to the pins. I want those names to be an array, so I can cycle through them in succession in a loop. By assigning the bits to the array name, I should be able to rearrange them logically to fit my physical setup.

Is that achievable in PBPro, and if so, what do I need to do so?

I attempted to do this by creating the array led[x]. I then defined each bit of led[x] to a specific I/O pin (porta.2 = led[1]) I have also tried this with led[1] var porta.2, and that did not work either. It does work if I do NOT use an array ( led1 var porta.2 ), but then I can't use the name led1 in a loop, cycling from led1 to led9...

Is that question more clear?

paul borgmeier
- 25th October 2007, 19:35
mcphill,

I understand your question and the link I provided is the key. In post 7 of that link I show how to, in a loop blink three port pins in succession - RB6, RC4, and RD2. The order and pin can easily be changed. Further, Ingvar, Bruce, Darrel, and others show other ways to do this. Study post 1 from that thread and make sure you understand what the OP requested. Then see post 7 and beyond for the answer. If you still need more explanation, I will have some time tonight to re-reply.

Good Luck