#include "include.h"
/*
HC18M003A-EEPROM-Demo
注意：
1、仿真无法使用PA0/PA1  为通信IO口
2、VDD上电需等待电源稳定后，再进行读写EEPROM操作
3、写EEPROM过程是强制打开高频时钟的
4、操作EE时CPU停止工作，完成后恢复
5、	EEPERAT = 0x4E;   ///不可更改
	EEPPROT = 0x2E;   ///不可更改
*/
unsigned short Read_EE[16];
unsigned short Write_EE[16];
unsigned short Read_Save;
void main(void)
{
	DelayMs(200);
	unsigned char i,j;
	////初始化函数 
	System_Int();
	
	TXIF = 0;
	UARTEN = 1;
	
	////填写数组
	for(i = 0; i < 16; i ++)
	{
		Write_EE[i] = i;
	}	

	/// 报头  写EE数据
	SBUF = 0x55;
	while(!TXIF);
	TXIF = 0;
	///写EE
	for(j = 0;j < 16;j++)
	{	
		Read_Save = Write_EE[j];
		EEPDATH =  Read_Save >> 8;
		EEPDATL =  Read_Save;
		EEONPADR = j;
		WR = 1;
		asm("nop");
		asm("nop");
		while(WR);
	}
	
	EEPAGADR = 0x00;    ///EE页地址
	EEONPADR = 0x00;    ///EE页内地址
	
	/// 报头  读EE数据
	SBUF = 0xAA;
	while(!TXIF);
	TXIF = 0;
	
	///读EE数据  转存数组
	for(j = 0;j < 16;j++)
	{
		EEONPADR = j;
		RD = 1;
		asm("nop");
		asm("nop");
		asm("nop");
		asm("nop");
		while(RD);
		Read_Save = EEPDATH;
		Read_Save = (Read_Save << 8) | EEPDATL;
		Read_EE[j] = Read_Save;	
	}

	///报头  发送数据
	SBUF = 0x5A;
	while(!TXIF);
	TXIF = 0;
	
	///UART发送
	for(j = 0;j < 16;j++)
	{
		Read_Save = Read_EE[j];
		SBUF = Read_Save >> 8;
		while(!TXIF);
		TXIF = 0;
		
		SBUF = Read_Save;
		while(!TXIF);
		TXIF = 0;		
	}


	while(1)
	{
//		asm("clrwdt");   ///注意WDT是否开启

	}
}
///中断服务函数
void interrupt Timer0_Isr(void)
{

}