Previous in Forum: Is My Drive Recycled?   Next in Forum: Nokia 3110c
Close
Close
Close
43 comments
Rate Comments: Nested
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194

PicBasic Pro Code Problem

03/01/2008 11:38 PM

Hi Everyone,

MY PicBasicPro accepts the following code. (lights 8 LEDs in succession)

CLEAR

loop:
High PORTD.0 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low PORTD.0 ' Turn off LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds

High PORTD.1 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low PORTD.1 ' Turn off LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds

High PORTD.2 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low PORTD.2 ' Turn off LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds

High PORTD.3 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low PORTD.3 ' Turn off LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds

High PORTD.4 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low PORTD.4 ' Turn off LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds

High PORTD.5 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low PORTD.5 ' Turn off LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds

High PORTD.6 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low PORTD.6 ' Turn off LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds

High PORTD.7 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low PORTD.7 ' Turn off LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End

SO WHY DOESN'T THIS WORK?


CLEAR

i VAR byte
FOR i = 0 TO 7
High PORTD.i ' Turn on LED connected to PORTD.0
Pause 50 ' Delay for .5 seconds
Low PORTD.i ' Turn off LED connected to PORTD.0
Pause 50 ' Delay for .5 seconds
NEXT i

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru
Engineering Fields - Instrumentation Engineering - New Member Hobbies - Fishing - New Member

Join Date: Jan 2008
Location: Kazakhstan
Posts: 753
Good Answers: 8
#1

Re: PicBasic Pro Code Problem

03/02/2008 2:20 AM

I do not use Basic but program is simple. As I could understand compact written loop code with "For" does not work?

Of course there would be a problems with PicBasic software, btw have you got any diagnostic messages from compiler? Nevertheless try this:

For i=0 to 7 step=1 ' try to determine a step

....your code

NEXT 'do not place i

Maybe it does not need to place i there? I have not any idea what from are composed the different dialects of Basic and how they are working. So do not mind so seriously my suppositions .

Best regards.

Post Script. "i VAR byte" Is it declaration of variable? It's not clear for me concerning byte.

Register to Reply Score 1 for Off Topic
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#22
In reply to #1

Re: PicBasic Pro Code Problem

03/03/2008 6:31 PM

Hi caramba,

I am having a bit of trouble understanding what you are saying, but I very much appreciate you taking the time to answer my post. I think I've made the problem a little clearer in my posts #18 and #19, as well as indicate a plan of action.

I promise that I will come back and let you all know what I find out!

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#2

Re: PicBasic Pro Code Problem

03/02/2008 4:07 AM

Saying 'This doesn't work' isn't much help...and is poor reporting/observing of the facts.

What exactly does it do?
Does it initialise ok and light the first Leds...?

I'm not familiar with that particular coding... but my comment still holds good..always supply as much accurat information as possible.... for all we know you might not have a 5v supply!

Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Guru
Engineering Fields - Instrumentation Engineering - New Member Hobbies - Fishing - New Member

Join Date: Jan 2008
Location: Kazakhstan
Posts: 753
Good Answers: 8
#3
In reply to #2

Re: PicBasic Pro Code Problem

03/02/2008 4:28 AM

Good morning Del,

Seems you're a guru on duty this weekend .

I am not use Basic for coding as well but being taken to consideration how detailed was this post he'd done all properly and no one warning message appeared during flashing to PIC.. Simply no one LED turns on .


Though 5V is so plausible thing. I just made this mistake week ago (four PS one forgotten be turned on ) and spent a hour to fix it.

Register to Reply Off Topic (Score 5)
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#4
In reply to #3

Re: PicBasic Pro Code Problem

03/02/2008 4:33 AM

Hi there...
I'm just killing time (what a horrible expression?) before we go to my Mother in Laws for lunch..... .
It's a sunny day, I'd rather be gardening or 5 million other things....

Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply Off Topic (Score 5)
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#5
In reply to #2

Re: PicBasic Pro Code Problem

03/02/2008 7:30 AM

Yeah, Del. You're right. Let me try again. Each of these sections of code should do the same thing - light up (and turn off) 8 LEDs in succession and start over. Here is the first section of code which works fine:

<start>

CLEAR

loop:
High PORTD.0 ' Turn on LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds
Low PORTD.0 ' Turn off LED connected to PORTB.0
Pause 50 ' Delay for .5 seconds

High PORTD.1 ' Turn on LED connected to PORTB.1

Pause 50 ' Delay for .5 seconds
Low PORTD.1 ' Turn off LED connected to PORTB.1
Pause 50 ' Delay for .5 seconds

High PORTD.2 ' Turn on LED connected to PORTB.2
Pause 50 ' Delay for .5 seconds
Low PORTD.2 ' Turn off LED connected to PORTB.2
Pause 50 ' Delay for .5 seconds

High PORTD.3 ' Turn on LED connected to PORTB.3
Pause 50 ' Delay for .5 seconds
Low PORTD.3 ' Turn off LED connected to PORTB.3
Pause 50 ' Delay for .5 seconds

High PORTD.4 ' Turn on LED connected to PORTB.4
Pause 50 ' Delay for .5 seconds
Low PORTD.4 ' Turn off LED connected to PORTB.4
Pause 50 ' Delay for .5 seconds

High PORTD.5 ' Turn on LED connected to PORTB.5
Pause 50 ' Delay for .5 seconds
Low PORTD.5 ' Turn off LED connected to PORTB.5
Pause 50 ' Delay for .5 seconds

High PORTD.6 ' Turn on LED connected to PORTB.6
Pause 50 ' Delay for .5 seconds
Low PORTD.6 ' Turn off LED connected to PORTB.6
Pause 50 ' Delay for .5 seconds

High PORTD.7 ' Turn on LED connected to PORTB.7
Pause 50 ' Delay for .5 seconds
Low PORTD.7 ' Turn off LED connected to PORTB.7
Pause 50 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End

<stop>

Then I wanted to be able to condense the code by substituting the pin numbers (PORTD.0, PORTD.1) for an integer variable (PORTD.i) and using a FOR/NEXT. Below is the condensed code and it doesn't work. The compiler kicks it out on the line <High PORTD.i>.

<Start>
CLEAR

i VAR byte
FOR i = 0 TO 7
High PORTD.i 'Turn on LED connected to PORTD.i
Pause 50 ' Delay for .5 seconds
Low PORTD.i 'Turn off LED connected to PORTD.i
Pause 50 ' Delay for .5 seconds
NEXT i

<Stop>

With every Basic I've worked with, I have done this with no problem, so what gives?

(hope that's a little clearer)

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply Off Topic (Score 5)
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#6
In reply to #5

Re: PicBasic Pro Code Problem

03/02/2008 7:47 AM

I don't know this variety of Basic - it looks initially as if your for .. next version should work.

Does the manual indicate that "PORTD.i" is a valid construct? Could be that the "i" has to be a literal (an actual number), or has to be declared as an integer (rather than a byte type)? Just ideas ...

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply Off Topic (Score 5)
Guru

Join Date: Dec 2005
Location: Etats Unis
Posts: 1871
Good Answers: 45
#8
In reply to #5

Re: PicBasic Pro Code Problem

03/03/2008 12:33 AM

Are you controlling a Microchip part? Or any other part for that matter. Do you set the data direction of the port lines to OUTPUT at any point? Most microcontrollers power up with their pins in INPUT mode and you must explicitly set them as outputs.

__________________
The hardest thing to overcome, is not knowing that you don't know.
Register to Reply Off Topic (Score 5)
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#21
In reply to #8

Re: PicBasic Pro Code Problem

03/03/2008 6:22 PM

Hi rcapper,

It is a PIC16F877A. When given the command HIGH or LOW, the pin is automatically put in output mode. And yes, you are right; the default poweron direction for all the pins is Input.

Thanks for your input!

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply Off Topic (Score 5)
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#9
In reply to #5

Re: PicBasic Pro Code Problem

03/03/2008 3:14 AM

Another thing you could try:

<Start>
CLEAR

i VAR byte
FOR i = 0 TO 7
High PORTD.0 'Turn on LED connected to PORTD.0
Pause 50 ' Delay for .5 seconds
Low PORTD.0 'Turn off LED connected to PORTD.0
Pause 50 ' Delay for .5 seconds
NEXT i

<Stop>

That may narrow it down a bit.

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply Off Topic (Score 5)
Commentator

Join Date: Oct 2006
Location: Cape Town
Posts: 88
Good Answers: 1
#7

Re: PicBasic Pro Code Problem

03/03/2008 12:13 AM

Hi Mike,

Here is a forum likely to give you better info and answers on Pic Basic Pro problems

http://www.picbasic.co.uk/forum/

Register to Reply
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#20
In reply to #7

Re: PicBasic Pro Code Problem

03/03/2008 6:19 PM

Hi Neil,

Thanks for the the tip. I have been there before, but haven't posted this problem there. I think I'll talk to ME Labs tomorrow to find out the reason for it not working and a workaround, if possible. If they can't help me with a workaround, I'll go to the PICBasic forum and post what I need there.

Again, thanks Neil!

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Commentator

Join Date: Oct 2006
Location: Cape Town
Posts: 88
Good Answers: 1
#32
In reply to #20

Re: PicBasic Pro Code Problem

03/04/2008 1:13 AM

Hi Mike, have you looked at PBP manual from:

http://www.melabs.com/downloads/pbpm304.pdf

and then look at section 4.4 Aliases (page 22), which describes port pin naming, amongst other things

Regards, Neil

Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#10

Re: PicBasic Pro Code Problem

03/03/2008 3:15 AM

Hi,

If you are still having a problem, I'd sugest debugging it outside the loop...

e.g. Simplify.. try just.

i VAR byte
i=1 (or whatever the correct syntax is)
High PORTD.i ' Turn on LED connected to PORTD.0
Pause 50 ' Delay for .5 seconds
Low PORTD.i ' Turn off LED connected to PORTD.0
Pause 50 ' Delay for .5 seconds

This should narrow it down a bit...maybe it's just some peculiarity of the language/interpreter/assembler that maybe doesn't lke port allocations being variables or some thing weird like that.

When in doubt simplify, eventually you will boil it down to the actual line of code that doesn't work...then you can throw the rubber brick at the mointor.

Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Guru
Hobbies - HAM Radio - New Member

Join Date: Oct 2006
Location: Vancouver (not BC) Washington (not DC) US of A
Posts: 1261
Good Answers: 12
#11

Re: PicBasic Pro Code Problem

03/03/2008 4:46 AM

I suspect that "PORTD.0" describes a physical pin on the IC. (through "PORTD.7"). The compiler (assembler) doesn't recognize "PORTD.i" as it is not a physical location.

I suggest that you contact www.microchip.com . They can explain why it won't work, and also give you software ways around it.

Bill

Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#12
In reply to #11

Re: PicBasic Pro Code Problem

03/03/2008 7:17 AM

Yup..that's the sort of thing I was think of in the previous post.

__________________
health warning: These posts may contain traces of nut.
Register to Reply Off Topic (Score 5)
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#13
In reply to #12

Re: PicBasic Pro Code Problem

03/03/2008 8:03 AM

... and I in #6

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply Off Topic (Score 5)
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#14
In reply to #13

Re: PicBasic Pro Code Problem

03/03/2008 8:05 AM

Ok you said it first....

Let's hope he tells us what the actual answer turns out to be!

__________________
health warning: These posts may contain traces of nut.
Register to Reply Off Topic (Score 5)
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#15
In reply to #14

Re: PicBasic Pro Code Problem

03/03/2008 8:13 AM

Hear! Hear!

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply Off Topic (Score 5)
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#18
In reply to #15

Re: PicBasic Pro Code Problem

03/03/2008 6:10 PM

OK OK - sorry I haven't gotten back here sooner.

In your post #6, I suspect that it probably isn't a valid construct, but nowhere in the literature can I find anything explicitly confirming this. Thanks John!

Keep in mind (and I think I made it clearer in my post #5 reply to Del), that there are two sets of code here. They are both supposed to be identical in their functionality.

The first one explicitly & laboriously numbers and commands each pin for the firing of its associated LED. This section of code compiles and programs and runs on the PIC16F877A as expected.

It seemed to me that this code could be condensed using a variable for the pin number and doing a FOR/NEXT loop, which I've done in VB forever (seems like).

So, putting (only) the second section of code in, the compiler chokes when it comes to the "High PORTD.i" line.

That's why I suspect that John (#6), Del (#10) and Sciesis2 (#11) may be right about the physical port not being addressable by a variable.

There must be some way to condense that code though!

We had a trial today at work and I was busy all day, so I didn't have a chance to call MicroEngineering Labs. I'll talk to 'em tomorrow and come back here to let y'all know what I find out.

I appreciate all the help guys!

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply Off Topic (Score 5)
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#23
In reply to #18

Re: PicBasic Pro Code Problem

03/03/2008 6:41 PM

Hi, Mike,

This is the sort of thing we needed (as in some feedback!). I think most of us assumed that both your code examples compiled OK, but the loop version didn't flash the LEDs.

I agree that there must be a way around it. Does the compiler allow you to include chunks of in-line assembler? Or to add assembly code routines that you can call with parameters? If either of these is available (and nothing else works) - it could give you a work-around . But it might end up being target device specific .

Anyway, ta for the update & keep us posted. John.

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply Off Topic (Score 5)
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#24
In reply to #23

Re: PicBasic Pro Code Problem

03/03/2008 7:37 PM

Thanks John, will do!

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply Off Topic (Score 5)
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#33
In reply to #18

Re: PicBasic Pro Code Problem

03/04/2008 2:20 AM

There must be some way to condense that code though!

Ha this is an interesting point...
The shortest written code may not result in the fastest or shortest compiled code, or for that matter the most readable maintainable code.

My code is often interspersed with comments like .

; Repeat for each pump by brute force
or

; I know it's long winded but it works.

I think simplicity, reliability and maintainability are the key.
Del

(PS I wasn't having a go about lack of replies, just interested in the actual answer)

__________________
health warning: These posts may contain traces of nut.
Register to Reply Off Topic (Score 5)
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#34
In reply to #33

Re: PicBasic Pro Code Problem

03/04/2008 7:23 AM

Thanks Del - good point!

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply Off Topic (Score 5)
Active Contributor

Join Date: Aug 2007
Location: South Central Nebraska, USA
Posts: 17
#16

Re: PicBasic Pro Code Problem

03/03/2008 10:57 AM

I have questions about your post.

Is it a compiler error or the compiled code won't run in the PIC?

Are your LEDs installed with proper polarity?

Power supply is proper voltage and polarity?

The PIC is properly initialized in the code? As in device type, port DDR, etc. Variables are DIM ed properly as to word, byte or bit?

All of these little things can cause a non working program.

I don't mean to say you are inexperienced or demean your electronic and programming talents but, these little things have driven me over the edge more than once only to return to a project and find it was some little common thing I had over looked. I find my self asking myself "What were we thinking?"

Please, let us all know the result!

blueice

Register to Reply
Active Contributor

Join Date: Aug 2007
Location: South Central Nebraska, USA
Posts: 17
#17

Re: PicBasic Pro Code Problem

03/03/2008 11:08 AM

One other thing is to check your delays. If they are too short the LED will flash but too fast for the eye to see it.

Good hunting and stay frosty!

blueice

Register to Reply
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#19
In reply to #17

Re: PicBasic Pro Code Problem

03/03/2008 6:13 PM

Hi blueice,

Keep in mind (and I think I made it clearer in my post #5 reply to Del), that there are two sets of code here. They are both supposed to be identical in their functionality.

The first one explicitly & laboriously numbers and commands each pin for the firing of its associated LED. This section of code compiles and programs and runs on the PIC16F877A as expected.

It seemed to me that this code could be condensed using a variable for the pin number and doing a FOR/NEXT loop, which I've done in VB forever (seems like).

So, putting (only) the second section of code in, the compiler chokes when it comes to the "High PORTD.i" line.

That's why I suspect that John (#6), Del (#10) and Sciesis2 (#11) may be right about the physical port not being addressable by a variable.

There must be some way to condense that code though!

We had a trial today at work and I was busy all day, so I didn't have a chance to call MicroEngineering Labs. I'll talk to 'em tomorrow and come back here to let y'all know what I find out.

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#25

Re: PicBasic Pro Code Problem

03/03/2008 8:40 PM

Hi Everyone - this is an update. Below is an email I sent to MicroEngineering Labs on 3/3/2008 @ 8:30 EST. I'll post the response as soon as I get it.

Mike

Hello and Greetings,

I purchased PICBasic Pro and assembled all of the parts on the LAB-X1 PCB that I bought from you. The board seems to be working just fine. "Hello World" and "Blink" sample programs work as expected. I am very happy with my purchase.

I have coded the PIC16F887A chip to light the first 8 LEDs (in sequence, in a loop) of the LED bargraph on the LAB-X1 board. Using the HIGH and LOW commands (with pauses in between), and giving these commands for EACH PIN as follows:

loop:
High PORTD.0
Pause 50
Low PORTD.0
Pause 50

High PORTD.1
Pause 50
Low PORTD.1
Pause 50

High PORTD.2
Pause 50
Low PORTD.2
Pause 50

High PORTD.3
Pause 50
Low PORTD.3
Pause 50

High PORTD.4
Pause 50
Low PORTD.4
Pause 50

High PORTD.5
Pause 50
Low PORTD.5
Pause 50

High PORTD.6
Pause 50
Low PORTD.6
Pause 50

High PORTD.7
Pause 50
Low PORTD.7
Pause 50

Goto loop
End

This code compiles, programs, and executes just fine.

Yet when I try to substitute a variable for the pin number, the compiler chokes on the first line of code, giving the following error:

ERROR Line 20: Bad variable modifier: .i.

The code that generated this error is as follows:

i VAR BYTE
FOR i = 0 TO 7
High PORTD.i
'This is LINE 20
Pause 50
Low PORTD.i
Pause 50
NEXT i

Can you tell me why I get this error?

In the code that works, having to explicitly number each pin (and write the line of code that goes with it) seems rather laborious. There must be some way to condense the code. Is there another way to reduce the number of lines of code in a program where the same command on sequentially numbered pins (and looped) is required?

Mike Hogan

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#26
In reply to #25

Re: PicBasic Pro Code Problem

03/03/2008 8:43 PM

Oops, guess I'm not anonymoys anymore!

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#27
In reply to #26

Re: PicBasic Pro Code Problem

03/03/2008 8:44 PM

anonymous

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Guru
Engineering Fields - Instrumentation Engineering - New Member Hobbies - Fishing - New Member

Join Date: Jan 2008
Location: Kazakhstan
Posts: 753
Good Answers: 8
#28
In reply to #25

Re: PicBasic Pro Code Problem

03/03/2008 10:14 PM

It seems here is specific of PicBasic as said John, Del and others. The only way (if it possible in this version of Basic) to pre-create indexed array of LED states S[8]={"PORTD.0", "PORTD.1", "PORTD.2" ...."PORTD.7"}. Excuse me for some C++ notation as I treated Basic so long time ago. "PORTD.i" is string variable in C. It's remain up to you how you must treat variables in your ProBas program.

Once more else plausible way: Can you gather string variable somewhat like "PORTD."+"i"?

i from integer type should be converted to char type. Sorry for C approach again.

Best regards.

Car.

Register to Reply
Guru
Engineering Fields - Instrumentation Engineering - New Member Hobbies - Fishing - New Member

Join Date: Jan 2008
Location: Kazakhstan
Posts: 753
Good Answers: 8
#29
In reply to #25

Re: PicBasic Pro Code Problem

03/03/2008 10:47 PM

My last comment means PicBas has to eat construction like this

High S[i]

Pause 50....

hmm.. I'm not sure of that, though you can try it.

Regarding "bad variable modifier" it's just about that in your loop you declared i as integer type, but for command PORTD.i this i should be inserted as char variable (ASCII, for instance 1 in ASCII has code 31 for MSDOS). So you need to convert i to char(string) variable (for example ii) and then put it to your PORTD.ii variable.

If PORTD.I is unbreakable command --- nothing will help, though it looks like Structure.

Kind regards.

Register to Reply
Active Contributor

Join Date: Aug 2007
Location: South Central Nebraska, USA
Posts: 17
#35
In reply to #25

Re: PicBasic Pro Code Problem

03/04/2008 10:38 AM

Hi Mike,

The condensed version of your code seems as though it should work.

Still some "gotchas" here.

To set a pin or port to an output (or input), set its TRIS register. Setting a TRIS bit to 0 makes its pin an output. Setting a TRIS bit to 1 makes its pin an input. For example:

TRISA = %00000000 ' Or TRISA = 0

sets all the PORTA pins to outputs.

TRISB = %11111111 ' Or TRISB = 255

sets all the PORTB pins to inputs.

TRISB = %11111111 ' Or TRISB = 255

Have you set the TRIS register? Or is this just automatic when a port pin is set to 1 in Picbasic Pro?

There are certain variables that are reserved. Is there a conflict with "i"?

blueice

Register to Reply
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#36
In reply to #35

Re: PicBasic Pro Code Problem

03/04/2008 12:09 PM

Hi blueice,

Whenever you use the HIGH or LOW commands, the associated pin is set to an output automatically.

Thanks for the input though!

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Anonymous Poster
#30

Re: PicBasic Pro Code Problem

03/04/2008 12:18 AM

I assume you still have the "goto loop" else your "for" loop will only execute one time and end.


Good Luck

Register to Reply
Anonymous Poster
#31

Re: PicBasic Pro Code Problem

03/04/2008 12:31 AM

Try This!

i VAR BYTE
FOR i = 0 TO 7
High PORTD.0(i) 'This is LINE 20
Pause 50
Low PORTD.0(i)
Pause 50
NEXT i

Cheers!

Register to Reply
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#37

Re: PicBasic Pro Code Problem

03/05/2008 6:35 PM

OK Guys, here's the solution:

CLEAR

i VAR BYTE

TRISD = 0

PORTD = 0

FOR i = 0 TO 7

PORTD.0[i] = 1

Pause 50

PORTD.0[i] = 0

Pause 50

NEXT i

Thanks for all the effort at help with this problem. You guys are great! Now I just need to understand why this works.

MicroEngineering Labs was very quick to answer me; my appreciation (if anyone associated with MELabs ever reads this).

Kudos to all!

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#38
In reply to #37

Re: PicBasic Pro Code Problem

03/06/2008 2:43 AM

Now I just need to understand why this works.

Creationism....The chip/language creators just made it like that. It will save you having to worry.

__________________
health warning: These posts may contain traces of nut.
Register to Reply Off Topic (Score 5)
Anonymous Poster
#39

Re: PicBasic Pro Code Problem

04/02/2008 1:41 AM

I think you forgot to set PORTD for output:

PORTD=0

Register to Reply
Anonymous Poster
#40

Re: PicBasic Pro Code Problem

04/02/2008 1:46 AM

I think you forgot to set PORTD for output:

TRISD=0 REM Set PORTD for output

Sorry about the mistake (PORTD=0) posted earlier.

Register to Reply
Guru
Hobbies - Musician - Engineering Fields - Chemical Engineering - New Member Engineering Fields - Control Engineering - New Member Engineering Fields - Instrumentation Engineering - New Member

Join Date: Jan 2007
Location: Moses Lake, WA, USA, Thulcandra - The Silent Planet (C.S. Lewis)
Posts: 4216
Good Answers: 194
#41
In reply to #40

Re: PicBasic Pro Code Problem

04/02/2008 8:11 AM

Dear guest,

Please read posts #36 and #37. As I mentioned in post #36, the commands HIGH and LOW AUTOMATICALLY make the designated pin an output.

I show the solution in post #37.

You really should read the entire thread before posting replies.

Mike

__________________
"Reason is not automatic. Those who deny it cannot be conquered by it. Do not count on them. Leave them alone." - Ayn Rand
Register to Reply
Anonymous Poster
#42

Re: PicBasic Pro Code Problem

02/14/2010 12:21 PM

Hey Mike in this message (below) you posted some time ago did you get a reason why you cannot index a variable assigned as an LED? Hi Everyone, MY PicBasicPro accepts the following code. (lights 8 LEDs in succession) CLEAR loop: High PORTD.0 ' Turn on LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds Low PORTD.0 ' Turn off LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds High PORTD.1 ' Turn on LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds Low PORTD.1 ' Turn off LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds High PORTD.2 ' Turn on LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds Low PORTD.2 ' Turn off LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds High PORTD.3 ' Turn on LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds Low PORTD.3 ' Turn off LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds High PORTD.4 ' Turn on LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds Low PORTD.4 ' Turn off LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds High PORTD.5 ' Turn on LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds Low PORTD.5 ' Turn off LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds High PORTD.6 ' Turn on LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds Low PORTD.6 ' Turn off LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds High PORTD.7 ' Turn on LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds Low PORTD.7 ' Turn off LED connected to PORTB.0 Pause 50 ' Delay for .5 seconds Goto loop ' Go back to loop and blink LED forever End SO WHY DOESN'T THIS WORK? CLEAR i VAR byte FOR i = 0 TO 7 High PORTD.i ' Turn on LED connected to PORTD.0 Pause 50 ' Delay for .5 seconds Low PORTD.i ' Turn off LED connected to PORTD.0 Pause 50 ' Delay for .5 seconds NEXT i Mike

Register to Reply
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#43
In reply to #42

Re: PicBasic Pro Code Problem

02/14/2010 6:51 PM

Hey, Guest,

You may or may not have a useful contribution or valid question here, but nobody can work it out!

Did you look at the preview before posting? I suggest you do (or pay more attention) next time.

Please re-format & re-post.

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply
Register to Reply 43 comments
Copy to Clipboard

Users who posted comments:

Anonymous Poster (5); blueice (3); caramba (4); JohnDG (6); Mikerho (14); NeilJ (2); rcapper (1); Sciesis2 (1); user-deleted-1105 (7)

Previous in Forum: Is My Drive Recycled?   Next in Forum: Nokia 3110c

Advertisement