Data tables again !


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default A Big thankyou

    Guys what can I say but Thanks Bigtime

    I did type out a long post detailing what I had done and that the only reason Steves code failed was down to my human error ! I compiled it again and it worked fine. However the post didn't appear (probably human error again - as its been a long day and I'm knackered !). Anyway I've now moved on since that intended post... so maybe it was just as well I closed the browser before posting !!

    Bruce, I took your example code and it worked a treat. I've therefore edited out all the "work in progress" and included the full data tables and have a nice tight bit of code which works... more or less !

    Here's the code.

    Code:
    PORTA = 0 ' declare port level BEFORE port direction = safe power-on
    CMCON = 7 ' PortA Digital inputs
    CCP1CON = 0 ' PWM off
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 =    0
    
    TRISA=%11100011        'set PORTA as all input apart from A2,A3 & A4
    TRISB=%00000000        'set PORTB as all output
    
    DATA @1,word 625,0,word 545,word 750 ' pre-setting EEPROM
    
    @RC_OSC_NOCLKOUT 
    @WDT_ON
    @PWRT_ON
    @MCLR_OFF
    @BOD_ON
    @LVP_OFF
    @CPD_OFF
    @PROTECT_OFF
    
    ;set up pattern data
        
    Patt1 DATA 17,16,1,2,4,8,16,32,64,128,128,64,32,16,8,4,2,1 
    Patt2 DATA 9,8,129,66,36,24,24,36,66,129 
    Patt3 DATA 17,16,1,3,2,6,4,12,8,24,16,48,32,96,64,192,128,0 
    Patt4 DATA 17,16,1,128,2,64,4,32,8,16,8,32,4,64,2,128,1,0 
    Patt5 DATA 13,12,24,60,126,255,231,195,129,0,129,195,231,255 
    Patt6 DATA 14,13,1,2,4,8,17,34,68,136,16,32,64,128,0 
    Patt7 DATA 9,8,128,64,32,16,8,4,2,1
    
    ;set up varibles
        
    i var byte                          ;used for for next loops
    D var byte                          ;used to store the result of the pot on port A1
    scale var byte                      ;used in the POT command
    Scale = 254                         ;used to set range 
    SW1 var PORTA.6                     ;up switch 
    SW2 var PORTA.0                     ;down switch
    SWcount var byte                    ;used as a place holder for patterns
    swcount=1                           ;set place holder to default to pattern 1
    
    steps VAR BYTE                      ;used to store the number of steps in the pattern sequence
    counts VAR BYTE                     ;used in the FOR NEXT loop to run through the sequence
                                                                
    ;main program
    
    Main:
    Pot PORTA.1,scale,D                 ;used to read value from 10k pot
    if sw1=0 then swcount=swcount+1     ;check to see if up button pressed, if so add 1 to SWcount
    if sw2=0 then swcount=swcount-1     ;check to see if down button pressed if so delete 1 to SWcount
    pause 60                            ;debounce delay
    If swcount>4 then swcount=4         ;error trap for exceeding max patterns
    If SWcount<1 then swcount=1         ;error trap for exceeding min patterns
    
    TRISB = 0                           
    READ Patt1, steps                   ;get number of EEPROM entries
    FOR counts = 1 TO steps             ;advance to through the entries
    READ (Patt1+counts), PORTB          ;read the next entry and send the result to PORTB
    PAUSE D                             ;pause period set by varible D
    NEXT counts                         ;advance through loop to next position
    goto main:                          ;go back to the main program and run again
        
    END
    When this is compiled I was expecting the PIC to run through just the first pattern in the sequence (Patt1). But the instead it cycles in a loop through all 7 sequences and then lights all LEDS on portB for a short period (about the same as that set by D ) and then repeats over and over.

    I also need to come up with a means of using SWcount to select the pattern sequence contained in the read statement (rather than repeating the READ statement for every pattern), however I'm not sure how to have a varible select a lable...

    Other than that.. I want to thank you guys for showing me the way, and improving my understanding of PBP

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c

    I also need to come up with a means of using SWcount to select the pattern sequence contained in the read statement (rather than repeating the READ statement for every pattern), however I'm not sure how to have a varible select a lable...
    Well its amazing what a cup of coffee can do ;-)

    I came up with the following which works. Ok it might not be the best way, or the neatest.. but it worked !!

    Code:
    ;main program
    
    Main:
    Pot PORTA.1,scale,D                 ;used to read value from 10k pot
    if sw1=0 then swcount=swcount+1     ;check to see if up button pressed, if so add 1 to SWcount
    if sw2=0 then swcount=swcount-1     ;check to see if down button pressed if so delete 1 to SWcount
    pause 60                            ;debounce delay
    If swcount>7 then swcount=7         ;error trap for exceeding max patterns
    If SWcount<1 then swcount=1         ;error trap for exceeding min patterns
    
    TRISB = 0                           
    gosub sel1                          ;go to subroutine to select pattern
    FOR counts = 1 TO steps             ;advance to through the entries
    gosub sel2                          ;go to subroutine to advance through sequence
    PAUSE D                             ;pause period set by varible D
    NEXT counts                         ;advance through loop to next position
    goto main:                          ;go back to the main program and run again
    
    Sel1:
    if swcount = 1 then read Patt1, steps
    if swcount = 2 then read Patt2, steps
    If swcount = 3 then read Patt3, steps
    if swcount = 4 then read Patt4, steps
    if swcount = 5 then read Patt5, steps
    If swcount = 6 then read Patt6, steps
    If swcount = 7 then Read patt7, steps
    return
    
    Sel2:
    if swcount = 1 then READ (Patt1+counts), PORTB 
    if swcount = 2 then READ (Patt2+counts), PORTB
    if swcount = 3 then READ (Patt3+counts), PORTB
    if swcount = 4 then READ (Patt4+counts), PORTB
    if swcount = 5 then READ (Patt5+counts), PORTB
    if swcount = 6 then READ (Patt6+counts), PORTB
    if swcount = 7 then READ (Patt7+counts), PORTB
    RETURN
      
    END
    The only strange thing that is happening now is that at the end of each pattern sequence I get strange additional flash on some LEDS at the end (or start its hard to tell). On most patterns this tends to be RA3 or RA4, but on one RA0, RA2 and RA3 all flash together (one pulse) at the end of the sequence ???

    Maybe I should look at the data tables a bit more ?

    EDIT:
    Thats really strange.. for the pattern of RA0, RA2 and RA3 to light I think I'm right is saying that PORTB would have to have 13 sent to it. - I can't see 13 anywhere in the vales of the last two patterns which is where this problem is occuring

    Thanks for all your help... Boy I love coding with PBP... things actually happen
    Last edited by malc-c; - 14th June 2006 at 00:03.

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Doh !

    Either that second cup of coffee helped, or I need glasses !

    I rechecked the data strings and the offending digit was the first one after each step value (ie the second byte) - How I missed it I don't know !


    Now that phase 1 is complete, its time to move on to phase 2. Uploading the data sequences via RS232 comms..... time to read the manual

    And before you ask what phase 3 might be... its Music triggering.... Time to go searching for a circuit that will provide either a beat pulse to trigger the stepping of the pattern, or some form of filter so I can produce a 4 channel sound to light with RA0 & RA1 triggered by the bass, RA2 and RA3, lower midrange, RA4 and RA5 upper midgrange and finally RA6 and RA7 treble

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 05:47
  2. Nokia 3310 display text
    By chai98a in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th August 2007, 04:39
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 03:21
  4. LCD + bar graph
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th October 2005, 15:50
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 29th November 2004, 00:56

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