I2CWRITE not writing anything on PIC18F45K80


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    Found another bug/issue.

    Here's simple code:

    Code:
    topline	var byte [16]  'top part of the screen array
    botline var byte [16] 'bottom part of screen
    
    
    arraywrite topline,["0123456789ABCDEF"]
    arraywrite botline,["0123456789ABCDEF"]
    
    
    
    
    
    
    FOR X=0 TO 30 step 2	'READ ARRAY INTO VARIABLE, ARRAY MEMBER CHAR=EEPROM OFFSET	
    if X<=15  then
    Y=(botline[x]-48)*8
    Z=(botline[x+1]-48)*8 'READ  INTO VARIABLE AS TWINS
    endif
    
    
    
    
    FOR I=0 TO 7	'HELPER LOOP FOR CHARACTER READING
    LCDOUT $FE,$80+c+i 'UPDATE Y POSITION
    LCDOUT $FE,$80+x/2 'UPDATE X POSITION
    READ Y+I,A 'READ EEPROM BYTES INTO VAR
    READ Z+I,B
    
    
    if topline[x]=32 or botline[x]=32 then a=0
    if topline[x+1]=32 or botline[x+1]=32 then b=0 'blanker
    
    
    if atrib=1 and X<16 then
    a=A^%11111111
    b=b^%11111111
    endif
    
    
    if a=$FE then a=0
    if b=$fe then b=0
    
    
    
    
    LCDOUT a
    LCDOUT b 'WRITE TO SCREEN
    NEXT I
    NEXT X
    It should display 0123456789ABCDEF on LCD screen. It does, but there's an issue.

    If reading text from 1st declared array (topline), then it is displayed correctly. However, if reading from 2nd declared array (botline), one of characters will be randomly missing in displayed text. This is not issue of my code, because if I do not declare "topline" array, then "botline" reading works fine.

    So what this means, 18F45K80 can't handle two 16 byte arrays at same time?

  2. #2
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    Your arrays are declared as 'var byte[16]'
    Code:
    topline var byte [16]
    botline var byte [16]
    That means a valid array index is from 0-15

    This code here will fail when x=15
    Code:
    if X<=15  then
    Y=(botline[x]-48)*8
    Z=(botline[x+1]-48)*8 'READ  INTO VARIABLE AS TWINS
    Z will try and access botline[x+1] = botline[16], which is invalid

  3. #3
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    X is being incremented in steps of 2, so it will never be 15.
    I even modified code so that X will never exceed 14 - issue is still here, but there is some logic in it.

    I tried to add code in loop and look at output.
    it changes in the following way based on loop step:

    012345 789ABCDEF
    0123456789 BCDEF
    012345678 ABCDEF
    01234567 9ABCDE

  4. #4
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    Did a test with various size of arrays.
    If both arrays do not exceed 24 bytes total, then everything is fine. As they exceed 24 bytes, issues start to appear.

  5. #5
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    Fair enough, but what about this when x >= 16
    Code:
    if topline[x]=32 or botline[x]=32 then a=0
    if topline[x+1]=32 or botline[x+1]=32 then b=0 'blanker

  6. #6
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    I don't see any relation
    I modified code and X now changes from 0 to 14 - still same issue.

  7. #7
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    You've been using x, y, and z to get values to set a and b.
    You've been shoving invalid data out to the lcd and wondering why the display is wrong.

    It's probably still wrong.

  8. #8
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    LOL.
    I'm trying to explain that if I add one extra array definition, another array gets screwed. How this is related to LCD?
    I just wrote another code, which simply reads values of array and writes data on 1602LCD.
    Issue still exists - data in array gets damaged, if total array length exceeds 24 bytes.

Similar Threads

  1. DT_Ints with PIC18F45K80 problem
    By Zapman in forum Code Examples
    Replies: 2
    Last Post: - 20th April 2022, 01:43
  2. Replies: 9
    Last Post: - 27th January 2015, 13:57
  3. PIC18F45K80 runs way to fast.
    By bmoe79 in forum PBP3
    Replies: 3
    Last Post: - 19th December 2014, 13:24
  4. I2CWrite issue
    By robertmark68 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 20th September 2006, 01:30
  5. I2CWRITE writing Strings to EEPROM
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th March 2005, 19:45

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