I2CWRITE not writing anything on PIC18F45K80


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    453


    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

    The "complete" code is about 700 lines (and it is not complete yet)
    You just said...
    I just wrote another code, which simply reads values of array and writes data on 1602LCD.
    Issue still exists
    That's the code that's 700 lines?

    If you're having issues then continuing to add more code isn't going to help.
    You should stop, and start trimming things down bit by bit until it starts working.
    Then you'll know what to look at.

    While compiler and chip issues are always a possibility, there's a much better chance you're just doing something wrong.

  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

    No that different code
    Now I'm back to "big" code.

    I'm trying now to isolate the problem and writing all from the scratch, part by part, verifying.

  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

    What I 100% figured out, by writing the small code is the 18F issue with ST7920 LCD.
    When I turn on the graphic mode, by sending LCDOUT $FE,$2E , there are high chances that random character in text mode will be displayed in top left corner.
    I tried adjusting timings and OSC settings - no change. Same code, same PCB, same LCD - no issues with 16F1939.

  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

    OK here it is. Here's a code.
    It works properly only on first run after the flashing the code. If I unplug the power, next it will run with the same error.
    The left picture shows correct result, how display should look, and right picture shows how it looks after cycling the power.

    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
    
    
    '''''''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
    
    
    '----------- 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
                                         '1234567890ABCDEF
    arraywrite topline, ["1234567890ABCDEF"]
    arraywrite botline, ["GHIJKLMNOPQRSTUV"]
    for c=0 to 24 step 8
    gosub gcoder
    next
    astart=5
    aend=10
    arraywrite BOTLINE, ["SACDELI XAZI z  "]
    C=24
    GOSUB GCODER
    
    
    
    
    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 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
    Name:  1st.jpg
Views: 8908
Size:  77.7 KB Name:  2nd.jpg
Views: 8639
Size:  82.8 KB

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


    Did you find this post helpful? Yes | No

    Default Re: I2CWRITE not writing anything on PIC18F45K80

    The position of inversion depends on two variables, ASTART and AEND.
    They are assigned values of 5 and 10.
    On 1st run code works fine and inversion starts at 5th char and ends on 10th.
    But after power off and back on, seems like these two variables are not same any more.

  6. #6
    Join Date
    Aug 2011
    Posts
    453


    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

    The variables astart and aend are not assigned values until right before the last time gcoder is called.
    What do you expect them to be the first time the program runs since they are uninitialized?

  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

    "The last call" of gcoder is the code that makes that inversion, so variables are assigned before their use.

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