I2CWRITE not writing anything on PIC18F45K80


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    Quote Originally Posted by CuriousOne View Post
    "The last call" of gcoder is the code that makes that inversion, so variables are assigned before their use.
    They're used BEFORE the "last call", they're used on EVERY call to gcoder, and they're NOT assigned values.
    If that's how you think this all works you should give up now.

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


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    OK, that was my fault, you're right
    but I have caught this variable space array bug again. What happens here. If code I've selected with BOLD is active, it causes topline last byte to be replaced by space too.
    So whenever there are even seconds, instead of last digit of the date at the end of the line, I'm getting an empty space.
    As you can see, that code section does nothing - it just changes value of certain variable, which is not used elsewhere.
    But if I comment that piece of code, the error is gone.

    how this is possible?

    Code:
    #config
    CONFIG RETEN = OFF	
    CONFIG INTOSCSEL = HIGH
    CONFIG SOSCSEL = DIG
    CONFIG XINST = OFF	    ;Enabled
    CONFIG FOSC = INTIO1
    CONFIG PLLCFG = OFF
    CONFIG FCMEN = OFF	    ;Disabled
    CONFIG PWRTEN = OFF	    ;Disabled
    CONFIG BOREN = OFF	    ;Disabled in hardware, SBOREN disabled
    CONFIG WDTEN = OFF	    ;WDT disabled in hardware; SWDTEN bit disabled
    CONFIG CANMX = PORTB
    CONFIG MCLRE = OFF
    
    
    #endconfig
    
    
    OSCTUNE.6 = 1 ; Enable 4x PLL
    OSCCON = %01110000
    ANCON1=0 'DISABLE ADC D3-D2-D1-D0-
    ANCON0=0
    ADCON0=0
    TRISC=%11110000 'set PORTC as output first 4
    TRISD=%00000000 'set PORTD as output all
    TRISB=%00000000 'set PORTB as output all
    TRISA=%00000000 'set PORTA 2 as input, others as output
    TRISE=%0000000  'set PORTE as output all
    define OSC 64
    
    
    DEFINE LCD_DREG PORTD 
    DEFINE LCD_DBIT 4  
    DEFINE LCD_RSREG PORTB  
    DEFINE LCD_RSBIT 5  
    DEFINE LCD_EREG PORTA  
    DEFINE LCD_EBIT 3  
    DEFINE LCD_BITS 4  
    DEFINE LCD_LINES 2  
    DEFINE LCD_COMMANDUS 850  
    DEFINE LCD_DATAUS 30
    
    
    'i var byte
    high portb.4 'enable LCD backlight
    
    
    'digits
    data $3E, $67, $6F, $7B, $73, $63, $3E, $00 'NOLI
    data $1C, $3C, $6C, $0C, $0C, $0C, $7F, $00 'ERTI
    data $3E, $63, $03, $3E, $60, $60, $7F, $00 'ORI
    data $3E, $63, $03, $0E, $63, $63, $3E, $00 'SAMI
    data $63, $63, $63, $3F, $03, $03, $03, $00 'OTXI
    data $7F, $60, $60, $7E, $03, $63, $3E, $00 'XUTI
    data $3E, $63, $60, $7E, $63, $63, $3E, $00 'EQVSI
    data $7F, $63, $03, $06, $0C, $0C, $0C, $00 'SHVIDI
    data $3E, $63, $63, $3E, $63, $63, $3E, $00 'RVA
    data $3E, $63, $63, $3F, $03, $63, $3E, $00 'CXRA
    'SYMBOLS
    data $00, $00, $18, $18, $00, $18, $18, $00 'orcertili
    data $00, $00, $18, $18, $00, $18, $18, $30 'certilmdzime
    data $06, $0c, $18, $30, $18, $0c, $06, $00 'aket
    data $00, $00, $7e, $7e, $00, $7e, $7e, $00 'tolia
    data $30, $18, $0C, $06, $0C, $18, $30, $00 'iket
    data $3E, $63, $63, $06, $0C, $00, $0C, $00 'KITXVA
    data $7C, $C6, $DE, $F6, $DC, $C0, $7E, $00 'LOKOKINA
    
    
    'font georgian alphabet without squeek door
    data $0C, $0C, $06, $03, $63, $63, $3E, $00' data ' Char 048 (0)
    data $38, $0C, $0C, $3E, $63, $63, $3E, $00'data ' Char 049 (1)
    data $26, $63, $66, $63, $63, $63, $3E, $00'data ' Char 050 (2)
    data $3E, $63, $63, $7E, $60, $60, $3E, $00'data ' Char 051 (3)
    data $3E, $63, $03, $03, $63, $63, $3E, $00'data ' Char 052 (4)
    data $36, $6B, $6B, $36, $03, $63, $3E, $00'data ' Char 053 (5)
    data $3E, $63, $03, $1E, $33, $63, $3E, $00'data ' Char 054 (6)
    data $1E, $03, $0E, $03, $0E, $63, $3E, $00'data ' Char 055 (7)
    data $3E, $63, $63, $63, $63, $63, $22, $00'data ' Char 056 (8)
    data $0C, $3F, $0C, $06, $63, $63, $3E, $00'data ' Char 057 (9)
    data $06, $03, $0E, $03, $63, $63, $3E, $00'data ' Char 058 (:)
    data $3E, $63, $63, $62, $60, $60, $3E, $00'data ' Char 059 (;)
    data $3E, $63, $03, $3F, $63, $63, $3E, $00'data ' Char 060 (<)
    data $7F, $60, $60, $7E, $63, $63, $3E, $00'data ' Char 061 (=)
    data $3E, $6B, $6B, $6B, $63, $63, $22, $00'data ' Char 062 (>)
    data $0C, $06, $03, $06, $63, $63, $3E, $00'data ' Char 063 (?)
    data $03, $03, $0F, $1B, $03, $63, $3E, $00'data ' Char 064 (@)
    data $60, $60, $60, $7E, $63, $63, $63, $00'data ' Char 065 (A)
    data $60, $60, $60, $63, $63, $63, $3E, $00'data ' Char 066 (B)
    data $2E, $6B, $6B, $63, $63, $63, $3E, $00'data ' Char 067 (C)
    data $36, $6B, $4B, $03, $63, $63, $3E, $00'data ' Char 068 (D)
    data $3E, $63, $03, $06, $63, $63, $3E, $00'data ' Char 069 (E)
    data $3E, $6B, $60, $7E, $63, $63, $3E, $00'data ' Char 070 (F)
    data $60, $60, $60, $7E, $63, $63, $3E, $00'data ' Char 071 (G)
    data $63, $63, $63, $3F, $03, $63, $3E, $00'data ' Char 072 (H)
    data $38, $6C, $6C, $3E, $1B, $1B, $0E, $00'data ' Char 073 (I)
    data $3E, $6B, $6B, $6B, $6B, $6B, $32, $0 'data for TH [
    data $07, $4F, $5B, $33, $03, $63, $3E, $00 '\ jh
    data $3E, $6B, $6B, $62, $60, $60, $3E, $00 '] RR
    data $36, $5B, $03, $3F, $63, $63, $3E, $00 '^sh
    data $3C, $66, $6C, $7E, $63, $63, $63, $00  '_ ch
    data $03, $03, $03, $3F, $63, $63, $3E, $00  '` dz
    
    
    'indicators  CORRESPOND SMALL LETTERS
    data $EC, $A4, $A4, $A4, $A4, $A4, $EE, $00 '01
    data $EE, $AA, $A2, $AE, $A8, $A8, $EE, $00 '02
    data $EE, $A2, $A2, $AE, $A2, $A2, $EE, $00 '03
    data $EA, $AA, $AA, $AE, $A2, $A2, $E2, $00 '04
    data $EE, $A8, $A8, $AE, $A2, $AA, $EE, $00 '05
    data $EE, $AA, $A8, $AE, $AA, $AA, $EE, $00 '06
    data $EE, $AA, $A2, $A2, $A2, $A2, $E2, $00 '07
    data $EE, $AA, $AA, $AE, $AA, $AA, $EE, $00 '08
    data $EE, $AA, $AA, $AE, $A2, $AA, $EE, $00 '09
    data $CE, $4A, $4A, $4A, $4A, $4A, $EE, $00 '10
    data $CC, $44, $44, $44, $44, $44, $EE, $00 '11
    data $CE, $42, $42, $4E, $48, $48, $EE, $00 '12
    data $CE, $42, $42, $4E, $42, $42, $EE, $00 '13
    data $CA, $4A, $4A, $4E, $42, $42, $E2, $00 '14
    data $CE, $48, $48, $4E, $42, $4A, $EE, $00 '15
    data $CE, $48, $48, $4E, $4A, $4A, $EE, $00 '16
    data $CE, $4A, $42, $42, $42, $42, $E2, $00 '17
    data $CE, $4A, $4A, $4E, $4A, $4A, $EE, $00 '18
    data $CE, $4A, $4A, $4E, $42, $4A, $EE, $00 '19
    data $EE, $AA, $2A, $EA, $8A, $8A, $EE, $00 '20
    data $EC, $A4, $24, $E4, $84, $84, $EE, $00 '21
    data $EE, $AA, $22, $EE, $88, $88, $EE, $00 '22
    data $EE, $A2, $22, $EE, $82, $82, $EE, $00 '23
    data $EA, $AA, $2A, $EE, $82, $82, $E2, $00 '24
    data $10, $28, $48, $48, $48, $28, $10, $00 'light oFF
    data $20, $56, $90, $96, $90, $56, $20, $00 'LIGHT ON
    data $01, $03, $06, $0C, $18, $30, $60, $00 '/ side line { this char
    
    
    '''''''LCD HANDLER VARIABLES
    x var byte ' counter variable
    z var WORD ' temp variable
    y var WORD 'eeprom reader var
    i var byte 'counter
    a var byte
    b var byte  'temps
    c var byte
    astart var byte 'inversion atribute start
    aend var byte 'inversion end
    separ var byte 'dual dot separator
    
    
    '----------- RTC 
    
    
    RTCYear  Var Byte: RTCMonth Var Byte: RTCDate  Var Byte: RTCDay   Var Byte: RTCHour  Var Byte
    RTCMin   Var Byte: RTCSec   Var Byte: RTCCtrl  Var Byte 
    SDA VAR PORTB.3
    SCL VAR PORTB.2
    
    
    SAATI VAR BYTE
    CUTI VAR BYTE
    'CELI VAR BYTE
    TVE VAR BYTE
    RICXVI VAR BYTE
    DGE VAR BYTE 
    CAMI VAR BYTE
    dro var byte
    cvlileba var byte 'clock trigger set
    
    
    
    
    '------------- PCF IO
    padr var byte
    PSDA var portd.0
    PSCL var portd.1
    
    
    
    
    '-----GLOBAL VARIABLES
    ABSTIME VAR WORD 'CURRENT ABSOLUTE TIME, HOURS*60+MINUTES FROM RTC
    MENUITEM VAR BYTE 'CURRENT MENU POSITION VARIABLE
    time var bit[24] 
    
    
    'INPUTS
    UPBT VAR PORTC.5 'UP BUTTON
    DNBT VAR PORTC.4 'DOWN BUTTON
    LBUT VAR PORTC.7 'LEFT/BACK BUTTON
    RBUT VAR PORTC.6 'RIGHT/OK BUTTON 
    
    
    sdao var portd.0
    sclo var portc.3
    
    
    'OUTPUTS PCF  - 66 CON EDGE, 64 MIDDLE, 78 BUTTON SIDE
    adr var byte  'OUTPUT PCF ADDRESS
    adr=78
    
    
     '[\]`^_  th zh R dz sh ch
    topline	var byte [32]  'top part of the screen array
    botline var byte [32] 'bottom part of screen
    
    
    lcdout $fe, $20 'enable text mode -  this is required to fix issue of 18F
    LCDOUT $FE,$2, "TEST"
    pause 100
    LCDOUT $FE,$2, "    "
    pause 500
    LCDOUT $FE,$2E  'enable graphic mode
    pause 500
    'z=0
    gosub gpt 'clear screen
    
    
    astart=0
    aend=0                                     '1234567890ABCDEF
    arraywrite topline, ["                "]
    arraywrite botline, ["                "]
    for c=0 to 24 step 8
    gosub gcoder
    next
    drk:
    gosub gettime
    
    
    if CAMi.0=1 then  'blink the dots each second
    separ=58
    else
    separ=32
    endif
    
    
    
    arraywrite TOPLINE, [dec saati dig 1,dec saati dig 0,32, dec cuti dig 1, dec cuti dig 0,32, dec cami dig 1, dec cami dig 0,32, dec TVE DIG 1, DEC TVE DIG 0,"{", DEC ricxvi DIG 1, DEC ricxvi dig 0]
    C=0
    'astart=1+16
    'aend=2+16  
    if cvlileba=1 then GOSUB GCODER
    pause 50
    goto drk
    
    
    
    
    stop
    
    
    
    
    
    
    GCODER:
    FOR X=0 TO 30 step 2	'READ ARRAY INTO VARIABLE, ARRAY MEMBER CHAR=EEPROM OFFSET	
    if X<15 then
    Y=(topline[x]-48)*8
    Z=(topline[x+1]-48)*8 'READ  INTO VARIABLE AS TWINS
    endif
    
    
    if x>15 then
    Y=(botline[x-16]-48)*8
    Z=(botline[x-15]-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-16]=32 then a=0
    if topline[x+1]=32 or botline[x-15]=32 then b=0 'blanker
    
    
    if X=>astart and x<=aend and astart<>aend 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
    return
    
    
    GPT:
    for y=0 to 30 step 2
    LCDOUT $FE,$80+y
    LCDOUT $FE,$80
    FOR x=1 TO 16
    LCDOUT 0
    NEXT
    next
    return
    
    
    gettime:
       I2CRead SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
       CAMI=(RTCSEC >> 4)*10+RTCSEC // 16
       CUTI=(RTCmin >> 4)*10+RTCmin // 16 'decode seconds
       SAATI=(RTCHour >> 4)*10+RTCHour // 16 'decode hours
       TVE=(RTCmonth >> 4)*10+RTCmonth // 16 'decode month   
       RICXVI=(RTCdate >> 4)*10+RTCdate // 16 'decode month
       DGE=RTCday
         if DRO<>rtcsec then  'check for time changes, so display only is refreshed when time is changed
      cvlileba=1
      else
      cvlileba=0
      endif 
      DRO=rtcmin 
    Return

  3. #3
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    There are still places where things can go wrong, so until they're fixed all bets are off.

    For example in gcoder you have the following (I've removed some of the code for clarity)
    Code:
        FOR X=0 TO 30 step 2	'READ ARRAY INTO VARIABLE, ARRAY MEMBER CHAR=EEPROM OFFSET	
    ...
            FOR I=0 TO 7	'HELPER LOOP FOR CHARACTER READING
    ...
                if topline[x]=32 or botline[x-16]=32 then a=0
                if topline[x+1]=32 or botline[x-15]=32 then b=0 'blanker
    Follow that code through for X=0 to 14. What happens to a and b?
    Last edited by tumbleweed; - 9th May 2023 at 22:57.

  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

    These are code parts which insert the empty space when in the array we do have code for ASCII space (32).
    And this part of code works just fine.
    The issue is that another, non-related part of code is causing problems.
    Why changing value of certain variable, which is not used at all, causes issues with another variable?

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    Maybe because you are altering places in memory of the PIC that you are not aware of?

    In the above example, if x=0, the

    Code:
    botline[x-16]=32 then a=0
    how does evaluate?

    Do you see the consequences of?

    Ioannis

  6. #6
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    And this part of code works just fine.
    The issue is that another, non-related part of code is causing problems.
    Why changing value of certain variable, which is not used at all, causes issues with another variable?
    Ioannis gets it. You don't. That code doesn't "work just fine".

    Your array index statements are screwed up, so you're accessing who knows what in memory.
    That would explain the mysterious "I add unrelated code and things change".

    There are any number of places for all that to go south... I don't trust many of those array accesses to be valid.

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


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    Well, that is interesting.
    As I understand, there is no "index out of bounds" error type supported by PBP?

    I've modified that part of code to look like this:

    Code:
    if topline[x]=32 then a=0
    if topline[x+1]=32 then b=0 'blanker
    
    
    if X=>16 and botline[x-16]=32 then a=0
    if x=>16 and botline[x-15]=32 then b=0
    So far, works fine. Will keep you updated

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    Quote Originally Posted by CuriousOne View Post
    Well, that is interesting.
    As I understand, there is no "index out of bounds" error type supported by PBP?
    Page 275 of the manual:

    7.6.1 The Danger
    The techniques about to be discussed are not monitored by PBP during compilation
    or execution of the program. This means that you can write some crazy code that
    could totally wreck the RAM on the PIC MCU. PBP won't warn you or generate an
    error message.

    The greatest opportunity for trouble lies in the fact that PBP doesn't monitor (isn't
    even aware) of array variable sizes. When you declare an array in PBP and specify
    a size, all that really happens is that PBP skips a number of RAM locations after the
    base variable name is allocated.

    Code:
    my_array VAR WORD[16]   ' Allocates "my_array" as two
                               bytes, then skips (reserves) a
                               block of 30 bytes in RAM
    Even if you blatantly write to a location that is beyond the size of an array you created,
    PBP won't complain.

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