				;file c:\users\edenlai\desktop\esk-310\7_eeprom\EEPROM.c
				;1	/************************************************************
				;2	* PROGRAM : EEPROM
				;3	* Wire Connection:
				;4	*   ESK-303 (VDD)   connects to ESK-310 (5V)
				;5	* 	ESK-303 (GND)   connects to ESK-310 (GND)
				;6	*   ESK-303 (C0~C7) connects to ESK-310 ((JP13)0~7)
				;7	*   ESK-303 (F0~F7) connects to ESK-310 ((JP24)0~7)
				;8	* Created on 2021/08/27 by Best Modules Corp.
				;9	*************************************************************/
				;10	#include <HT66F2390.h>
				;11	#include "setup.H"
				;12	
				;13	unsigned char KEY,led;	
				;14	void main()
				;15	{	
				@code .SECTION 'CODE'
				include HT66F2390.inc
0000	1F0B	clr     PBP
0001	2802	jmp     _main_startup1
				@start .SECTION 'CODE'
				_main_startup1:
				@start .SECTION 'CODE'
0002	0F00	mov     a, 0H
0003	008B	mov     PBP, a
0004	2849	jmp     _main
				;16		setup();
				_main:
				_main:
0049	2044	call    _setup
				;17		while(1) 
				;18		{			
				;19			KEY=Scan();
				_L27:
004A	2023	call    _Scan
004B	4080	mov     ra, a
004C	4700	mov     a, ra
004D	4083	mov     KEY[0], a
				;20			if(KEY==0)
004E	5080	sz      ra
004F	2853	jmp     _L25
				;21			{		
				;22				led=0;
0050	5F02	clr     led[0]
				;23				Write4Byte(led);					//Write to EEPROM	
0051	0F00	mov     a, 0H
0052	2015	call    _Write4Byte
				;24			}	
				;25			if(KEY==1)
				_L25:
0053	5703	sdza    KEY[0]
0054	284A	jmp     _L27
				;26			{		
				;27				Read4Byte(led);						//Read to EEPROM
0055	4702	mov     a, led[0]
0056	2005	call    _Read4Byte
				;28				LED_Port=led;			
0057	4702	mov     a, led[0]
0058	009B	mov     PC, a
0059	284A	jmp     _L27
005A	285A	jmp     $
				;29			}
				;30		}
				;31	}
				;32	
				;33	void Read4Byte(volatile unsigned char data)
				;34	{	
				_Read4Byte:
				_Read4Byte:
0005	4081	mov     data[0], a
				;35		_mp1h=0x01; _mp1l=0x40;						//MP1=EEC (Sector 1)
0006	0F01	mov     a, 1H
0007	0084	mov     MP1H, a
0008	0F40	mov     a, 40H
0009	0083	mov     MP1L, a
				;36		_iar1=RDEN; _iar1|=RD;						//Set RDEN=1,RD=1
000A	0F02	mov     a, 2H
000B	0082	mov     __iar1[0], a
000C	3002	set     __iar1[0].0
				;37		while(_iar1&RD);							//Wait for read
				L000D:
000D	3C02	sz      __iar1[0].0
000E	280D	jmp     L000D
				;38		_iar1=0;									//Disable EEPROM
000F	1F02	clr     __iar1[0]
				;39		data=_eed;									
0010	0743	mov     a, EED
0011	4081	mov     data[0], a
				;40		led=data;
0012	4701	mov     a, data[0]
0013	4082	mov     led[0], a
0014	0003	ret
				;41	}
				;42	
				;43	void Write4Byte(volatile unsigned char data)
				;44	{	
				_Write4Byte:
				_Write4Byte:
0015	4081	mov     data[0], a
				;45		_eed=data;									
0016	4701	mov     a, data[0]
0017	00C3	mov     EED, a
				;46		_mp1h=0x01; _mp1l=0x40;						//MP1=EEC (Sector 1)
0018	0F01	mov     a, 1H
0019	0084	mov     MP1H, a
001A	0F40	mov     a, 40H
001B	0083	mov     MP1L, a
				;47		_iar1=WREN; _iar1|=WR;						//Set WREN=1,WR=1
001C	0F08	mov     a, 8H
001D	0082	mov     __iar1[0], a
001E	3102	set     __iar1[0].2
				;48		while(_iar1&WR);							//Wait for write
				L001F:
001F	3D02	sz      __iar1[0].2
0020	281F	jmp     L001F
				;49		_iar1=0;									//Disable EEPROM
0021	1F02	clr     __iar1[0]
0022	0003	ret
				;50	}
				;file c:\users\edenlai\desktop\esk-310\7_eeprom\setup.H
				;1	#define LED_Port  	_pc								
				;2	#define LED_PortC 	_pcc
				;3	#define	KEY_Port	_pf						
				;4	#define	KEY_PortC	_pfc						
				;5	#define	KEY_PortPU	_pfpu	
				;6	
				;7	#define	WREN		0x08							//WREN Bit In EEC
				;8	#define	WR			0x04							//WR Bit In EEC
				;9	#define	RDEN		0x02							//RDEN Bit  In EEC
				;10	#define	RD			0x01							//RD Bit In EEC
				;11	#define	StartADRS	0x100							//Set EEPROM Start Address
				;12	
				;13	void Write4Byte(volatile unsigned char);
				;14	void Read4Byte(volatile unsigned char);
				;15	
				;16	void setup()								
				;17	{	
				;18		_wdtc=0xAB;										//Turn off the watchdog timer
				_setup:
				_setup:
0044	0FAB	mov     a, ABH
0045	00BE	mov     WDTC, a
				;19		LED_PortC=0;									//Set LED_Port to output mode
0046	1F1C	clr     PCC
				;20		LED_Port=0xFF;									//Set the initial value of LED_Port
0047	1F9B	set     PC
0048	0003	ret
				;21	}
				;22	
				;23	unsigned char Scan()
				;24	{	
				;25		unsigned char i,KEY=0;
0029	5F00	clr     ra
				;26		KEY_Port=0xFE;					         		//KEYPort[3:0]=1110
				_Scan:
				_Scan:
0023	0FFE	mov     a, FEH
0024	00A4	mov     PF, a
				;27		KEY_PortC=0xF0; 								//KEY_PortC[7:4]/[3:0] as input/output attributes
0025	0FF0	mov     a, F0H
0026	00A5	mov     PFC, a
				;28		KEY_PortPU=0xF0;			   					//Enable KEY_PortPU[7:4] boost resistance
0027	0FF0	mov     a, F0H
0028	00A6	mov     PFPU, a
				;29		for(i=0;i<4;i++)								
003E	4700	mov     a, ra
003F	0A10	sub     a, 10H
0040	390A	snz     Z
0041	282A	jmp     _L7
				;30		{	
				;31			if(!(KEY_Port & 0x80)) break;		      	//Check (KEY_Port[4]) is pressed
				_L7:
002A	3BA4	snz     PF7
002B	2842	jmp     _L3
				;32			KEY++;										//KEY+1
002E	5480	inc     ra
002F	2842	jmp     _L3
				;33			if(!(KEY_Port & 0x40)) break;			   	//Check (KEY_Port[5]) is pressed
002C	3F24	sz      PF6
002D	2830	jmp     _L4
				;34			KEY++;										//KEY+1
0032	0F02	mov     a, 2H
0033	4380	addm    a, ra
0034	2842	jmp     _L3
				;35			if(!(KEY_Port & 0x20)) break;			   	//Check (KEY_Port[6]) is pressed
				_L4:
0030	3EA4	sz      PF5
0031	2835	jmp     _L5
				;36			KEY++;										//KEY+1
0037	0F03	mov     a, 3H
0038	4380	addm    a, ra
0039	2842	jmp     _L3
				;37			if(!(KEY_Port & 0x10)) break;			   	//Check (KEY_Port[7]) is pressed
				_L5:
0035	3E24	sz      PF4
0036	283A	jmp     _L6
				;38			KEY++;										//KEY+1
				_L6:
003A	0F04	mov     a, 4H
003B	4380	addm    a, ra
				;39			KEY_Port<<=1; 	   							//Update scan code
003C	0724	mov     a, PF
003D	03A4	addm    a, PF
				;40		}
				;41		return KEY;	
				;42	}
				_L3:
0042	4700	mov     a, ra
0043	0003	ret
				;43	
				;44	void Delay1ms(unsigned short delay)					//Delay1ms
				;45	{	
				;46		unsigned short i;											
				;47		for(i=0;i<delay;i++) GCC_DELAY(2000);			//GCC_DELAY(0.5us)
				;48	}	
				;49	
				;50	void Delay10ms(unsigned short delay)				//Delay10ms
				;51	{	
				;52		unsigned short i;											
				;53		for(i=0;i<delay;i++) GCC_DELAY(20000);			//GCC_DELAY(0.5us)
				;54	}
				data .SECTION 'DATA'
				__iar1 DB DUP (?) ; __iar1
				__mp1l DB DUP (?) ; __mp1l
				__mp1h DB DUP (?) ; __mp1h
				__pc DB DUP (?) ; __pc
				__pcc DB DUP (?) ; __pcc
				__pf DB DUP (?) ; __pf
				__pfc DB DUP (?) ; __pfc
				__pfpu DB DUP (?) ; __pfpu
				__wdtc DB DUP (?) ; __wdtc
				__eed DB DUP (?) ; __eed
				ra DB DUP (?)
				data DB DUP (?) ; data
				led DB DUP (?) ; led
				KEY DB DUP (?) ; KEY
