![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| Is your Bincount loop constructed corectlly ? | |
| |
| | (permalink) |
| I believe you have to initialize your variable(b0) to 0 first.
__________________ Eric. | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| Have you declared the variable b0? e.g. Code: Dim b0 as byte
__________________ "There is no way to peace, peace is the way!" | |
| |
| | (permalink) |
| hey, thank you very much kinjalgp. It worked!!! But what does this command do ???
__________________ www.winpicprog.co.uk - Great PIC language tutorials. | |
| |
| | (permalink) |
| 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!" | |
| |
| | (permalink) |
| is it possible to declare mutiple variables in one command ?? e.g. Code: Dim b0,b1,b2,b3 as byte
__________________ www.winpicprog.co.uk - Great PIC language tutorials. | |
| |
| | (permalink) | |
| Quote:
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!" | ||
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| Thanks for your help guys !!!
__________________ www.winpicprog.co.uk - Great PIC language tutorials. | |
| |