Problem in reading and writing internal eeprom


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2014
    Posts
    25

    Default Problem in reading and writing internal eeprom

    Iam not able to read & write internal eeprom Of 16f876A.
    My code is...


    DG1 VAR BYTE
    DG2 VAR BYTE
    DG3 VAR BYTE
    DIGIT VAR BYTE
    DG VAR BYTE
    COUNTT VAR BYTE
    CX VAR WORD
    NUMB VAR WORD
    N VAR WORD
    B1 VAR BYTE
    WORDVariable var WORD

    MemoryA DATA @0,0
    MemoryB DATA @0


    ADCON1=%00000111
    TRISA=0
    TRISB=%00111000

    TRISC=0

    PAUSE 2000

    NUMB=0
    N=NUMB
    GOSUB DIGITCALC 'SEGMENTS TO LIGHTUP FOR THE 3 DIGITS ARE FOUND
    '-------------------------------------------------------------------------
    MAIN:
    GOSUB DISPLAY
    'SCAN PUSHBUTTONS
    IF PORTB.3=1 THEN UP

    iF PORTB.5=1 THEN PromptLoop

    IF PORTB.4=1 THEN WRITC

    GOTO MAIN
    '-------------------------------------------------------------------------
    WRITC:
    WORDVariable=nUMB
    WRITE MemoryA,WORDVariable.HighByte
    WRITE MemoryB,WORDVariable.LowByte
    PAUSE 1000



    PromptLoop:

    READ MemoryA,WORDVariable.HighByte
    READ MemoryB,WORDVariable.LowByte

    GOSUB DIGITCALC
    '
    GOTO MAIN


    '_____________________________________
    UP:
    IF NUMB=999 THEN MAIN 'MAX LIMIT
    NUMB=NUMB+1
    N=NUMB
    GOSUB DIGITCALC 'GET NEW DATA FOR SEGMENTS
    GOTO MAIN
    '_____________________________________
    '_____________________________________
    DOWN:
    IF NUMB=0 THEN MAIN 'MIN LIMIT
    NUMB=NUMB-1
    N=NUMB
    GOSUB DIGITCALC
    GOTO MAIN
    '_____________________________________

    '_________________________________________________ _______________
    DISPLAY:
    'DATA FOR DG1,DG2,DG3 IS PUT ON PORTC AND THE CORRESPONDING
    'PINS ON PORTB TOGGLED
    'THIS IS DONE 100 TIMES
    FOR COUNTT=0 TO 99
    PORTC=DG1
    PORTB.2=1
    PAUSE 1
    PORTB.2=0
    PORTC=DG2
    PORTB.1=1
    PAUSE 1
    PORTB.1=0
    PORTC=DG3
    PORTB.0=1
    PAUSE 1
    PORTB.0=0
    NEXT COUNTT
    RETURN
    '_________________________________________________ _______________

    '_________________________________________________ _________________________
    DIGITCALC:
    'THIS ROUTINE BREAKS UP THE NUMBER INTO 3 DISTINCT PARTS - DG1,DG2,DG3
    'NOTICE THAT ANOTHER SUBROUTINE IS CALLED EACH TIME
    DIGIT=0
    LP1:
    IF N<100 THEN DS1
    N=N-100
    DIGIT=DIGIT+1
    GOTO LP1
    DS1:
    GOSUB FND
    DG1=DG

    DIGIT=0
    LP2:
    IF N<10 THEN DS2
    N=N-10
    DIGIT=DIGIT+1
    GOTO LP2
    DS2:
    GOSUB FND
    DG2=DG
    DIGIT=N
    GOSUB FND
    DG3=DG

    RETURN
    '_________________________________________________ _________________________

    '_________________________________________________ _________________________
    FND:
    'THIS ROUTINE IDENTIFIES THE SEGMENTS TO LIGHT UP
    '7 SEGMENTS WIRED UP AS FOLLOWS
    'A -PORTC.2
    'B -PORTC.3
    'C -PORTC.6
    'D -PORTC.5
    'E -PORTC.4
    'F -PORTC.1
    'G -PORTC.0

    FND0:
    IF DIGIT>0 THEN FND1
    DG=$7E '%0111 1110
    GOTO FNDEND
    FND1:
    IF DIGIT>1 THEN FND2
    DG=$48 '%0100 1000
    GOTO FNDEND
    FND2:
    IF DIGIT>2 THEN FND3
    DG=$3D '%0011 1101
    GOTO FNDEND
    FND3:
    IF DIGIT>3 THEN FND4
    DG=$6D '%0110 1101
    GOTO FNDEND
    FND4:
    IF DIGIT>4 THEN FND5
    DG=$4B '%0100 0011
    GOTO FNDEND
    FND5:
    IF DIGIT>5 THEN FND6
    DG=$67 '%0110 0111
    GOTO FNDEND
    FND6:
    IF DIGIT>6 THEN FND7
    DG=$77 '%0111 0111
    GOTO FNDEND
    FND7:
    IF DIGIT>7 THEN FND8
    DG=$4C '%0100 1100
    GOTO FNDEND
    FND8:
    IF DIGIT>8 THEN FND9
    DG=$7F '%0111 1111
    GOTO FNDEND
    FND9:
    DG=$6F '%0110 1111
    FNDEND:
    RETURN
    '_________________________________________________ _________________________

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Problem in reading and writing internal eeprom

    I'm not sure what version of PicBasic you are using, but this:

    5.93. WRITE

    WRITE Address,{WORD}{LONG}Value {,Value...}

    Write byte, word or long (if PBPL used) Values to the on-chip EEPROM at the specified Address. This instruction may only be used with a PIC MCU that has an on-chip EEPROM data area such as the PIC12F683, PIC16F84 and the 16F87x(A) series.

    I would begin with a short, simple demonstration of a BYTE read and write operation based on simple syntax: WRITE ADDRESS, VARIABLE. Use READ ADDRESS, VARIABLE to retrieve the variable. Presuming then that your version of PicBasic is the same as mine, WRITE ADDRESS, WORD VARIABLE will write a word and READ ADDRESS, WORD VARIABLE will retrieve it. If this fails then: WRITE ADDRESS, VARIABLE.highbyte and WRITE ADDRESS + 1, VARIABLE.lowbyte - similar syntax with READ to retrieve the value. Once reads and writes are working, you'll be able to replace the code in your longer program without issue.

    Disclaimer: I'm a noob with no WORKING code to test reading or writing WORD variables, but I am reading and writing bytes successfully with the examples posted and the manual seems to make clear how WORDS may be handled.

    In any case it will much easier to troubleshoot a short, simple demonstration program - with comments indicating the version of PicBasic you are using and complete configuration included.

  3. #3
    Join Date
    Sep 2014
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Problem in reading and writing internal eeprom

    Please give me an example.

  4. #4
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Problem in reading and writing internal eeprom

    i uses pbp3 so not sure about other versions but

    option 1 - data command - for loading values into a eeprom location - used when preloading when the device is programed

    example
    Code:
    '----------------- EEprom pre-programmed dephalts Memory Map --------------------- ^
    
        DATA @$00,5                ' 0.  Location 0 , Program location 0 with Firmware Version#: 05= Version 0.5
        data @$01,0                ' 1.  Location 1 , Program Location 1 with Hardware version # 0.0

    option 2; Write / read command

    done for changeing eeprom bytes as required in program
    Code:
    write $01, $10 ' write location 1 , value of 10 hex 
    
    for x = 1 to 10  ' clear ( write 0 value ) to locations 1 - 10 
    
        write  x , 0
    
    next x 
    
    
    
    read $01 , X              '  read the value at location 1 in eeprom to varable x 
    
    for x = 1 to 10           ' read locations 1 - 10  values into Y array 
    
    read x, y[x] 
    
    next x
    very straight forward for EEprom based on PIC chips

Similar Threads

  1. Need help writing/reading from 16F819 internal EEPROM.
    By Navaidstech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th February 2010, 01:25
  2. Writing, Reading from Internal PIC EEPROM
    By NO2K in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th October 2007, 00:35
  3. reading, writing, and displaying from eeprom
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th January 2006, 22:05
  4. 93c46 Eeprom Writing/reading Help
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th June 2005, 20:40
  5. Writing / Reading EEPROM 24LC256 Problem
    By schmoddel in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th February 2004, 18:55

Members who have read this thread : 2

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