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.

Using Identifiers for pins in PicBasic Pro

Status
Not open for further replies.

Flamer1

New Member
With PBP, are you not allowed to use identifiers as pins? Such as
this code to turn on all LED's on PORTB in succession, pause, then
turn all off

TRISB = 0

N var byte

for N = 0 to 7
PORTB.N = 1
Next N

Pause 10
PORTB = 0
 
I don't know if picbasic accepts this code or not, but if you run it like that you wont see the leds do anything. They will light and go out before you even notice...

anyway, if picbasic does accept this code it will be inefficient anyway. Try shifting the bits in port B for better code.

loke this
TRISB = 0

N var byte

PORTB = 1 'light the first led
for N = 0 to 7
'if you want to see it all happen , put a pause here (pause 500 for half a sec)
PORTB = PORTB << 1 'shift the bits in portB left
Next N

Pause 10
PORTB = 0
 
i understand what you mean by the LED's lighting too fast then turning off. it was just an example i made up, the important part is using the variable N for a pin number.
 
If N=1 then your program will write %00000010 to portb.Or if N=2 Portb = %00000100, etc.Wouldn't just putting n into portb(portb=n) have the same result?
 
I think picbasic does'nt accept this because it also isn't possible on the hardware (assembly level)

the assembly command to set a bit
BSF PORTB, bit
requires a constant for 'bit'

As i said, it is a better choice to just shift the bits with
PORTB = PORTB << 1

this can be compiled into a single assembly instruction
 
To anser your question NO :?
Those identifiers can't work like that bummer. I wanted to do that but that doesn't work.
Depending on what you want to do you ca work around that.

Like in your example you would be better off writting the number to the Port, and then incrementing the a counter variable. In other cases you may want to define arrays and modify those identifiers..... 8)

Good Luck

Ivancho
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top