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.

Whats wrong with my code ???

Status
Not open for further replies.

pike

Member
hey guys,

I tried making a binary counter to learn how to write and program PIC's a few weeks ago. I'm using PIC Basic Plus to compile these codes. Unsuccesful, I left it alone for a little while to cool down my temper...

Now that i've come back to give it another go, i'm still stuck!!! This is my code:

Initial:
poke trisb, 0 'set port b to output
poke portb, 0 'turn off all connected leds
Bincount:
for b0 = 0 to 255
poke portb, b0 'write the value of b0 into the register
next b0 'increase the value by 1
goto bincount 'keep repeating
end

The problem is that it won't let me compile the code it says:

Error at Line [7] In file [test.bas] *** Misplaced or Incorrect 'NEXT' command! ***

Whats wrong with the code???
 
Yeah, the code was constructed correctly and yeah i have tried writing a value of 0 into b0.

This is REALLY starting to get me frustrated-If only i decided to take the assembly language course... :evil:
 
Have you declared the variable b0?
e.g.
Code:
Dim b0 as byte
 
Before using any variable you have to explicitely define it or in simple words - notify the compiler that you are using a variable named xxx & what type of variable it is.
Some of the variable data types are
Byte - (8-bit) - Range: 0-255 or -128 to +127
Integer- (16-bit) - Range : 0 to 65536 or -32768 to +32767
Long (long integer) 4 bytes -2,147,483,648 to 2,147,483,647
Single (single-precision floating-point) 4 bytes -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values
etc.

Depending upon type a variable will use that much amount of RAM in your uC. Never use large data types unless needed.
 
is it possible to declare mutiple variables in one command ??

e.g.
Code:
Dim b0,b1,b2,b3 as byte

or do i have to do it separately to every variable??
 
Code:
Dim b0,b1,b2,b3 as byte
Accoding to Visual Basic if you declare variables like this, only b3 will be considered as byte. Rest all variables will be declared as variant data types which can accespt just anything you can think of and uses quite good amount of RAM. I don't know how PICBASIC treats this statement.
To be on the safer side and declare all variables as byte, use statements like this
Code:
Dim b0 as byte, b1 as byte, b2 as byte, b3 as byte
 
You have to declare each variable seperate..... and use a DIM statement wit each one in PICBASIC PRO... I am not sure what PICBASIC PLUS is like :?

dog var byte
cat var bit
w0 var word

Also in PBP you can address the registers instead of having to use the poke command... so for poke trisb, 0 you would do

TRISB = 0

Ivancho
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top