DCD command - need some advice


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    So, i think i lost you pretty much more with the second asm code using the text substitution?

    Sorry sometimes i'm getting sick with those MOVE?CB, PAUSE?C, macro and whatever else... It's the Darrel's fault!

    Yup indeed the whole MOVE?CB ... block could be replace by using...
    Code:
    Patt[1]=Patt1
    Patt[2]=Patt2
    Patt[3]=Patt3
    Patt[4]=Patt4
    Patt[5]=Patt5
    Patt[6]=Patt6
    Patt[7]=Patt7
    Now compile those line and open the .asm file... you'll discover somewhere those lines...
    Code:
    ; C:\PBP_PROG\A.BAS        	00040	Patt[1]=Patt1
    	MOVE?CB	_Patt1, _Patt + 00001h
    
    ; C:\PBP_PROG\A.BAS        	00041	Patt[2]=Patt2
    	MOVE?CB	_Patt2, _Patt + 00002h
    
    ; C:\PBP_PROG\A.BAS        	00042	Patt[3]=Patt3
    	MOVE?CB	_Patt3, _Patt + 00003h
    
    ; C:\PBP_PROG\A.BAS        	00043	Patt[4]=Patt4
    	MOVE?CB	_Patt4, _Patt + 00004h
    
    ; C:\PBP_PROG\A.BAS        	00044	Patt[5]=Patt5
    	MOVE?CB	_Patt5, _Patt + 00005h
    
    ; C:\PBP_PROG\A.BAS        	00045	Patt[6]=Patt6
    	MOVE?CB	_Patt6, _Patt + 00006h
    
    ; C:\PBP_PROG\A.BAS        	00046	Patt[7]=Patt7
    	MOVE?CB	_Patt7, _Patt + 00007h
    Interesting eh?

    NOW, why i use the MOVE?CB first? Well didn't thought Patt[1]=Patt1 would worked... later i decide to try and... Woohhooo

    So this is why i edited my previous post. I'm still learning as well. I guess we never stop anyways!

    MOVE?CB: Is a PBP macro wich copy a Constant value to a Byte variable. Not much.

    Glad to hear it's working as expected
    Have fun!
    Last edited by mister_e; - 16th December 2006 at 19:57.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default An apple for my teacher :)

    Thanks for the explanation...

  3. #3
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Thumbs up

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1273&stc=1&d=116630151 9">
    Bravo Steve!

    Nice explaination.


    SteveB
    Attached Images Attached Images  

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Woooho!


    Gracias, Merci, thank you,falemnderit, σασ ευχαριστώ, danke, grazie, ขอบคุณ, teşekkür ederim ,...,..
    Last edited by mister_e; - 16th December 2006 at 20:50.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    You guys crack me up !

    Ok' I'm working my way through this version using the 16F873A, but I've hit a small issue which is so basic I can't see why it responds the way it does (it worked with the 16F628a).

    I have set port A to all inputs and added
    Code:
    SW1 var PORTA.2                         ;pattern selection switch
    I have a 10k pull up resistor between pin 4 (RA2) and +5v with a tactile switch between pin 4 and GND.

    I've added the code
    Code:
    if SW1=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
    So in therory if the switch (sw1) is low then swcount is increased by 1, until it is > than 7 and if so then its swcount is reset to 1. This way the pattern is selected by pressing the switch.

    However in practice, the PIC simply ignores any input on RA2, but more confusingly, it runs each pattern once in sequence, ie it cycles through the patterns as if the button is being pressed, so swcount must in some way be changing as the remainder of the code works if the above lines are remed out and swcount is manual set to 1, 2, 3 etc, which results in just the selected pattern running.

    Code:
    Pot PORTA.1,scale,D                     ;used to read value from 10k pot and set the speed
    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
    GOTO MAIN
    Its probably me having a blonde moment (no offence to any fair haired madiens out there ) - but can anyone shed some light why this isn't working.

  6. #6
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c
    Ok' I'm working my way through this version using the 16F873A, but I've hit a small issue...

    I have set port A to all inputs...

    the PIC simply ignores any input on RA2, but more confusingly, it runs each pattern once in sequence, ie it cycles through the patterns as if the button is being pressed, so swcount must in some way be changing...
    Code:
    Pot PORTA.1,scale,D                     ;used to read value from 10k pot and set the speed
    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
    GOTO MAIN
    Exactly what value have you put into ADCON1 to "set port A to all inputs" yet still get the Pot command to work? It seems as though you still might have some of them set as Analog Inputs.

    SteveB
    Last edited by SteveB; - 17th December 2006 at 01:57.

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    Here is the complete code (less the data for light patterns)
    Code:
    ;************* set up PIC ********************
    
    ADCON1=$0F
    CMCON = 7                               ' Digital inputs
    CCP1CON = 0                             ' PWM off
    TRISA=%11111111                         'set PORTA as all input 
    TRISB=%00000000                         'set PORTB as all output
    PORTB=0
    PORTA=0
    SW1 var PORTA.1                         ;pattern selection switch 
    
    ;************* 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  
    steps var byte                          ;used for storing the number of steps in a sequence
    swcount var byte                        ;used to select the required sequence required
    swcount=1                               ;set for testing only or default sequence
    
    ;**************** main program ********************
    main:
    
    if sw1=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                      
    
    ;Pot PORTA.1,scale,D                     ;used to read value from 10k pot and set the speed
    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 250                      ;delay for speed
            NEXT
    GOTO MAIN
    In this example I've removed the wire from the 10 pot and set SW to the same pin as I have the pot working fine - and it works. If I set SW to RA0, RA2, RA3 etc the LEDs run through each pattern from 1 - 7 in a loop.

    As you stated, it must be something is the setting of port A for digital. However I will at some point want one pin to be det up to use the A to D conversion as I want to input the line signal from a CD player to get the LEDs to flash / run to music at some stage in the future, all other inputs.

    Sorry if it seems so basic, but as the other Steve can vouch for.. I'm very rusty on the PBP coding !

Similar Threads

  1. Need "PIC16F84A" Controler schematic Advice...
    By Kyo_89 in forum Schematics
    Replies: 1
    Last Post: - 28th May 2009, 00:03
  2. Design Advice
    By isaac in forum General
    Replies: 38
    Last Post: - 12th October 2008, 00:07
  3. Your OTP advice?
    By truvahorse in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th June 2008, 17:37
  4. NCD vs. DCD - Commentary
    By andrewroz in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th November 2007, 00:16
  5. Advice needed on 'neat' Project!
    By vacpress in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th February 2007, 07:21

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