So simple but it don't work


Closed Thread
Results 1 to 2 of 2
  1. #1
    malc-c's Avatar
    malc-c Guest

    Default So simple but it don't work

    Guys, I've been pulling my hair out all afternoon to get this working. All I'm trying to do is read a pin, if its low then goto one section. That section then contains the same line to check if the same pin is low and if so jump back to main.

    Here's the complete code

    Code:
    ;*************** Set up LCD *****************
    
    DEFINE LCD_DREG PORTC                           ' LCD data port 
    DEFINE LCD_DBIT 0                               ' LCD data starting bit 0 or 4 
    DEFINE LCD_RSREG PORTC                          ' LCD register select port 
    DEFINE LCD_RSBIT 4                              ' LCD register select bit 
    DEFINE LCD_EREG PORTC                           ' LCD enable port 
    DEFINE LCD_EBIT 5                               ' LCD enable bit 
    DEFINE LCD_BITS 4                               ' LCD bus size 4 or 8 
    DEFINE LCD_LINES 2                              ' Number lines on LCD 
    DEFINE LCD_COMMANDUS 2000                       ' Command delay time in us 
    DEFINE LCD_DATAUS 50                            ' Data delay time in us
    
    ;************* set up pattern data **********
        
    Patt1 DATA 16,1,2,4,8,16,32,64,128,128,64,32,16,8,4,2,1 
    Patt2 DATA 8,129,66,36,24,24,36,66,129 
    Patt3 DATA 16,1,3,2,6,4,12,8,24,16,48,32,96,64,192,128,0 
    Patt4 DATA 16,1,128,2,64,4,32,8,16,8,32,4,64,2,128,1,0 
    Patt5 DATA 12,24,60,126,255,231,195,129,0,129,195,231,255 
    Patt6 DATA 13,1,2,4,8,17,34,68,136,16,32,64,128,0 
    Patt7 DATA 8,128,64,32,16,8,4,2,1
    
    ;************* set up PIC ********************
    
    ADCON1=$07                                      ' PORTA all disgital
    CMCON = 7                                       ' Digital inputs
    CCP1CON = 0                                     ' PWM off
    TRISA=%11111111                                 ' set PORTA as all input 
    TRISB=%00000000                                 ' set PORTB as all output
    TRISC=%00000000                                 ' set PORTC as all output
    PORTB=0
    
    audio var PORTA.0                               ;input from beat filter (+5v)
    option var PORTA.2                              ;music or chase option select
    sequence var PORTA.3                            ;pattern selection
    
    ;************* set up variables ***************
    
    Patt    var byte [8]                            ;used to store the sequences
    Patt[1]=Patt1
    Patt[2]=Patt2
    Patt[3]=Patt3
    Patt[4]=Patt4
    Patt[5]=Patt5
    Patt[6]=Patt6
    Patt[7]=Patt7
    
    C var byte                                      ;used to advance through pattern
    D var byte                                      ;used for the speed the sequence runs at
    scale var byte                                  ;used in the POT command
    Scale = 254                                     ;used to provide ragge with pot command
    steps var byte                                  ;used for storing the number of steps in a sequence
    swcount var byte                                ;used to select the required sequence required
    swcount=4                                       ;set default sequence at start
    sel var byte                                    ;used to select music or chase
    sel=0                                           ;used to select mode 
    
    ;**************** main program ********************
    main:
    
    Pot PORTA.4,scale,D                             ;used to read value from 10k pot and set the speed
    
    if sequence=0 then swcount=swcount+1            ;check to see if up button pressed, if so add 1 to SWcount
    pause 60                                        ;debounce delay
    If swcount>7 then swcount=1                     ;error trap for exceeding max patterns                      
    
    if swcount=1 then LCDOUT $FE, 1, "Pattern 1"    'Clear display and show sequence number
    if swcount=2 then LCDOUT $FE, 1, "Pattern 2"
    if swcount=3 then LCDOUT $FE, 1, "Pattern 3"
    if swcount=4 then LCDOUT $FE, 1, "Pattern 4"
    if swcount=5 then LCDOUT $FE, 1, "Pattern 5"
    if swcount=6 then LCDOUT $FE, 1, "Pattern 6"
    if swcount=7 then LCDOUT $FE, 1, "Pattern 7"
    LCDOUT $FE,$C0, "Chase Speed " ,#D	             'Jump to second line and show speed
    
    
    if PORTA.2=0 then goto music
    pause 60
    
    read patt[swcount],steps                        ;read the first value of the selected patter and place it in the variable steps
    for C = 1 to steps                              ;for / next loop
    READ PATT[SWCOUNT]+ C,PORTB                     ;reads the step value for selected pattern and send it to PORTB 
    PAUSE D                                         ;delay for speed
    NEXT                                            ;advance through pattern
    goto main:                                      ;go to start of main program
    
    music:
    
    if PORTA.2 = 0 then goto main                   ;if A2 is low then goto main
    pause 60                                        ;debounce delay
    
    LCDOUT $FE,$C0, "Music Selected " 	            ;show that music has been selecterd
    
    read patt[swcount],steps                        ;read the first value of the selected patter and place it in the variable steps
    READ PATT[SWCOUNT]+ C,PORTB                     ;reads the step value for selected pattern and send it to PORTB 
    If audio=1 then C=C+1                           ;if pin is high a beat is present, so advance pattern
    If C=steps then C=1                             ;check to see if end of the patetrn is reached
    goto music:                                     ;go back to music and start again
    I've tried
    Code:
    branch sel,[music,main]
    I've also tried
    Code:
    if option=0 then sel = sel + 1
    if sel = 1 then goto music
    if sel = 2 then goto main
    if sel>2 then sel =0
    But no mater what I try the program won't jump to the music section. If I press and hold the button down (thus grounding the pin) the program seems to halt at the end of what ever pattern is selected, and the LCD displays rapid values for the speed.

    The hardware checks out and PORTA.2 is indeed being pulled low when the button is pressed (10k pull up holds it at +5v).

    I'm sure its something really obvious that I've overlooked.. but at the moment I just can't see why it shouldn't jump to each section when the button is pressed...
    Last edited by malc-c; - 1st January 2007 at 19:48.

  2. #2
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Exclamation

    at the beginning of the "music:"-section, porta.2 is checking for zero, so the program jumps immediate to "main:", if it ever reaches "music:".
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

Similar Threads

  1. Simple RF remote control code
    By Bruce in forum Code Examples
    Replies: 13
    Last Post: - 22nd January 2014, 10:45
  2. Simple Blinking LED - WTF!!
    By johnnylynx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2010, 06:19
  3. Simple Blink program doesnt work.
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 1st March 2009, 20:30
  4. Simple "backround" timer
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th November 2005, 05:11
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

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