/***
 * A program the functions of the RTC drivers
 * Copyright (c) 2003, Inventronik
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this 
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation 
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the Inventronik nor the names of its contributors may be 
 * used to endorse or promote products derived from this software without specific 
 * prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id: eep-test.c,v 1.1 2005/01/27 18:14:09 jensi Exp $ *
 *
 * new 2. Feb. 04 - added mem protection for the bootloader
 */

#if defined(__PCM__)
#include <16f876.h>
#fuses XT, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP
#elif defined(__PCH__)
#include <18f252.h>
#fuses HS, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP
#endif

#zero_ram // erase all used ram cells at initialisation.

#use delay(clock=6000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

/* reserve space for the bootstrap loader */
#ORG 0x1F00,0x1FFF //for the 8k 16F876/7
void loader() { }

#define SDA_LINE PIN_C4
#define SCL_LINE PIN_C3
#include "eep2465.c"

void main(void) 
{
    long int i;
    EEP_ADDRESS address;

    init_ext_eeprom();
//    printf("\r\nRead and write to an external eeprom: ");
//    printf("\r\nWrite 256 bytes");
    for(i=0; i<256; i++)
        printf("%02x ", read_byte_ext_eeprom(i));
    for(i=0; i<256; i++)
        write_byte_ext_eeprom(i, i);
    printf("\r\ndone\r\nRead 256 bytes\r\n");
    for(i=0; i<256; i++) {
        printf("%02x ", read_byte_ext_eeprom(i));
        if(!((i+1)%8))
            printf("\r\n");
    }
    printf("\r\ndone");
    printf("\r\nWrite 256 long int");
    for(i=0; i<256; i++)
        write_longint_ext_eeprom(i, 1000+i);
    printf("\r\ndone\r\nRead 256 long int\r\n");
    for(i=0; i<256; i++)
        printf("long int %ld: %ld\r\n", i, read_longint_ext_eeprom(i));
    printf("\r\ndone");
    for(;;); // nothing to do
}
