1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Read/write serial Eeprom 24AA16

Discussion in 'Oshonsoft' started by revave, Sep 13, 2014.

  1. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello,

    For an appplication i need an external memory to store some data.
    Therefore i will use an Eeprom from microchip, type 24AA16, which can be written and read by using the I2C protocol.

    In a program i try to write data to different locations of the memory (Eeprom) (8 levels possible, selected by bit 1, 2 and 3 of the controlbyte).
    This is done by using some lookup tables.

    As a test i will read back the complete memory and write it to hyperterminal (using serout).
    Well, as you can imagine this is going wrong. I think the problem has to be something to do with the I2CRead instruction.

    Reading the datasheet i found some rules.
    - The controlbyte has the format 1010ABCx. A, B and C are selectionbits for the level (block) of the memory (8 blocks of 256 byte available). x is used for write or read action (will be controlled by the I2CWrite and I2CRead instructions).
    - The I2C write sequense seems to be the same as used in the I2CWrite instruction (see image 1, byte write)
    - The I2C read sequence is different and i think the problem can be found here. For random reading (this is what i want to use) the internal Eeprom addresscounter must be set first. This is done with a write instruction. Then - without a stop - a read instruction is folowing to get the data. (see image 2, random read)

    So, it seems to me that i have to write a special routine for reading out the Eeprom by using the lower level I2C instructions.
    I tried to do this, but do not know how to handle the acknowledge bit in case of reading out one byte per instruction.

    In the sourcecode below, i've tried to use the normal I2CRead instruction, but that doesn't work. Also the readout of the Eeprom is attached as txt-file.

    Hopefully someone has some experiance with this type of Eeprom...
     

    Attached Files:

  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,157
    Likes:
    907
    Location:
    Rochdale UK
    Oshonsoft has an automatic word / byte I2C address... If you declared

    Dim addr As Byte
    Dim data As Byte

    Then it uses a byte address... The 24AA16 needs a word address.... so

    Dim addr As Word
    Dim data As Byte
     
  3. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello Ian,

    Below the description from the datasheet.
    It says that the word adres is a byte. But i can check it in practice.

    And how about the read action?



    4.1 WRITE OPERATION
    Byte Write Following the Start condition from the master, the device code (4 bits), the block address (3 bits) and the R/W bit, which is a logic-low, is placed onto the bus by the master transmitter. This indicates to the addressed slave receiver that a byte with a word address will follow once it has generated an Acknowledge bit during the ninth clock cycle. Therefore, the next byte transmitted by the master is the word address and will be written into the address pointer of the 24XX16. After receiving another Acknowledge signal from the 24XX16, the master device will transmit the data word to be written into the addressed memory location. The 24XX16 acknowledges again and the master generates a Stop condition. This initiates the internal write cycle and, during this time, the 24XX16 will not generate Acknowledge signals (Figure4-1).
     
    Last edited: Sep 13, 2014
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,157
    Likes:
    907
    Location:
    Rochdale UK

    Two things...

    First the write process isn't writing properly as you are writing one byte at a time and not waiting 10mS for the chip to do its housekeeping..

    IF you do the total write time of all your data will be around 10 seconds...

    Secondly! I cant seem to get the I2CREAD working either.... I'll work on it to see why...
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,157
    Likes:
    907
    Location:
    Rochdale UK
    aha!!! Found it....

    If you are using the weak pullups then you MUST disable them and use external resistors....

    To speed things up, you can use page write to get the values in.... To use page writes you really need to use low level routines... There is an example in the help file....
     
  7. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hi Ian,

    I am using 10k pull-up resistors.
    Some ports (RA2 and RA3) need a weak pullup and will be used for an interrupt to get the device out his sleepmode (not a part of this program yet).

    I can remove the waiting time to speed it up.
    I have no experiance with the lower level I2C instructions, so at this time i try tot use the standard instructions.
    that gives me the problem with read out. For random readout i cannot use the standard routine, because the write/read format is not compatible with the standard instructions.
    if i use I2CWrite1 directly followed with I2CRead, then i am creating a stopbit between the two instructions..
     
    Last edited: Sep 13, 2014
  8. languer

    languer Active Member

    Joined:
    Oct 26, 2010
    Messages:
    193
    Likes:
    25
    Location:
    Arizona
    The snippets of code below should provide a framework to fill the entire EEP using single byte writes, and retrieve the entire contents using single byte reads. Haven't had a chance to check it out though (but I've used similar architecture to do "in-house" endurance tests of EEPs).

    Generic code for sample write:
    Code (text):
    'WRITE TO EEP
    For block = 0 To 14 Step 2
        block_addr = 0xa0 + block
        For addr = 0 To 254 Step 1
            I2CWrite sda, scl, block_addr, addr, addr
            WaitMs 5
        Next addr
    Next block
    Generic code for sample read:
    Code (text):
    'READ FROM EEP
    For block = 1 To 15 Step 2
        block_addr = 0xa0 + block
        For addr = 0 To 254 Step 1
            I2CRead sda, scl, block_addr, addr, data
            Serout portc.3, 9600, #data, ";"
        Next addr
        Serout portc.3, 9600, CrLf
    Next block
    BTW, addr, block_addr, and data should be defined as BYTE
     
    Last edited: Sep 13, 2014
  9. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hi Ian,

    I've tried your code and have attached the program and the readout from hyperterminal.
    As you can see, the internal addrescounter of the eeprom is counting up twice at every read from the PIC.
    For a try i've changed the addr to datatype Word, but that doesn't gave a good solution.
    Also the I2CRead1 instruction doesn't work.

    For readout:
    How can I build the code with lower level instructions - without a stop in the middle - that the format seems like:
    S-1010xxx0-Ack-addr-Ack-S1010xxx1-Ack-data-NoAck-P

    I am thinking about (for the first block)......

    I2CPrepare sda, scl
    I2CStart
    I2CSend 0xa0
    I2CRecA ???
    I2CSend addr
    I2CRecA ???
    I2CSend 0xa1
    I2CRecA ???
    I2CRecN data
    I2CStop

    I do not know how the instructions I2CRecA and I2CRecN are working.
    For I2CRecA tmp
    Does this mean that the program is waiting for an acknowledge AFTER sending tmp?


    For I2CRecN tmp
    Does this mean that the program doesn't have to wait for an acknowledge BEFORE reading tmp?

    Oh, and thank you for your help for sofar :)
     

    Attached Files:

    Last edited: Sep 14, 2014
  10. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,157
    Likes:
    907
    Location:
    Rochdale UK
    I didn't post any code..... I just place a 5mS delay in your write routines and disabled the WPUA reg...

    The code works fine for me.....

    The only recommendation was to page write the bytes in to save a whole lot of time...
     
  11. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Ok, but if i want to use page write and page read then i have to understand the loverlevel instructions.

    Can you tell me how the instructions I2CRecA and I2CRecN are working? There's no clear explanation in the Oshonsoft reference manual..
     
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,157
    Likes:
    907
    Location:
    Rochdale UK
    The two functions are I2C read ack and I2C read nack When you ask an I2C device to do anything it replies with ACK or NACK to signal that your request has been delt with..

    Similarly when you are reading you must respond with NACK to continue or ACK to finish correspondence...
     
  13. languer

    languer Active Member

    Joined:
    Oct 26, 2010
    Messages:
    193
    Likes:
    25
    Location:
    Arizona
    I still think the stock functions should work .

    Following is tested code. Unfortunately it is tested on 24AA256 because that is what I have on hand.
    Code (text):
    'Test Code to Read/Write to 24AA256 with 12F683

    'General Configuration
        Define CONF_WORD = 0x33c4
        Define CLOCK_FREQUENCY = 8
        OSCCON = 0x71

    'Debug Option
        Dim debug As Bit
        debug = True
        debug = False

    'Variable Declarations
        Dim control As Byte
        Dim addr As Word
        Dim data As Byte
        Dim _true As Bit
        Dim _false As Bit
        _true = True
        _false = False

    'IO Definitions
        Const _trisio = %11111110
        Symbol tx232 = GP0
        Symbol scl = GP4
        Symbol sda = GP5

    main:
        AllDigital
        TRISIO = _trisio
        If debug = _false Then
            WaitMs 2500
            Serout tx232, 9600, "I2C EEP Write/Read", CrLf
        Endif
        control = 0xa0
        'WRITE TO EEP
        If debug = _false Then
            Serout tx232, 9600, "Writing...", CrLf
        Endif
        For addr = 0 To 254 Step 1
            data = addr.LB
            I2CWrite sda, scl, control, addr, data
            If debug = _false Then
                WaitMs 5
            Endif
        Next addr

        'READ FROM EEP
        While _true
            If debug = _false Then
                Serout tx232, 9600, "Reading...", CrLf
            Endif
            For addr = 0 To 254 Step 1
                I2CRead sda, scl, control, addr, data
                Serout tx232, 9600, #data, ";"
            Next addr
            Serout tx232, 9600, CrLf, CrLf, CrLf
        Wend
    End
    RS232 output:
     
    Last edited: Sep 15, 2014
  14. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,180
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    Look at this fast buffer write using the Oshonsoft Basic , for the IDE 25C256 the EEPROM's internal buffer is 63 bytes long.
    I have shown a double write 0 to 63 and 64 to 127.
    Modify as required to suit your EEPROM

    Eric

    Code (text):

    'ext eeprom fast write/read
    'modified from a web extract.
    '18f2550

    Define CONFIG1L = 0x00
    Define CONFIG1H = 0x0e
    Define CONFIG2L = 0x1e
    Define CONFIG2H = 0x00
    Define CONFIG3L = 0x00
    Define CONFIG3H = 0x83
    Define CONFIG4L = 0x80
    Define CONFIG4H = 0x00
    Define CONFIG5L = 0x0f
    Define CONFIG5H = 0xc0
    Define CONFIG6L = 0x0f
    Define CONFIG6H = 0xe0
    Define CONFIG7L = 0x0f
    Define CONFIG7H = 0x40


    Define SIMULATION_WAITMS_VALUE = 1' make this =0 for a PIC

    Dim readbfr(63) As Byte  'test only
    Dim addr As Word
    Dim loc As Byte
    Dim data As Byte

    'define the SDA and SCL channels
    Symbol sda = PORTB.6
    Symbol scl = PORTB.7

    addr = 0  '1st eeprom mem location

    OSCCON = %01110000  '8MHz internal * 4 PLL

    'enable SDA and SCL channels
    I2CPrepare sda, scl
    I2CStart

    I2CSend 0xa2  'control byte
    'send the mem start address
    I2CSend addr.HB
    I2CSend addr.LB

    'load the EEPROM's buffer, note 24C256 in the IDE has a 64 Byte buffer, check your EEPROM type
    For loc = 0 To 63  'page 0
    data = loc
    I2CSend data
    Next loc
    I2CStop  'force the EEPROM to write the EEPROM's buffer to the EEPROM's memory
    WaitMs 5

    'next page 1
    addr = 64
    I2CStart
    I2CSend 0xa2  'control byte
    'send the mem start address
    I2CSend addr.HB
    I2CSend addr.LB

    For loc = 0 To 63
    data = loc
    I2CSend data
    Next loc
    I2CStop  'force the EEPROM to write the EEPROM's buffer to the EEPROM's memory

    End
     
     
  15. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello,

    So, finally it works. After a few experiments every addres in every block can be written and read out.
    The code needs a minimum delay of 5 ms after every write and read action. If a shorter delay or no delay is programmed the read out goes wrong.

    But, during most of the test last days i've made the mistake that the instruction "Define SIMULATION_WAITMS_VALUE = 1" was active. So, this gave me wrong timing in the PIC with as result a terrible working of the I2C function.

    Also some lookup tables were not correct programmed (see first .bas file). In every for loop - not started with zero - the pointer to the table was wrong.
    Below the final (test)code and read out from hyperterminal.
    Code (text):
    'PIC16F636;  programm to fill eeprom (24AA16) with data
     
    Define CLOCK_FREQUENCY = 4
    Define CONFIG = 0x30c4
    'OSCCON.IRCF2 = False
    'OSCCON.IRCF1 = False
    'OSCCON.IRCF0 = False
     
    AllDigital
    'Define SIMULATION_WAITMS_VALUE = 1
    Symbol scl = PORTA.4
    Symbol sda = PORTA.5
    Define I2CREAD_DELAYUS = 0
    ConfigPin PORTC.4 = Output
    PORTC.4 = False
    Dim ctd As Bit
    Dim addr As Byte
    Dim data As Byte
    Dim block As Byte
    Dim block_addr As Byte
     
    ctd = True
     
    'WRITE TO EEP
    For block = 0 To 14 Step 2
    block_addr = block + 0xa0
        For addr = 0 To 255 Step 1
            If ctd Then
                data = addr
            Else
                data = 255 - addr
            Endif
        I2CWrite sda, scl, block_addr, addr, data
        WaitMs 5
        Next addr
     
        Toggle ctd
    Next block
     
     
     
    'READ FROM EEP
    For block = 0 To 14 Step 2
    block_addr = block + 0xa0
    Serout PORTC.3, 9600, CrLf, CrLf, #block, CrLf, CrLf
        For addr = 0 To 255 Step 1
            I2CRead sda, scl, block_addr, addr, data
            WaitMs 5
            Serout PORTC.3, 9600, #data, ";"
        Next addr
    Next block
     
     
    main:
    PORTC.4 = True  'indication writing and reading done
    Goto main
    End      
    and below the read out..
    Code (text):

     
    0
     
    0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;                                                                        
    30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56                                                                        
    ;57;58;59;60;61;62;63;64;65;66;67;68;69;70;71;72;73;74;75;76;77;78;79;80;81;82;8                                                                        
    3;84;85;86;87;88;89;90;91;92;93;94;95;96;97;98;99;100;101;102;103;104;105;106;10                                                                        
    7;108;109;110;111;112;113;114;115;116;117;118;119;120;121;122;123;124;125;126;12                                                                        
    7;128;129;130;131;132;133;134;135;136;137;138;139;140;141;142;143;144;145;146;14                                                                        
    7;148;149;150;151;152;153;154;155;156;157;158;159;160;161;162;163;164;165;166;16                                                                        
    7;168;169;170;171;172;173;174;175;176;177;178;179;180;181;182;183;184;185;186;18                                                                        
    7;188;189;190;191;192;193;194;195;196;197;198;199;200;201;202;203;204;205;206;20                                                                        
    7;208;209;210;211;212;213;214;215;216;217;218;219;220;221;222;223;224;225;226;22                                                                        
    7;228;229;230;231;232;233;234;235;236;237;238;239;240;241;242;243;244;245;246;24                                                                        
    7;248;249;250;251;252;253;254;255;                          
     
    2
     
    255;254;253;252;251;250;249;248;247;246;245;244;243;242;241;240;239;238;2                                                                
    235;234;233;232;231;230;229;228;227;226;225;224;223;222;221;220;219;218;217;216;                                                                        
    215;214;213;212;211;210;209;208;207;206;205;204;203;202;201;200;199;198;197;196;                                                                        
    195;194;193;192;191;190;189;188;187;186;185;184;183;182;181;180;179;178;177;176;                                                                        
    175;174;173;172;171;170;169;168;167;166;165;164;163;162;161;160;159;158;157;156;                                                                        
    155;154;153;152;151;150;149;148;147;146;145;144;143;142;141;140;139;138;137;136;                                                                        
    135;134;133;132;131;130;129;128;127;126;125;124;123;122;121;120;119;118;117;116;                                                                        
    115;114;113;112;111;110;109;108;107;106;105;104;103;102;101;100;99;98;97;96;95;9                                                                        
    4;93;92;91;90;89;88;87;86;85;84;83;82;81;80;79;78;77;76;75;74;73;72;71;70;69;68;                                                                        
    67;66;65;64;63;62;61;60;59;58;57;56;55;54;53;52;51;50;49;48;47;46;45;44;43;42;41                                                                        
    ;40;39;38;37;36;35;34;33;32;31;30;29;28;27;26;25;24;23;22;21;20;19;18;17;16;15;1                                                                        
    4;13;12;11;10;9;8;7;6;5;4;3;2;1;0;                          
     
    4
     
    0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;                                                                        
    30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;5                                                                
    ;57;58;59;60;61;62;63;64;65;66;67;68;69;70;71;72;73;74;75;76;77;78;79;80;81;82;8                                                                        
    3;84;85;86;87;88;89;90;91;92;93;94;95;96;97;98;99;100;101;102;103;104;105;106;10                                                                        
    7;108;109;110;111;112;113;114;115;116;117;118;119;120;121;122;123;124;125;126;12                                                                        
    7;128;129;130;131;132;133;134;135;136;137;138;139;140;141;142;143;144;145;146;14                                                                        
    7;148;149;150;151;152;153;154;155;156;157;158;159;160;161;162;163;164;165;166;16                                                                        
    7;168;169;170;171;172;173;174;175;176;177;178;179;180;181;182;183;184;185;186;18                                                                        
    7;188;189;190;191;192;193;194;195;196;197;198;199;200;201;202;203;204;205;206;20                                                                        
    7;208;209;210;211;212;213;214;215;216;217;218;219;220;221;222;223;224;225;226;22                                                                        
    7;228;229;230;231;232;233;234;235;236;237;238;239;240;241;242;243;244;245;246;24                                                                        
    7;248;249;250;251;252;253;254;255;                          
     
    6
     
    255;254;253;252;251;250;249;248;247;246;245;244;243;242;241;240;239;238;237;236;                                                                        
    235;234;233;232;231;230;229;228;227;226;225;224;223;222;221;220;219;218;217;216;                                                                        
    215;214;213;212;211;210;209;208;207;206;205;204;203;202;201;200;199;198;1                                                                
    195;194;193;192;191;190;189;188;187;186;185;184;183;182;181;180;179;178;177;176;                                                                        
    175;174;173;172;171;170;169;168;167;166;165;164;163;162;161;160;159;158;157;156;                                                                        
    155;154;153;152;151;150;149;148;147;146;145;144;143;142;141;140;139;138;137;136;                                                                        
    135;134;133;132;131;130;129;128;127;126;125;124;123;122;121;120;119;118;117;116;                                                                        
    115;114;113;112;111;110;109;108;107;106;105;104;103;102;101;100;99;98;97;96;95;9                                                                        
    4;93;92;91;90;89;88;87;86;85;84;83;82;81;80;79;78;77;76;75;74;73;72;71;70;69;68;                                                                        
    67;66;65;64;63;62;61;60;59;58;57;56;55;54;53;52;51;50;49;48;47;46;45;44;43;42;41                                                                        
    ;40;39;38;37;36;35;34;33;32;31;30;29;28;27;26;25;24;23;22;21;20;19;18;17;16;15;1                                                                        
    4;13;12;11;10;9;8;7;6;5;4;3;2;1;0;                          
     
    8
     
    0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;                                                                        
    30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56                                                                        
    ;57;58;59;60;61;62;63;64;65;66;67;68;69;70;71;72;73;74;75;76;77;78;79;80;81;82;8                                                                        
    3;84;85;86;87;88;89;90;91;92;93;94;95;96;97;98;99;100;101;102;103;104;105                                                                
    7;108;109;110;111;112;113;114;115;116;117;118;119;120;121;122;123;124;125;126;12                                                                        
    7;128;129;130;131;132;133;134;135;136;137;138;139;140;141;142;143;144;145;146;14                                                                        
    7;148;149;150;151;152;153;154;155;156;157;158;159;160;161;162;163;164;165;166;16                                                                        
    7;168;169;170;171;172;173;174;175;176;177;178;179;180;181;182;183;184;185;186;18                                                                        
    7;188;189;190;191;192;193;194;195;196;197;198;199;200;201;202;203;204;205;206;20                                                                        
    7;208;209;210;211;212;213;214;215;216;217;218;219;220;221;222;223;224;225;226;22                                                                        
    7;228;229;230;231;232;233;234;235;236;237;238;239;240;241;242;243;244;245;246;24                                                                        
    7;248;249;250;251;252;253;254;255;                          
     
    10
     
    255;254;253;252;251;250;249;248;247;246;245;244;243;242;241;240;239;238;237;236;                                                                        
    235;234;233;232;231;230;229;228;227;226;225;224;223;222;221;220;219;218;217;216;                                                                        
    215;214;213;212;211;210;209;208;207;206;205;204;203;202;201;200;199;198;197;196;                                                                        
    195;194;193;192;191;190;189;188;187;186;185;184;183;182;181;180;179;178;177;176;                                                                        
    175;174;173;172;171;170;169;168;167;166;165;164;163;162;161;160;159;158;                                                              
    155;154;153;152;151;150;149;148;147;146;145;144;143;142;141;140;139;138;137;136;                                                                        
    135;134;133;132;131;130;129;128;127;126;125;124;123;122;121;120;119;118;117;116;                                                                        
    115;114;113;112;111;110;109;108;107;106;105;104;103;102;101;100;99;98;97;96;95;9                                                                        
    4;93;92;91;90;89;88;87;86;85;84;83;82;81;80;79;78;77;76;75;74;73;72;71;70;69;68;                                                                        
    67;66;65;64;63;62;61;60;59;58;57;56;55;54;53;52;51;50;49;48;47;46;45;44;43;42;41                                                                        
    ;40;39;38;37;36;35;34;33;32;31;30;29;28;27;26;25;24;23;22;21;20;19;18;17;16;15;1                                                                        
    4;13;12;11;10;9;8;7;6;5;4;3;2                    
     
    12
     
    0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;                                                                        
    30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56                                                                        
    ;57;58;59;60;61;62;63;64;65;66;67;68;69;70;71;72;73;74;75;76;77;78;79;80;81;82;8
    3;84;85;86;87;88;89;90;91;92;93;94;95;96;97;98;99;100;101;102;103;104;105;106;10
    7;108;109;110;111;112;113;114;115;116;117;118;119;120;121;122;123;124;125;126;12
    7;128;129;130;131;132;133;134;135;136;137;138;139;140;141;142;143;144;145;146;14
    7;148;149;150;151;152;153;154;155;156;157;158;159;160;161;162;163;164;165;166;16
    7;168;169;170;171;172;173;174;175;176;177;178;179;180;181;182;183;184;185;186;18
    7;188;189;190;191;192;193;194;195;196;197;198;199;200;201;202;203;204;205;206;20
    7;208;209;210;211;212;213;214;215;216;217;218;219;220;221;222;223;224;225;226;22
    7;228;229;230;231;232;233;234;235;236;237;238;239;240;241;242;243;244;245;246;24
    7;248;249;250;251;252;253;254;255;
     
    14
     
    255;254;253;252;251;250;249;248;247;246;245;244;243;242;241;240;239;238;237;236;
    235;234;233;232;231;230;229;228;227;226;225;224;223;222;221;220;219;218;217;216;
    215;214;213;212;211;210;209;208;207;206;205;204;203;202;201;200;199;198;197;196;
    195;194;193;192;191;190;189;188;187;186;185;184;183;182;181;180;179;178;177;176;
    175;174;173;172;171;170;169;168;167;166;165;164;163;162;161;160;159;158;157;156;
    155;154;153;152;151;150;149;148;147;146;145;144;143;142;141;140;139;138;137;136;
    135;134;133;132;131;130;129;128;127;126;125;124;123;122;121;120;119;118;117;116;
    115;114;113;112;111;110;109;108;107;106;105;104;103;102;101;100;99;98;97;96;95;9
    4;93;92;91;90;89;88;87;86;85;84;83;82;81;80;79;78;77;76;75;74;73;72;71;70;69;68;
    67;66;65;64;63;62;61;60;59;58;57;56;55;54;53;52;51;50;49;48;47;46;45;44;43;42;41
    ;40;39;38;37;36;35;34;33;32;31;30;29;28;27;26;25;24;23;22;21;20;19;18;17;16;15;1
    4;13;12;11;10;9;8;7;6;5;4;3;2;1;0;

    And finally the code with the (corrected) lookup tables and working I2C. :)
    Code (text):
    'PIC16F636;  programm to fill eeprom (24AA16) with data
    'Block 0
    'addr 0..240 reserved for character set
    'Block 1
    'addr 0..240 reserved for character set
    'Block 2
    'addr 0..60 reserved for character set
    'Block 3
    'addr 0..84 reserved for text "CV-CONTROL"
    'addr 100..118 reserved for text "SET"
    'addr 120.150 reserved for text "START"
    'Block 4
    'addr 0..84 reserved for text "PROG:   min."
    'addr 100..105 reserved for flame quadrant 1
    'addr 110..115 reserved for flame quadrant 1
    'addr 120..125 reserved for flame quadrant 1
    'addr 130..135 reserved for flame quadrant 1
    'addr 140..152 reserved for batt symbol
    Define CLOCK_FREQUENCY = 4
    Define CONFIG = 0x30c4
    'OSCCON.IRCF2 = False
    'OSCCON.IRCF1 = False
    'OSCCON.IRCF0 = False
    AllDigital
    'Define SIMULATION_WAITMS_VALUE = 1
    Symbol scl = PORTA.4
    Symbol sda = PORTA.5
    ConfigPin PORTC.4 = Output
    Dim addr As Byte
    Dim data As Byte
    Dim look As Byte
    Dim i As Byte
    Dim a As Byte
    Dim t As Byte
     
     
    'WRITE DATA INTO EEPROM 24AA16
     
    'first part of characterset
    For addr = 0 To 240 Step 1  'van 0x20 t/m 0x47 (32 t/m 71)
        data = LookUp(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14, 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12, 0x00, 0xc4, 0xc8, 0x10, 0x26, 0x46, 0x00, 0x36, 0x49, 0x55, 0x22, 0x50, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00, 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00, 0x00, 0x14, 0x08, 0x3e, 0x08, 0x14, 0x00, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x00, 0x00, 0x00, 0x50, 0x30, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x00, 0x42, 0x61, 0x51, 0x49, 0x46, 0x00, 0x21, 0x41, 0x45, 0x4b, 0x31, 0x00, 0x18, 0x14, 0x12, 0x7f, 0x10, 0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30, 0x00, 0x01, 0x71, 0x09, 0x05, 0x03, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x06, 0x49, 0x49, 0x29, 0x1e, 0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x56, 0x36, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x02, 0x01, 0x51, 0x09, 0x06, 0x00, 0x32, 0x49, 0x59, 0x51, 0x3e, 0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e, 0x00, 0x7f, 0x49, 0x49, 0x49, 0x36, 0x00, 0x3e, 0x41, 0x41, 0x41, 0x22, 0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c, 0x00, 0x7f, 0x49, 0x49, 0x49, 0x41, 0x00, 0x7f, 0x09, 0x09, 0x09, 0x01, 0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a, 0x00), addr
        I2CWrite sda, scl, 0xa0, addr, data
        WaitMs 10
    Next addr
     
    'second part of characterset
    For addr = 0 To 240 Step 1  'van 0x48 t/m 0x6F (72 t/m 111)
    data = LookUp(0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00, 0x00, 0x41, 0x7f, 0x41, 0x00, 0x00, 0x20, 0x40, 0x41, 0x3f, 0x01, 0x00, 0x7f, 0x08, 0x14, 0x22, 0x41, 0x00, 0x7f, 0x40, 0x40, 0x40, 0x40, 0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f, 0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f, 0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00, 0x7f, 0x09, 0x09, 0x09, 0x06, 0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e, 0x00, 0x7f, 0x09, 0x19, 0x29, 0x46, 0x00, 0x46, 0x49, 0x49, 0x49, 0x31, 0x00, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f, 0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f, 0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f, 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x07, 0x08, 0x70, 0x08, 0x07, 0x00, 0x61, 0x51, 0x49, 0x45, 0x43, 0x00, 0x00, 0x7f, 0x41, 0x41, 0x00, 0x00, 0x55, 0x2a, 0x55, 0x2a, 0x55, 0x00, 0x00, 0x41, 0x41, 0x7f, 0x00, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 0x00, 0x7f, 0x48, 0x44, 0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0x20, 0x00, 0x38, 0x44, 0x44, 0x48, 0x7f, 0x00, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x08, 0x7e, 0x09, 0x01, 0x02, 0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e, 0x00, 0x7f, 0x08, 0x04, 0x04, 0x78, 0x00, 0x00, 0x44, 0x7d, 0x40, 0x00, 0x00, 0x20, 0x40, 0x44, 0x3d, 0x00, 0x00, 0x7f, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x41, 0x7f, 0x40, 0x00, 0x00, 0x7c, 0x04, 0x18, 0x04, 0x78, 0x00, 0x7c, 0x08, 0x04, 0x04, 0x78, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00), addr
        I2CWrite sda, scl, 0xa2, addr, data
        WaitMs 10
    Next addr
     
    'third part of characterset
    For addr = 0 To 60 Step 1  'van 0x70 t/m 0x7A (112 t/m 122
    data = LookUp(0x7c, 0x14, 0x14, 0x14, 0x08, 0x00, 0x08, 0x14, 0x14, 0x18, 0x7c, 0x00, 0x7c, 0x08, 0x04, 0x04, 0x08, 0x00, 0x48, 0x54, 0x54, 0x54, 0x20, 0x00, 0x04, 0x3f, 0x44, 0x40, 0x20, 0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c, 0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c, 0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c, 0x00, 0x44, 0x64, 0x54, 0x4c, 0x44, 0x00), addr
        I2CWrite sda, scl, 0xa4, addr, data
        WaitMs 10
    Next addr
     
    'tekst "CV-CONTROL"
    For addr = 0 To 84 Step 1
    data = LookUp(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xbe, 0xbe, 0xbe, 0xdd, 0xff, 0xe0, 0xdf, 0xbf, 0xdf, 0xe0, 0xff, 0xef, 0xef, 0xef, 0xef, 0xef, 0xff, 0xc1, 0xbe, 0xbe, 0xbe, 0xdd, 0xff, 0xc1, 0xbe, 0xbe, 0xbe, 0xc1, 0xff, 0x80, 0xfb, 0x0f7, 0xef, 0x80, 0xff, 0xfe, 0xfe, 0x80, 0xfe, 0xfe, 0xff, 0x80, 0xf6, 0xe6, 0xd6, 0xb9, 0xff, 0xc1, 0xbe, 0xbe, 0xbe, 0xc1, 0xff, 0x80, 0xbf, 0xbf, 0xbf, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), addr
        I2CWrite sda, scl, 0xa6, addr, data
        WaitMs 10
    Next addr
     
    'tekst "SET"
    For addr = 100 To 118 Step 1
    look = addr - 100
    data = LookUp(0xff, 0xff, 0xb9, 0xb6, 0xb6, 0xb6, 0xce, 0xff, 0x80, 0xb6, 0xb6, 0xb6, 0xbe, 0xff, 0xfe, 0xfe, 0x80, 0xfe, 0xfe, 0xff, 0xff), look
        I2CWrite sda, scl, 0xa6, addr, data
        WaitMs 10
    Next addr
     
    'tekst "START"
    For addr = 120 To 150 Step 1
    look = addr - 120
    data = LookUp(0xff, 0xff, 0xb9, 0xb6, 0xb6, 0xb6, 0xce, 0xff, 0xfe, 0xfe, 0x80, 0xfe, 0xfe, 0xff, 0x81, 0xee, 0xee, 0xee, 0x81, 0xff, 0x80, 0xf6, 0xe6, 0xd6, 0xb9, 0xff, 0xfe, 0xfe, 0x80, 0xfe, 0xfe, 0xff), look
        I2CWrite sda, scl, 0xa6, addr, data
        WaitMs 10
    Next addr
     
    'tekst "PROG:    min."
    For addr = 0 To 84 Step 1
    data = LookUp("P", "R", "O", "G", ".", ":", 0x20, 0x20, 0x20, 0x20, "m", "i", "n", "."), addr
        I2CWrite sda, scl, 0xa8, addr, data
        WaitMs 10
    Next addr
     
    'vlam quadr. 1
    For addr = 100 To 105 Step 1
    look = addr - 100
    data = LookUp(0xc0, 0xf0, 0x78, 0x9c, 0xff, 0xf8), look
        I2CWrite sda, scl, 0xa8, addr, data
        WaitMs 10
    Next addr
     
    'vlam quadr. 2
    For addr = 110 To 115 Step 1
    look = addr - 110
    data = LookUp(0xf0, 0xe0, 0x80, 0x00, 0x00, 0x00), look
        I2CWrite sda, scl, 0xa8, addr, data
        WaitMs 10
    Next addr
     
    'vlam quadr. 3
    For addr = 120 To 125 Step 1
    look = addr - 120
    data = LookUp(0x0f, 0x3f, 0xff, 0xfe, 0xdc, 0xe3), look
        I2CWrite sda, scl, 0xa8, addr, data
        WaitMs 10
    Next addr
     
    'vlam quadr. 4
    For addr = 130 To 135 Step 1
    look = addr - 130
    data = LookUp(0x7f, 0x3f, 0x0f, 0x00, 0x00, 0x00), look
        I2CWrite sda, scl, 0xa8, addr, data
        WaitMs 10
    Next addr
     
    'batt icon
    For addr = 140 To 152 Step 1
    look = addr - 140
    data = LookUp(0x7e, 0x7e, 0x5e, 0x46, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x24, 0x3c), look
        I2CWrite sda, scl, 0xa8, addr, data
        WaitMs 10
    Next addr
     
    '**********************************************************
    'check eeprom adresses
    t = 0
    For a = 0 To 7
        Select Case a
        Case 0
            addr = 0xa0
        Case 1
            addr = 0xa2
        Case 2
            addr = 0xa4
        Case 3
            addr = 0xa6
        Case 4
            addr = 0xa8
        Case 5
            addr = 0xaa
        Case 6
            addr = 0xac
        Case 7
            addr = 0xae
        EndSelect
       
        Serout PORTC.3, 9600, CrLf, CrLf, #addr, CrLf, CrLf
            For i = 0 To 255 Step 1
                I2CRead sda, scl, addr, i, data  'bit 1 of "con" is controlled by the I2CRead instruction for reading
                WaitMs 10
                Serout PORTC.3, 9600, #data, ";",
                t = t + 1
                If t > 15 Then
                    t = 0
                    Serout PORTC.3, 9600, CrLf  'start new line after 16 bytes
                Endif
            Next i
    Next a
     
     
    main:
    PORTC.4 = True  'indication writing and reading done
    Goto main
    End                                          
     
    Now its time to clean up the code (i.e. the case structure can be replaced with for loop, just like the example from Languer).
    Finally, thank you all for your great help! I really appreciate it.
     
    Last edited: Sep 15, 2014

Share This Page