Newbie Problem


Closed Thread
Results 1 to 4 of 4

Thread: Newbie Problem

Hybrid View

  1. #1
    djh82uk's Avatar
    djh82uk Guest

    Default Newbie Problem

    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
    Last edited by djh82uk; - 13th July 2006 at 15:00.

  2. #2
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    If you are using PBC then PBP code will not work.

  3. #3
    djh82uk's Avatar
    djh82uk Guest


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    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

Similar Threads

  1. Newbie? Problem with LCD
    By lew247 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th December 2009, 19:48
  2. power problem (newbie here!)
    By clocks in forum General
    Replies: 10
    Last Post: - 2nd May 2009, 13:18
  3. Newbie problem :)
    By sokrad in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 10:34
  4. Newbie with LAB X1 timming problem
    By schlaray in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th November 2006, 00:30
  5. Replies: 2
    Last Post: - 13th September 2005, 18:23

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts