Advice please - data tables


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

    Default Advice please - data tables

    I'm learing PBP and although its been a steep learning curve, the support of this forum has been great and I've taken onboard what I've been given.

    I'm just playing about with the "flash some LEDs", basic stuff really, and I now have the basis for what could turn into a nice project for some disco lights. I've detailed my code below, which basically has a chase pattern, the speed of which is set by a 10k pot.

    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=%00000111        'set PORTA as all output apart from A0, A1 and A2
    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 varibles
    
    PORTBbit var  byte      
    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.2     ;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
                                                                
    ;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 sw2=0 then swcount=swcount-1     ;check to see if down button pressed
    pause 120                           ;debounce delay
    If swcount>2 then swcount=2         ;error trap for exceeding max patterns
    If SWcount<1 then swcount=1         ;error trap for exceeding min patterns
    if swcount=1 then pattern1          ;goto selected pattern based on value
    if swcount=2 then pattern2          
    
    
    pattern1:                           ;standard chase pattern 1 - 8
    For PORTBbit=0 to 7
    if D<5 then D=5                     ;set the minimum pause time to 5ms
    HIGH PORTBbit      
    pause D
    LOW PORTBbit
    pause D
    Next
    goto main
    
    pattern2:                           ;standard pattern reveresed 8 -1
    For PORTBbit=7 to 0 step -1
    if D<5 then D=5
    HIGH PORTBbit      
    pause D
    LOW PORTBbit
    pause D
    Next
    goto main
    However now I would like to add further patterns and ideally store / code them as data strings or binary patters that are repeated, eg

    [code]
    10000001
    01000010
    00100100
    00011000
    00100100
    01000010
    10000001

    or
    129, 66, 36, 24, 36, 66,129
    [code]

    I've browswed through the manual, but can't see any clear reference on how to write these values in a loop to portB. ie something like

    [code]
    for i = 1 to number of steps
    write value to port
    make port high
    delay
    port low
    next
    [code]

    My evential goal would be to use the UART in the chip to communicate with a PC and allow the additional patterns to be uploaded to the PIC.. but I think I had better learn to walk before I start running

  2. #2
    Early1's Avatar
    Early1 Guest


    Did you find this post helpful? Yes | No

    Default

    This is easy to do.

    Create a variable byte

    i byte
    Myvar byte[10] make the array the same size as the number of paterns you would like.
    Myvar[0]= some patern
    Myvar[1]= next patern
    Myvar[2]= another patern

    etc

    for i =0 to 10
    portb=myvar[i]
    delay
    portb=0
    next i

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Early1
    This is easy to do.

    Create a variable byte

    i byte
    Myvar byte[10] make the array the same size as the number of paterns you would like.
    Myvar[0]= some patern
    Myvar[1]= next patern
    Myvar[2]= another patern

    etc

    for i =0 to 10
    portb=myvar[i]
    delay
    portb=0
    next i

    Thanks for the reply, when you say myvar[0] = some pattern, how would I define the arrays? Would it be "00110011" etc or decimal numbers "xxx, xx, xx"

    Yeah I too was looking for the option of deleting my own posts after multiple post occured, but it looks like that is only available to the mods

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


    Did you find this post helpful? Yes | No

    Default

    Actually, I don't think that's what I'm after having read the code more. I'm really after the ability of having the patterns as single lines, in your example MyVAR[0] would contain all the steps of the pattern, and not the first step.

    eg:
    MyVAR[0] = "129, 66, 36, 24, 36, 66,129" would send decimal 129 to PORTB, then 66, then 36 and so on, then repeat this pattern over and over again.

    If I understand your suggestion correcly, it would be the same as having
    MyVar[0] = "129"
    MyVar[1] = "66"
    etc

    Any comments ?

  5. #5
    Early1's Avatar
    Early1 Guest


    Did you find this post helpful? Yes | No

    Default

    That is exactly what I meant.

    All I need now is for some one to help me with my little problem.

    Cheers

  6. #6
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default How about

    Pattern: var byte ' hold the pattern for PortB
    Gen0: var byte ' general purpose reg

    ChasePattern: data 129, 66, 36, 24, 36, 66,129, -1

    OutPattern:
    Gen0 = ChasePattern ' Gen0 is a pointer to the pattern
    while 1 ' forever
    read Gen0, Pattern
    if Pattern = -1 then ' this is the end marker,
    goto OutPattern ' see it, start over
    else
    PortB = Pattern
    endif
    wend

    Mind you, you need to configure PortB as outputs etc. which I havent done for you.
    Sorry I cannot find how to format the code even though I have done it earlier.

    Jerson

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


    Did you find this post helpful? Yes | No

    Default

    Jerson,

    Thanks for replying. I started a new thread last night and have a similar suggestion from Steve using for next loops, but I'll also try your suggestion of using the while and wend commands and adding an end of line marker such as -1 (its all go practice )

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 04:47
  2. Read/Write Problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th February 2010, 01:51
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21
  4. LCD + bar graph
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th October 2005, 14:50
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 28th November 2004, 23: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