PDA

View Full Version : Newbie Problem



djh82uk
- 13th July 2006, 15:53
Ok I have done a little programming with Jal, and I want to use Picbasic so I am trying the lite edition.

I want to generate a random number 1-10 and use it to switch on one of 10 corresponding led's.

Can someone tell me where i am going wrong? When i try to compile I get and error "list index out of bounds (1)".

Here is my code so far also.



'
' PIC Defines
' -----------
@ DEVICE pic16F628a, INTRC_OSC
' System Clock Options
@ DEVICE pic16F628a, WDT_OFF
' Watchdog Timer
@ DEVICE pic16F628a, PWRT_ON
' Power-On Timer
@ DEVICE pic16F628a, BOD_OFF
' Brown-Out Detect
@ DEVICE pic16F628a, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F628a, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic16F628a, PROTECT_OFF
' Program Code Protection
@ DEVICE pic16F628a, WRT_OFF
' Flash Memory Word Enable
@ DEVICE pic16F628a, DEBUG_OFF
' Debug

'
' Hardware Defines
' ----------------
LED1 var PortB.0
LED2 var PortB.1
LED3 var PortB.2
LED4 var PortB.3
LED5 var PortB.4
LED6 var PortB.5
LED7 var PortB.6
LED8 var PortB.7
LED9 var Porta.1
LED10 var Porta.2


'
' Initialse Hardware
' ------------------
PORTB=0
TRISB=0
PORTA=0
TRISA=0

'
' Main Program Loop
' -----------------


RandomValue var Word
Dice var Byte


RandomValue var 9876

Loop:
Random RandomValue ' Generate Random Value
Dice=(RandomValue//10)+1 ' Convert it to range 1-10
Pause 75 ' Debounce Delay for Button


If LED1 = 1 Then
Low LED1
Pause 5000
ELSE

If LED2 = 2 Then
Low LED2
Pause 5000
ELSE

If LED3 = 3 Then
Low LED3
Pause 5000
ELSE

If LED4 = 4 Then
Low LED4
Pause 5000
ELSE

If LED5 = 5 Then
Low LED5
Pause 5000
ELSE

If LED6 = 6 Then
Low LED6
Pause 5000
ELSE

If LED7 = 7 Then
Low LED7
Pause 5000
ELSE

If LED8 = 8 Then
Low LED8
Pause 5000
ELSE

If LED9 = 9 Then
Low LED9
Pause 5000
ELSE

If LED10 = 10 Then
Low LED10
Pause 5000
ELSE


GoTo Loop ' Do it again




This is the first time I have played with picbasic, so my code is most probably very wrong, but will help me to learn, please bear in mind that I am not super-intelligent

Regards

DJH

dhouston
- 13th July 2006, 16:12
If you are using PBC then PBP code will not work.

djh82uk
- 13th July 2006, 16:24
ok, so what do I need to change in the code to make it compile with the lite download of PDS?

Or is it all wrong?

DJH

paul borgmeier
- 13th July 2006, 16:43
You are on the wrong forum (MELabs Pic Basic) - please try this one (Proton Development Suite)

http://www.picbasic.org/forum/

Good Luck,

Paul Borgmeier
Salt Lake City, Utah
USA