Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

dimension arrays in Swordfish

Status
Not open for further replies.
Forgive me. I'm a little slow being on pain meds and sleep-deprived after my knee replacement surgey! I should have recognized a certain style!
 
BOY post #17 looks confusing at best. Talk about going from A to B via C, D and F
The CASE SELECT is way less confusing.
I am going to take a second look at Mikes solution as I have some time today being Sunday.
I agree with Jons statement in post #18
 
I'm not sure how IF THEN can be confusing, but if you like SELECT then how about this:
Code:
dim LED1 as PORTD.1,
    LED2 as PORTD.0,
    LED3 as PORTC.3,
    LED4 as PORTC.2,
    LED5 as PORTC.1
    // add more leds here       

public sub set_led(ledno as byte, setting as bit)
    select (ledno)
        case 1
            LED1 = setting
        case 2
            LED2 = setting
        case 3
            LED3 = setting
        case 4
            LED4 = setting
        case 5
            LED5 = setting
        // add more leds here       
    end select
end sub

public sub toggle_led(ledno as byte)
    select (ledno)
        case 1
            toggle(LED1)
        case 2
            toggle(LED2)
        case 3
            toggle(LED3)
        case 4
            toggle(LED4)
        case 5
            toggle(LED5)
        // add more leds here       
    end select
end sub

It compiles to exactly the same code as post #17.

The problem is that with the PIC there's no such thing as a 'pointer to a bit'... the hardware just doesn't support it (bit instructions have the bit number hard-coded into the asm instruction). Some languages may try to fool you into thinking there is, but if you take a look at all the gyrations it tries to go through behind the scenes you may have second thoughts.
 
Funny huh PortA is 00000000 so you change it with a 10000000 or a <<1 7times
 
I looked and tried out tumbleweeds and Mikes solution but ended up going with a long but easily readable solution
SUB Prg_1()
Ch_1 = 1
Ch_2 = 0
Ch_3 = 1
Ch_4 = 0
Ch_5 = 1
Ch_6 = 0
Ch_7 = 1
Ch_8 = 0
Ch_9 = 1
Ch_10 = 0
Ch_11 = 1
Ch_12 = 0
Ch_13 = 1
Ch_14 = 0
Ch_15 = 1
Ch_16 = 0
Ch_17= 1
Ch_18= 0
Ch_19= 1
Ch_20= 0
DELAYMS(speed)
Ch_1 = 0
Ch_2 = 1

yes it is the long way around BUT one must remember that I need 20 port pins for Led outputs. The 40 pin dip pic does not have consecutive pins on the same ports except portB. I needed two sets of 10 pins on each end of the pcboard making the layout clean and easy to de bug if needed, thus going in a clockwise rotation I have PortB.0-7 then PortD.7 - 6, then portC.5 & 4 then portD.3 -2 etc.
So using a shift bit would add to the jumble of code thus I decided to go long hand and use a simple CASE SELECT .
Using consecutive port pins sometimes adds to pcboard design issues. Using PORTB.BITS(x) is the easy method to cycle through a port but sometimes board design gets in the way.
 
You're really a troll aren't you? No one can spend 10 years trying to code and not learn anything.

I, for the second time, will ignore you forever more. Somehow, you drew me in again.

Bye.

Mike.
 
I have tried your suggestion so why get Po'ed if I don't use it??
I tried it and it works well but not for what I am doing. If I didn't have to use so many different ports then yes. your example works well.
As for learning, yes I have learned alot from examples.
As I mentioned before, I take a code example, deconstruct it to see what makes it work then I learn from that.
It's the learn by doing
 
You're really a troll aren't you? No one can spend 10 years trying to code and not learn anything.

I, for the second time, will ignore you forever more. Somehow, you drew me in again.

Bye.

Mike.

I should learn from your example. It's hard not to get sucked in.
 
I have tried your suggestion so why get Po'ed if I don't use it??
I tried it and it works well but not for what I am doing. If I didn't have to use so many different ports then yes. your example works well.
As for learning, yes I have learned alot from examples.
As I mentioned before, I take a code example, deconstruct it to see what makes it work then I learn from that.
It's the learn by doing
Learn by doing!!! You have been posting here for 10 years!!!! I really find it hard to believe, but it appears to be true, that you have learnt absolutely nothing in this time. People spend the time and give you solutions to your problem and you completely ignore it. Instead you find some other ludicrous thing to post. I can only conclude that you must be trolling.

Mike.
 
My interpretation in Mikes example is shifting port bits.
Will take another look and try again.Not saying it is right or wrong but t looks convoluted compared to tumbleweeds example
 
MrDEB has a unique ability to pick out some words that seem to support what he wants to see, while completely missing the point of a post.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top