Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 20th December 2003, 02:46 AM   (permalink)
Default Whats wrong with my code ???

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???
__________________
www.winpicprog.co.uk - Great PIC language tutorials.
pike is offline  
Old 20th December 2003, 10:59 PM   (permalink)
Default

Is your Bincount loop constructed corectlly ?
natbit is offline  
Old 21st December 2003, 11:15 AM   (permalink)
Default

I believe you have to initialize your variable(b0) to 0 first.
__________________
Eric.
Eclipsed is offline  
Old 21st December 2003, 12:33 PM   (permalink)
Default

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:
__________________
www.winpicprog.co.uk - Great PIC language tutorials.
pike is offline  
Old 21st December 2003, 12:39 PM   (permalink)
Default

Have you declared the variable b0?
e.g.
Code:
Dim b0 as byte
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline  
Old 21st December 2003, 12:44 PM   (permalink)
Default

hey, thank you very much kinjalgp. It worked!!!

But what does this command do ???
__________________
www.winpicprog.co.uk - Great PIC language tutorials.
pike is offline  
Old 21st December 2003, 01:05 PM   (permalink)
Default

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.
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline  
Old 21st December 2003, 01:17 PM   (permalink)
Default

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??
__________________
www.winpicprog.co.uk - Great PIC language tutorials.
pike is offline  
Old 21st December 2003, 03:43 PM   (permalink)
Default

Quote:
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
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline  
Old 22nd December 2003, 03:51 PM   (permalink)
Default

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
ivancho is offline  
Old 23rd December 2003, 12:58 AM   (permalink)
Default

Thanks for your help guys !!!
__________________
www.winpicprog.co.uk - Great PIC language tutorials.
pike is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 03:49 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker