Where is the problem?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2005
    Posts
    49

    Question Where is the problem?

    I was trying to use internal eeprom of the pic 16F628.My experiment is trying to write values of a counter.When i remove the battery i want to see the last value of the counter.But always give me something difrent.Here re my codes

    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    LCDOut $Fe,1
    LCDOut "counter"
    LCDOut $Fe,$C0
    LCDOut "total="
    time VAR BYTE
    time =0
    counter VAR WORD
    counter =0
    LCDOut $Fe,1
    LCDOut "Counting"
    LCDOut $Fe,$C0
    LCDOut "total=",#counter
    loop:
    Pause 2000
    counter=counter + 1
    time =time +1
    IF time=10 Then GoTo total_show
    LCDOut $Fe,1
    LCDOut "Counter"
    LCDOut $Fe,$C0
    LCDOut "total=",#counter
    Write 10,counter
    GoTo loop
    total_show:
    Read 10,counter
    LCDOut $Fe,1
    LCDOut "Counter"
    LCDOut $Fe,$C0
    LCDOut "total=",#counter
    time=0
    GoTo loop
    End
    '''''''''''''''''''''''''''''''''''''''''
    Each 10 seconds LCD shows the total but when i remove the battery and start pic again , i can't see the total i always see another numbers.
    Asking is not a shame but not learning is a SHAME!!!

  2. #2
    Join Date
    Mar 2005
    Location
    Denmark
    Posts
    31


    Did you find this post helpful? Yes | No

    Post

    Hi SuB-ZeRo,

    I'm a beginner to PBP but I think that you are trying to write a WORD into a BYTE.
    If I look in the PBP manuel under WRITE there is this example:

    w var word
    WRITE 0,w.BYTE0
    WRITE 1,w.BYTE1

    Regards
    Gert K.
    *Let's do it*

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    look at this part located at the top
    Code:
    time VAR BYTE
    time =0
    counter VAR WORD
    counter =0
    replace your counter=0 by read 10, counter
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Question I resolved the problem but......

    Yes i change the codes and now i can write to eeprom.The new problem is counting can't go more than 255 whats the problem?

    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    sayac var word
    b1 var byte
    sayac =0
    lcd_goster:
    read 5,sayac
    lcdout $Fe,1
    Lcdout "sayac"
    LCDOut $Fe,$C0
    lcdout "total=",#sayac
    loop:
    button porta.4 ,0,0,0,b1,1,ok
    goto loop:
    ok:
    data @5,0
    read 5,sayac
    sayac=sayac+1
    write 5,sayac
    goto lcd_goster
    end
    Asking is not a shame but not learning is a SHAME!!!

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i'm not sure on how PBP handle WRITE when using a WORD sized var but i think Sharky was right on his previous post.

    SO what about using something like...

    Code:
    MyVar      var word
    AnotherVar var word
    
    myvar=12345
        
        Write 0,Myvar.highbyte
        write 1,myvar.lowbyte
            ' code
            ' code
            ' code
            ' code
        Read 0,anothervar.highbyte
        read 1,anothervar.lowbyte
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Smile Thanks to all...

    Ok! I resolved the problem by u re suggests.Here re the working codes.
    I am always wrting the codes coz if somebody has or will the same problem they can find the way how to resolve by working codes

    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    sayac var word
    sayac=0
    sayac_goster var word
    sayac_goster = 0
    b1 var byte
    lcd_goster:
    read 5,sayac_goster.highbyte
    read 6,sayac_goster.lowbyte
    lcdout $Fe,1
    Lcdout "sayac"
    LCDOut $Fe,$C0
    lcdout "total=",#sayac_goster
    loop:
    button porta.4 ,0,0,0,b1,1,ok
    goto loop:
    ok:
    data @5,0
    data @6,0
    read 5,sayac_goster.highbyte
    read 6,sayac_goster.lowbyte
    sayac_goster = sayac_goster + 1
    sayac=sayac_goster
    write 5,sayac.highbyte
    write 6,sayac.lowbyte
    goto lcd_goster
    end
    Asking is not a shame but not learning is a SHAME!!!

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 19:52
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. Microcode Studio 18f2455 problem?????
    By volkan in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 21st May 2007, 21:04
  4. Hardware problem or what ?
    By Steve S. in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th March 2007, 21:39
  5. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59

Members who have read this thread : 0

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