Variable in array


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191

    Post Variable in array

    I'm trying to increase LCD refresh rate by doing SPI commands without using SHIFTOUT. There seems to be quite big improvement between code #1 and code #2.

    Code #1: Lcd_CLK high time is 3.6us
    Code #2: Lcd_CLK high time is 0.8us

    This speed increasement is big and you can really notice it visually

    Code #1
    Code:
        SHiftOUT Lcd_SDA , Lcd_CLK , MSBFIRST, [FC(0),FC(1),FC(2),FC(3),FC(4),FC(5)]
    Code #2
    Code:
        Lcd_SDA = FC.0(7) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(6) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(5) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(4) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(3) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(2) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(1) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(0) : Lcd_CLK = 1 : Lcd_CLK = 0
    
        Lcd_SDA = FC.0(15) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(14) : Lcd_CLK = 1 : Lcd_CLK = 0
        ....
        ....
        ....
    
        Lcd_SDA = FC.0(47) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(46) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(45) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(44) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(43) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(42) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(41) : Lcd_CLK = 1 : Lcd_CLK = 0
        Lcd_SDA = FC.0(40) : Lcd_CLK = 1 : Lcd_CLK = 0
    Because Code #2 is quite long (48 lines) and consumes memory, I tried to make it with loops but there I faced big problems.

    I tried many different ways but never managed to get it work as Code #2.

    Code:
        for i = 0 to 5
            k=7+8*i : Lcd_SDA = FC.0[k] : Lcd_CLK = 1 : Lcd_CLK = 0
            k=6+8*i : Lcd_SDA = FC.0[k] : Lcd_CLK = 1 : Lcd_CLK = 0
            k=5+8*i : Lcd_SDA = FC.0[k] : Lcd_CLK = 1 : Lcd_CLK = 0
            k=4+8*i : Lcd_SDA = FC.0[k] : Lcd_CLK = 1 : Lcd_CLK = 0
            k=3+8*i : Lcd_SDA = FC.0[k] : Lcd_CLK = 1 : Lcd_CLK = 0
            k=2+8*i : Lcd_SDA = FC.0[k] : Lcd_CLK = 1 : Lcd_CLK = 0
            k=1+8*i : Lcd_SDA = FC.0[k] : Lcd_CLK = 1 : Lcd_CLK = 0
            k=0+8*i : Lcd_SDA = FC.0[k] : Lcd_CLK = 1 : Lcd_CLK = 0
        next i
    Code:
        for i = 0 to 5
            Lcd_SDA = FC.0[7+8*i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[6+8*i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[5+8*i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[4+8*i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[3+8*i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[2+8*i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[1+8*i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[0+8*i] : Lcd_CLK = 1 : Lcd_CLK = 0
        next i
    Code:
        for k = 0 to 5
            for i = (8+(8*k)) to (1+(8*k)) step -1
                j = i-1
                Lcd_SDA = FC.0(j) : Lcd_CLK = 1 : Lcd_CLK = 0
            next i
        next k
    (Variables i, j and k are bytes)

    I have read Melanies guide about Bits, Byte Words and Arrays, which tells how to you can reference to Arrays, etc...
    http://www.picbasic.co.uk/forum/show...17&postcount=1
    but it didn't help me too much. I have understood that variable in array is OK, am I wrong?

    -Gusse-

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Gusse, this one should be better:

    Code:
    for i = 0 to 40 step 8
            Lcd_SDA = FC.0[7+i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[6+i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[5+i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[4+i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[3+i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[2+i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[1+i] : Lcd_CLK = 1 : Lcd_CLK = 0
            Lcd_SDA = FC.0[0+i] : Lcd_CLK = 1 : Lcd_CLK = 0
        next i
    Al.
    All progress began with an idea

  3. #3
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Post No solution yet...

    Hi Al,

    Your code worked a bit better but no as Code #2.

    Even code below won't run as Code #2. I wounder why? Only difference is that there is a variable in array. And why i = 0-7 is OK, but next are not??
    Code:
        i=7 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0
        i=6 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0
        i=5 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0
        i=4 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0
        i=3 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0
        i=2 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0
        i=1 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0
        i=0 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0 
        
        i=15 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0 '<- Stop working
        ...
        ...
        i=40 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0
    It seems that 1st character (1st 8 bits) are OK, but next charaxters 1-5 are not working (shows only blanck screen at those places).

    -Gusse-

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Even code below won't run as Code #2. I wounder why?
    you have an extra operation to do in this code (i=7:..), while in code 2 you don't do.

    Al.
    All progress began with an idea

  5. #5
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Post

    To my understanding these two codes should be as equal as possible. One is using a constant, the other variable (i).
    Code:
        Lcd_SDA = FC.0(7) : Lcd_CLK = 1 : Lcd_CLK = 0
    Code:
        i=7 : Lcd_SDA = FC.0(i) : Lcd_CLK = 1 : Lcd_CLK = 0
    This extra operation i=7 shouldn't be a problem if arrays support variable(s).

    -Gusse-
    Last edited by Gusse; - 18th February 2009 at 20:31.

  6. #6
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Red face Me Stupid!

    Now when I re-opened this problematic project, it was very clear to me what was wrong. It was too obvious and I can only say "Me Stupid!".
    If I have defined a new variable for loop, something else than i, j or k (which were used in other part of the code) then I would never faced the problem.

    All codes posted under this topic are working well.

    Thanks Al for your help, I appreciate it a lot!

    -Gusse-
    Last edited by Gusse; - 22nd February 2009 at 20:50.

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 01:06
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 05:46
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 21:36
  4. How to saparate variable to array and GLCD Question
    By pramarn in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 4th October 2006, 04:42
  5. display lcd variable array Ascii
    By volcane in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd November 2005, 22:36

Members who have read this thread : 1

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