+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    566

    Default Again about array

    Hi !
    I tried to read 10 samples of ADC values and sending to LCD display.
    Code:
    DataW 	var word[10]
    i       var byte
    
    
    main:
    for i=0 to 9
        ADCON0.1 = 1			' Start conversion
    	While ADCON0.1=1:Wend		' Wait for conversion
    	DataW.HighByte=ADRESH		' Read variable from ADC and save
    	DataW.LowByte=ADRESL
    	pause 50
    next i
    
    IF DATAW < 1023   THEN
          LCDOUT $fe,1
          for i=0 to 9
          lcdout dec dataw[i], " "
          next i
          endfor     
    PAUSE 1000                           
    Endif
    
    
    Goto main
    But on LCD I have the value of ADC and seven "0". (like : 77 0 0 0 0 0 0 0)
    Please, help ! What I do wrong ?
    Thanks !

  2. #2
    Join Date
    Sep 2009
    Posts
    654

    Default Re: Again about array

    Where you index your array here
    Code:
    for i=0 to 9
        ADCON0.1 = 1			' Start conversion
    	While ADCON0.1=1:Wend		' Wait for conversion
    	DataW.HighByte=ADRESH		' Read variable from ADC and save
    	DataW.LowByte=ADRESL
    	pause 50
    next i
    Also high and low byte will just use first word of array.
    IF DATAW < 1023 THEN this also only reference first word of array.

    Array must be used as in LCDOUT.
    So your code should look like this
    Code:
    TmpW var word
    DataW 	var word[10]
    i       var byte
    
    
    main:
    for i=0 to 9
        ADCON0.1 = 1			' Start conversion
    	While ADCON0.1=1:Wend		' Wait for conversion
    	TmpW .HighByte=ADRESH		' Read variable from ADC and save
    	TmpW .LowByte=ADRESL
            DataW[i]=TmpW 
    	pause 50
    next i
    
    LCDOUT $fe,1
    for i=0 to 9
          lcdout dec dataw[i], " "
    next i

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    566

    Default Re: Again about array

    Thank you verry much ! Works fine !
    I really appreciate it !
    ...and how to continue to second line of LCD ? There is no room for ten values on the first line ...
    Something like this ?
    Code:
    LCDOUT $fe,1
    for i=0 to 3
          lcdout dec dataw[i], "," 
    pause 500
    next i
    
    lcdout $FE, $C0
    
    for i=4 to 7
          lcdout dec dataw[i], "," 
    pause 500
    next i
    Note : there is room only for four values on the line
    Last edited by fratello; - 6th March 2018 at 13:11.

  4. #4
    Join Date
    Sep 2009
    Posts
    654

    Default Re: Again about array

    That should work.

  5. #5
    Join Date
    Oct 2009
    Posts
    577

    Default Re: Again about array

    Quote Originally Posted by fratello View Post
    ...and how to continue to second line of LCD ? There is no room for ten values on the first line ...
    Code:
    Line 1 = $80
    Line 2 = $C0
    If you have a 4 line LCD

    Code:
    Line 1 = $fe,$80,
    Line 2 = $fe,$C0,
    Line 3 = $fe,$94,
    Line 4 = $fe,$d4,
    Last edited by Scampy; - 6th March 2018 at 17:40.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,735

    Default Re: Again about array

    Quote Originally Posted by fratello View Post
    Note : there is room only for four values on the line
    Then you can only fit 8 values!

    For 10 I guess you have to use a larger display or maybe use hex notation.

    Ioannis

  7. #7
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    566

    Default Re: Again about array

    Yes, I use only 8 value.
    Thank you, all !

Similar Threads

  1. Copying Array to Array
    By vamtbrider in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th April 2010, 01:12
  2. Custom array of ports using array?
    By blainecf in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 18th June 2006, 01:43
  3. Array
    By ripmax in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th March 2006, 22:21
  4. Array
    By p5taylor in forum mel PIC BASIC
    Replies: 1
    Last Post: - 20th February 2006, 20:08
  5. Word array behaving like byte array.... wierd
    By forgie in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 2nd August 2005, 15:43

Members who have read this thread : 17

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