//************************************************************
//---------------XiAn AnaDig IC Inc.(XAD-IC)------------------
//-----------------C File Standard--------------------
//************************************************************
//#Author      :
//#Case name   :
//#Function    :
//
//************************************************************
#include "AD18F06A.h"
#include "com_port.h"
#include "periph.h"

__CONFIG(1,_FINTOSC_DIV1_1L   & _LVREN_OFF_1L      & _LVR24V_1L                                                                                          );
__CONFIG(2,_FLASH_CP7_OFF_2L  & _FLASH_CP6_OFF_2L  & _FLASH_CP5_OFF_2L   & _FLASH_CP4_OFF_2L   & _FLASH_CP3_OFF_2L
         & _FLASH_CP2_OFF_2L  & _FLASH_CP1_OFF_2L  & _FLASH_CP0_OFF_2L   & _CRYLEN_OFF_2L      & _CRYHEN_OFF_2L
  	     & _IDIS_ON_2L        & _CKSUM_OFF_2L      & _CBP_OFF_2L         & _RESETE_OFF_2L      & _RSEL_LOW_2L     & _STV_ON_2L              	         );
__CONFIG(3,_DBG_OFF_3L        & _PSUT_8_3L         & _FCPU_4T_3L         & _WDTEN_OFF_3L       & _TWDT_011_3L                                            );
__CONFIG(4,_OSCM_HIRC_16M_4L  & _ENVDDL_ON_4L      & _EEDIS_OFF_4L       & _FLDIS_OFF_4L       & _FCMEN_OFF_4L    & _IESO_OFF_4L&  _DBGS_IOSEL_1_4L      );

#define EEPROM_MODE2
/****************************************************
//EEPROM写的方式共有2种
//1、正常写，由硬件实现EEPROM擦除和写入逻辑无需关心擦除
//2、1Byte擦除和1byte写入，擦除和写入逻辑分开

*****************************************************/

void main(void)
{
    unsigned int   i     = 0;
    unsigned char  R_DAT = 0;
	TRISC2 = 0;
	PC2 = 0;
    usart_init();   //PB0作为输出打印口
    printf("Bingo>>...\r\n");
#ifdef EEPROM_MODE1
    printf("EEPROM_MODE1>>>>>>>>>>>>>>>>>\r\n");
    for(i = 0;i<256;i++)
    {
        R_DAT = EEPROM_Read(i);
        printf(" 0x%02x ",R_DAT);
        if(!((i+1)%16))printf("\r\n");//读取EEPROM
    }
    printf("Writer_EEPROM>>>>\r\n");
    for(i = 0;i<256;i++)
    {
        EEPROM_Write_Mode0(i,i);
    }
    printf("Read_EEPROM>>>>\r\n");
    for(i = 0;i<256;i++)
    {
        R_DAT = EEPROM_Read(i);
        printf(" 0x%02x ",R_DAT);
        if(!((i+1)%16))printf("\r\n");//读取EEPROM
    }
#endif
#ifdef EEPROM_MODE2
    printf("EEPROM_MODE2>>>>>>>>>>>>>>>>>\r\n");
    for(i = 0;i<256;i++)
    {
        R_DAT = EEPROM_Read(i);
        printf(" 0x%02x ",R_DAT);
        if(!((i+1)%16))printf("\r\n");//读取EEPROM
    }
    printf("Erase_EEPROM>>>>\r\n");
    for(i = 0;i<256;i++)
    {
        EEPROM_Erase_Mode1(i);
    }
    printf("Read_EEPROM>>>>\r\n");
    for(i = 0;i<256;i++)
    {
        R_DAT = EEPROM_Read(i);
        printf(" 0x%02x ",R_DAT);
        if(!((i+1)%16))printf("\r\n");//读取EEPROM
    }
    printf("Writer_EEPROM>>>>\r\n");
    for(i = 0;i<256;i++)
    {
        EEPROM_Writer_Mode1(i,i);
    }
    printf("Read_EEPROM>>>>\r\n");
    for(i = 0;i<256;i++)
    {
        R_DAT = EEPROM_Read(i);
        printf(" 0x%02x ",R_DAT);
        if(!((i+1)%16))printf("\r\n");//读取EEPROM
    }
#endif
    while(1);

}



//高优先级中断服务函数
void interrupt ISR_h (void)
{

}


//低优先级中断服务函数
void interrupt low_priority ISR_l (void)
{

}
