DCD command - need some advice


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    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
    The other question I have, is on a 16F628A the datasheet shows the program memory (flash words) as 2048, data memory as 224 bytes SRAM and 128 EEPROM bytes. However the Datasheet for the 16F873A shows Program memory as 7.2K bytes / 4096 single word instructions. Can someone advise why / what is meant by the two entries for the '873A's program memory, and if it's different to the '628A's memory ?

    In the Mid-Range PICs (16Fxxxx), each instruction is 14 bits long, and is considered a "single word instruction." So, 2048 words in the 628A is half the instructions as 4096 words in the 873A. The 7.2K bytes is just (4096 words * 14 bits)/8 bits = total actual bytes. Not a very useful number (IMO) when using these devices.

    HTH,
    SteveB

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


    Did you find this post helpful? Yes | No

    Default

    Thanks guys for your replies.

    Steve,
    When I said it worked, I mean it compiles without error, not that it actually produced the correct pattern sequence on the LEDs attached to PORT B. I based this on the example you provided in the post on my troubles with programming the 2550 chip. Your code below produced a nice chase sequence whe programmed into the 16F873A

    Code:
    ByteA   var byte
     
    main:
        for bytea=0 to 7
            PORTB=DCD BYTEA
            PAUSE 250
            NEXT
        PORTB=255
        PAUSE 250
        goto main
    If I read your code correctly DCD is converting the value of bytea (0 to 7) to binary and then displaying this vaule on port B. ie 1 = 00000001, 2 = 00000010 etc. I was hoping that I could read the pattern string, take the values of each step (0 to 255) and use DCD to display the pattern on port B. Hence
    Code:
    for bytea=0 to steps
            PORTB=DCD patt3
            PAUSE D
        NEXT
    Funny thing is that as I'm typing this I think I know where 'm going wrong. I need to read each value in the sequence. My old code (for the 16F628A) used
    Code:
    if swcount = 1 then READ (Patt1+counts), PORTB  ;read the next value in patt1 and display it on 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
    So I tried the following (hopefully you will see my logic

    Code:
    n = swcount
    
    Pot PORTA.1,scale,D                 ;used to read value from 10k pot
        for bytea=0 to steps
           READ (Pattn+bytea), PORTB 
            PAUSE D
        NEXT
    goto main
    Thinking that it would READ pattern 3 (as I set SWCOUNT to 3 for testing) + the value for bytea (0, to STEPS) and then output it to PORT B. But I get an error "Bad Expression" with the READ (PatN+bytea), PORTB line.

    SteveB (and Steve if you can help )

    Would the differences between the two chips that you stated cause the use of the DATA statement be handled differently between the two PICs. The reason I ask was then If I use the code I originally wrote for the 16F628a with the 16F873a, the patterns are not displayed in the same way on the '873a.

    Thanks for your help

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


    Did you find this post helpful? Yes | No

    Default

    how about this one?
    Code:
    ;************* 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=$0F
    CMCON = 7                        ' Digital inputs
    CCP1CON = 0                      ' PWM off
    TRISA=%11100111                  'set PORTA as all input apart from A3 & A4
    TRISB=%00000000                  'set PORTB as all output
    PORTB=0
    
    ;************* set up variables ***************
    
    Patt    var byte [8]
    asm
        MOVE?CB _Patt1,_Patt+1 ; Patt[1]
        MOVE?CB _Patt2,_Patt+2 ; Patt[2]
        MOVE?CB _Patt3,_Patt+3 ; Patt[3]
        MOVE?CB _Patt4,_Patt+4 ; Patt[4]
        MOVE?CB _Patt5,_Patt+5 ; Patt[5]
        MOVE?CB _Patt6,_Patt+6 ; Patt[6]
        MOVE?CB _Patt7,_Patt+7 ; Patt[7]
    endasm
    
    ByteA   var byte
    D var byte
    scale var byte                      ;used in the POT command
    Scale = 254  
    steps var byte
    swcount var byte
    swcount=7                           ; set to 3 for testing only
    D=250
    ;**************** main program ********************
    main:
        for swcount=1 to 7
            read patt[swcount],steps
            for bytea=1 to steps
               READ PATT[SWCOUNT]+BYTEA,PORTB
               PAUSE D
               NEXT
            next
        GOTO MAIN
    noticed that i skiped the POT command but use a fixed 250mSec delay. It's working here. if you want to use DCD, you'll need to modify the DATA lines and use bit# instead of Decimal value. No big deal

    It shouldn't be different from one to another. DATA remain DATA. PORTB remain PORTB. Well i can't explain why if it doesn't create the expected results with the above suggestion

    Too bad, MPASM text substitution doesn't seems to work with Bytes variable in the #V(Variable) area.. it would be too convenient...

    EDIT: Note that MOVE?CB _Patt1,_Patt+1 can be replace by Patt[1]=Patt1 etc...

    The whole MOVE?CB block (or Patt[x]=Pattx) could also be replace using MPASM text substitution like this
    Code:
    asm
        local a=1
        while a<7
            MOVE?CB _Patt#v(a),_Patt+a
    a+=1
            endw
    endasm
    Last edited by mister_e; - 16th December 2006 at 18:08.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    how about this one?
    Yup - works a treat here too... the LEDs are cycling through all the pattern sequences quite nicely

    Now sorry to be a pain in the a$$, but you lost me right at the point you went asm
    MOVE?CB _Patt1,_Patt+1 ; Patt[1]


    I assume that this could be done in PBP without dropping out to assembly code, hence the Note that MOVE?CB _Patt1,_Patt+1 can be replace by Patt[1]=Patt1 etc... statement ????

    Sorry if this seems dumb questions, but now that 'm moving away from the simple basic commands and the fact I was (and still am) a bit rusty with my coding, all help to expand the learning curve with PBP is greatly apreciated

  5. #5
    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 18:57.
    Steve

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

  6. #6
    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...

  7. #7
    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  

Similar Threads

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