				;file c:\users\edenlai\desktop\esk310\adc\ADC.c
				;1	/************************************************************
				;2	* PROGRAM : ADC conversion
				;3	* Wire Connection:
				;4	*   ESK303 (VDD) connects to ESK310 (5V)
				;5	*   ESK303 (GND) connects to ESK310 (GND)
				;6	*   ESK303 (C0~C6) connects to ESK310 ((JP7)a~g)
				;7	*   ESK303 (VDD) connects to ESK310 ((JP8)4)
				;8	*   ESK303 (D0) connects to ESK310 (JP16)
				;9	* Created on 2021/08/27 by Best Modules Corp.
				;10	*************************************************************/
				;11	#include <HT66F2390.h>
				;12	#include "setup.h"
				;13		
				;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	2817	jmp     _main
0005	063F	and     a, LVRC
0006	4F5B	dc	04F5BH
0007	6D66	jmp     D66H
0008	077D	mov     a, FD3H
0009	677F	call    F7FH
				;16		setup();
				_main:
				_main:
0017	200A	call    _setup
				_L10:
0018	2818	jmp     $
0019	2819	jmp     $
001A	0000	nop
001B	0000	nop
				;17		while(1);									
				;18	}
				;19	
				;20	DEFINE_ISR(VR,0x1c)
				;21	{		
				@VR_code .SECTION 'CODE'
001C	4080	mov     r11c, a
001D	070B	mov     a, PBP
001E	1F0B	clr     PBP
001F	2820	jmp     _VR
				_VR:
				_VR:
				@dummy28 .SECTION 'CODE'
				@dummy .SECTION 'CODE'
0020	4081	mov     r21c, a
0021	070A	mov     a, STATUS
0022	4086	mov     r31c, a
				;22		unsigned short vr;	
				;23		_start=1; _start=0;									//Start A/D conversion			
0023	33E9	set     START
0024	37E9	clr     START
				;24		vr=(_sadoh*256)+_sadol;								//12-bit conversion result
0025	0768	mov     a, SADOH
0026	4082	mov     rc1c, a
0027	5F03	clr     rb1c
0028	0767	mov     a, SADOL
0029	4383	addm    a, rb1c
002A	3C0A	sz      C
002B	5482	inc     rc1c
				;25		if(vr<540) SEGMENT_Port=SEGMENT_TAB[0];
002C	0F1B	mov     a, 1BH
002D	4203	sub     a, rb1c
002E	0F02	mov     a, 2H
002F	5202	sbc     a, rc1c
0030	380A	snz     C
0031	2834	jmp     _L12
0032	0F3F	mov     a, 3FH
0033	009B	mov     PC, a
				;26	
				;27		if(vr>=540 && vr<920) SEGMENT_Port=SEGMENT_TAB[1];
				_L12:
0034	0FE4	mov     a, E4H
0035	4303	add     a, rb1c
0036	4084	mov     rd1c, a
0037	0FFD	mov     a, FDH
0038	5302	adc     a, rc1c
0039	4085	mov     re1c, a
003A	0F7B	mov     a, 7BH
003B	4204	sub     a, rd1c
003C	0F01	mov     a, 1H
003D	5205	sbc     a, re1c
003E	380A	snz     C
003F	2842	jmp     _L13
0040	0F06	mov     a, 6H
0041	009B	mov     PC, a
				;28	
				;29		if(vr>=920 && vr<1300) SEGMENT_Port=SEGMENT_TAB[2];
				_L13:
0042	0F68	mov     a, 68H
0043	4303	add     a, rb1c
0044	4084	mov     rd1c, a
0045	0FFC	mov     a, FCH
0046	5302	adc     a, rc1c
0047	4085	mov     re1c, a
0048	0F7B	mov     a, 7BH
0049	4204	sub     a, rd1c
004A	0F01	mov     a, 1H
004B	5205	sbc     a, re1c
004C	380A	snz     C
004D	2850	jmp     _L14
004E	0F5B	mov     a, 5BH
004F	009B	mov     PC, a
				;30	
				;31		if(vr>=1300 && vr<1680) SEGMENT_Port=SEGMENT_TAB[3];
				_L14:
0050	0FEC	mov     a, ECH
0051	4303	add     a, rb1c
0052	4084	mov     rd1c, a
0053	0FFA	mov     a, FAH
0054	5302	adc     a, rc1c
0055	4085	mov     re1c, a
0056	0F7B	mov     a, 7BH
0057	4204	sub     a, rd1c
0058	0F01	mov     a, 1H
0059	5205	sbc     a, re1c
005A	380A	snz     C
005B	285E	jmp     _L15
005C	0F4F	mov     a, 4FH
005D	009B	mov     PC, a
				;32	
				;33		if(vr>=1680 && vr<2060) SEGMENT_Port=SEGMENT_TAB[4];
				_L15:
005E	0F70	mov     a, 70H
005F	4303	add     a, rb1c
0060	4084	mov     rd1c, a
0061	0FF9	mov     a, F9H
0062	5302	adc     a, rc1c
0063	4085	mov     re1c, a
0064	0F7B	mov     a, 7BH
0065	4204	sub     a, rd1c
0066	0F01	mov     a, 1H
0067	5205	sbc     a, re1c
0068	380A	snz     C
0069	286C	jmp     _L16
006A	0F66	mov     a, 66H
006B	009B	mov     PC, a
				;34	
				;35		if(vr>=2060 && vr<2440) SEGMENT_Port=SEGMENT_TAB[5];
				_L16:
006C	0FF4	mov     a, F4H
006D	4303	add     a, rb1c
006E	4084	mov     rd1c, a
006F	0FF7	mov     a, F7H
0070	5302	adc     a, rc1c
0071	4085	mov     re1c, a
0072	0F7B	mov     a, 7BH
0073	4204	sub     a, rd1c
0074	0F01	mov     a, 1H
0075	5205	sbc     a, re1c
0076	380A	snz     C
0077	287A	jmp     _L17
0078	0F6D	mov     a, 6DH
0079	009B	mov     PC, a
				;36	
				;37		if(vr>=2440 && vr<2820) SEGMENT_Port=SEGMENT_TAB[6];
				_L17:
007A	0F78	mov     a, 78H
007B	4303	add     a, rb1c
007C	4084	mov     rd1c, a
007D	0FF6	mov     a, F6H
007E	5302	adc     a, rc1c
007F	4085	mov     re1c, a
0080	0F7B	mov     a, 7BH
0081	4204	sub     a, rd1c
0082	0F01	mov     a, 1H
0083	5205	sbc     a, re1c
0084	380A	snz     C
0085	2888	jmp     _L18
0086	0F7D	mov     a, 7DH
0087	009B	mov     PC, a
				;38	
				;39		if(vr>=2820 && vr<3200) SEGMENT_Port=SEGMENT_TAB[7];
				_L18:
0088	0FFC	mov     a, FCH
0089	4303	add     a, rb1c
008A	4084	mov     rd1c, a
008B	0FF4	mov     a, F4H
008C	5302	adc     a, rc1c
008D	4085	mov     re1c, a
008E	0F7B	mov     a, 7BH
008F	4204	sub     a, rd1c
0090	0F01	mov     a, 1H
0091	5205	sbc     a, re1c
0092	380A	snz     C
0093	2896	jmp     _L19
0094	0F07	mov     a, 7H
0095	009B	mov     PC, a
				;40	
				;41		if(vr>=3200 && vr<3580) SEGMENT_Port=SEGMENT_TAB[8];
				_L19:
0096	0F80	mov     a, 80H
0097	4303	add     a, rb1c
0098	4084	mov     rd1c, a
0099	0FF3	mov     a, F3H
009A	5302	adc     a, rc1c
009B	4085	mov     re1c, a
009C	0F7B	mov     a, 7BH
009D	4204	sub     a, rd1c
009E	0F01	mov     a, 1H
009F	5205	sbc     a, re1c
00A0	380A	snz     C
00A1	28A4	jmp     _L20
00A2	0F7F	mov     a, 7FH
00A3	009B	mov     PC, a
				;42	
				;43		if(vr>=3580 && vr<4000) SEGMENT_Port=SEGMENT_TAB[9];	
				_L20:
00A4	0F04	mov     a, 4H
00A5	4383	addm    a, rb1c
00A6	0FF2	mov     a, F2H
00A7	5382	adcm    a, rc1c
00A8	0FA3	mov     a, A3H
00A9	4203	sub     a, rb1c
00AA	0F01	mov     a, 1H
00AB	5202	sbc     a, rc1c
00AC	380A	snz     C
00AD	28B0	jmp     _L11
00AE	0F67	mov     a, 67H
00AF	009B	mov     PC, a
				_L11:
00B0	4701	mov     a, r21c
00B1	008B	mov     PBP, a
00B2	4706	mov     a, r31c
00B3	008A	mov     STATUS, a
00B4	4700	mov     a, r11c
00B5	0004	reti
				L0D66:
				org	0d66h
0D66	0000	nop
				L0F7F:
				org	0f7fh
0F7F	0000	nop
				;44	}
				;file c:\users\edenlai\desktop\esk310\adc\setup.h
				;1	#define		SEGMENT_Port	_pc
				;2	#define		SEGMENT_PortC	_pcc
				;3	const unsigned char SEGMENT_TAB[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67};	//Seven-Segment Table
				;4	
				;5	void setup()										//Delay1ms
				;6	{	
				;7		_wdtc=0xAB;										//Turn off the watchdog timer
				_setup:
				_setup:
000A	0FAB	mov     a, ABH
000B	00BE	mov     WDTC, a
				;8		SEGMENT_PortC=0;								//Set SEGMENT_Port to output mode
000C	1F1C	clr     PCC
				;9		_sadc0=0b00111000;								//ADEN=ADRFS=1, SAC[3:0]=1000(AN8)
000D	0F38	mov     a, 38H
000E	00E9	mov     SADC0, a
				;10		_pds0=0x03;										//Set PD0 function to AN8
000F	0F03	mov     a, 3H
0010	80D3	lmov    PDS0, a
				;11		_ade=1;											//Enable ADC interrupt
0012	3191	set     ADE
				;12		_emi=1;											//Enable EMI
0013	3010	set     EMI
				;13		_start=1; _start=0;								////Start A/D conversion
0014	33E9	set     START
0015	37E9	clr     START
0016	0003	ret
				;14	}
				;15	
				;16	void Delay1ms(unsigned short delay)					//Delay1ms
				;17	{	
				;18		unsigned short i;											
				;19		for(i=0;i<delay;i++) GCC_DELAY(2000);			//GCC_DELAY(0.5us)
				;20	}	
				;21	
				;22	void Delay10ms(unsigned short delay)				//Delay10ms
				;23	{	
				;24		unsigned short i;											
				;25		for(i=0;i<delay;i++) GCC_DELAY(20000);			//GCC_DELAY(0.5us)
				;26	}
				data .SECTION 'DATA'
				__intc0 DB DUP (?) ; __intc0
				__intc1 DB DUP (?) ; __intc1
				__pc DB DUP (?) ; __pc
				__pcc DB DUP (?) ; __pcc
				__wdtc DB DUP (?) ; __wdtc
				__sadol DB DUP (?) ; __sadol
				__sadoh DB DUP (?) ; __sadoh
				__sadc0 DB DUP (?) ; __sadc0
				r11c DB DUP (?)
				r21c DB DUP (?)
				rc1c DB DUP (?)
				rb1c DB DUP (?)
				rd1c DB DUP (?)
				re1c DB DUP (?)
				r31c DB DUP (?)
				__pds0 DB DUP (?) ; __pds0
