;****************************************************   
;Copyright (asm) 2019   苏州华芯微电子股份有限公司  *   
;					            					*   
;文件名称:                                          *   
;文件标识:					    					*   
;摘    要:					    					*   
;SYS_INIT			                    			*   
;当前版本:	V2					    				*   
;作    者:	WSG			                    		*   
;完成日期:	2021.11.19		                    	* 
;变更记录:
	;V1: 初版	
	;V2: 增加E2相关位定义 增加位定义新格式
	;	 兼容原防盗器程序
;****************************************************   
;ROM:		2K-ROM
;EEPROM:	128*BYTE-EEPROM
;RAM:		128*BYTE-RAM
;***************************************************** 
;Common define Segment
;***************************************************** 
A		EQU		0x0
R		EQU		0x1
;*****************************************************   
;BANK0-定义   	INTFLAG
;*****************************************************   
INDF	EQU		00H   
TMR0	EQU		01H   
PCL		EQU		02H   
STATUS	EQU		03H   
FSR		EQU		04H   
PORTA	EQU		05H   
PA		EQU		05H   
IOSTA	EQU		05H   
PORTB	EQU		06H   
PB		EQU		06H   
IOSTB	EQU		06H   
SRAM	EQU		07H    
PCON	EQU		08H   
CHIPCON EQU     08H     
WUCON	EQU		09H   
PCHBUF	EQU		0AH   
PDCON	EQU		0BH   
ODCON	EQU		0CH   
PHCON	EQU		0DH   
INTEN	EQU		0EH   
INTFLAG	EQU		0FH      
;*****************************************************   
PWM0EN		EQU		050H   
PWM0C		EQU		051H   
PWM0TL		EQU		052H   
PWM0TH		EQU		053H   
PWM0PL		EQU		054H   
PWM0PH		EQU		055H   
PWM0DL		EQU		056H   
PWM0DH		EQU		057H   
   
PWM0DTL		EQU		058H   
PWM0DTH		EQU		059H   
PWMPSCON	EQU		05BH   
   
PWM1DL		EQU		060H   
PWM1DH		EQU		061H   
   
PBIC1		EQU		06CH   
PBIC0		EQU		06DH   
PAHCON		EQU		06EH   
PAIC1		EQU		06FH   
PAIC0		EQU		070H   
   
TC0L		EQU		071H   
TC0M		EQU		072H   
TC0R		EQU		073H   
TC0H		EQU		074H   
TC0D1		EQU		075H   
TC0D2		EQU		076H   
PWMCON		EQU		077H   
   
PADCON		EQU		078H   
OSCM		EQU		079H   
EECON1		EQU		07AH   
EEADRH		EQU		07BH   
EEADRL		EQU		07CH   
EEDATL		EQU		07EH   
      
;*****************************************************   
;BANK1-定义   
;*****************************************************   
TKC0		EQU		050H   
TK16DH		EQU		051H   
TK16DL		EQU		052H   
TKC1		EQU		053H   
TKC2		EQU		054H   
TKC3		EQU		055H   
TKSTA		EQU		056H   
TKPDH		EQU		057H   
   
TKPDL		EQU		058H   
CMPCON		EQU		059H   
CMPM		EQU		05AH   
OPAM		EQU		05BH   
   
INTEN1		EQU		05EH   
INTFLAG1	EQU		05FH   
   
FLCON1		EQU		079H   
FLCON2		EQU		07AH   
FLADRH		EQU		07BH   
FLADRL		EQU		07CH   
FLDATH		EQU		07DH   
FLDATL		EQU		07EH   
FLerrf		EQU		07FH    
;*****************************************************   
;BANK0-BIT-定义   
;*****************************************************   
;INDF	EQU		00H   
;TMR0	EQU		01H   
;PCL	EQU		02H   
;STATUS	EQU		03H   
	#define		FC		STATUS,0  
	#define		FDC		STATUS,1 
	#define		FZ		STATUS,2  
	#define		FNPD	STATUS,3  
	#define		FNTO	STATUS,4 
	#define		FRP0	STATUS,5   
	#define    	B_BANK  STATUS,5
	#define		FRP1	STATUS,6   
	#define		FRST	STATUS,7   
	   
;FSR	EQU		04H   
;PORTA	EQU		05H   
;PA	EQU		05H   
;IOSTA	EQU		05H   
;PORTB	EQU		06H   
;PB	EQU		06H   
;IOSTB	EQU		06H   
;SRAM	EQU		07H   
   
;PCON	EQU		08H   
	#define		FLVDTE	PCON,5   
	#define		FEIS	PCON,6   
	#define		FWDTE	PCON,7   
	   
;WUCON	EQU		09H   
;PCHBUF	EQU		0AH   
;PDCON	EQU		0BH   
;ODCON	EQU		0CH   
;PHCON	EQU		0DH   
;INTEN	EQU		0EH   
	#define		FT0IE		INTEN,0 
	#define		FPBIE		INTEN,1  
	#define		FINTIE		INTEN,2  
	#define		FTC0IE		INTEN,3   
	#define		FTP0IE		INTEN,4   
	#define		FINT1IE		INTEN,5     
	#define		FGIE		INTEN,7  

	#define		T0IE		INTEN,0 
	#define		PBIE		INTEN,1  
	#define		INTIE		INTEN,2  
	#define		TC0IE		INTEN,3   
	#define		TP0IE		INTEN,4   
	#define		INT1IE		INTEN,5     
	#define		GIE			INTEN,7  
	   
;INTFLAG	EQU		0FH   
	#define		FT0IF		INTFLAG,0  
	#define		FPBIF		INTFLAG,1   
	#define		FINTIF		INTFLAG,2	
	#define		FTC0IF		INTFLAG,3   	   
	#define		FTP0IF		INTFLAG,4   
	#define		FINT1IF		INTFLAG,5   

	#define		T0IF		INTFLAG,0  
	#define		PBIF		INTFLAG,1   
	#define		INTIF		INTFLAG,2	
	#define		TC0IF		INTFLAG,3   	   
	#define		TP0IF		INTFLAG,4   
	#define		INT1IF		INTFLAG,5 
   
;*****************************************************   
;PWM0EN		EQU		050H   
	#define		FPWM0EN		PWM0EN,0   
	#define		FPWM0OEN	PWM0EN,1   
	#define		FPWM01OEN	PWM0EN,2   
	#define		FPWM0M		PWM0EN,3   
	   
	#define		FPWM1OEN	PWM0EN,4   
	#define		FTPSEL8		PWM0EN,5   	   
	#define		FTPEN		PWM0EN,7   	   
;PWM0C		EQU		051H   
;PWM0TL		EQU		052H   
;PWM0TH		EQU		053H   
;PWM0PL		EQU		054H   
;PWM0PH		EQU		055H   
;PWM0DL		EQU		056H   
;PWM0DH		EQU		057H   
   
;PWM0DTL	EQU		058H   
;PWM0DTH	EQU		059H  

;PWMPSCON	EQU		05BH   
;PWM1DL		EQU		060H   
;PWM1DH		EQU		061H   

  
;PBIC1		EQU		06CH   
;PBIC0		EQU		06DH   
;PAHCON		EQU		06EH   
;PAIC1		EQU		06FH   
;PAIC0		EQU		070H   
   
;TC0L		EQU		071H   
;TC0M		EQU		072H 
	#define		FPWM0		TC0M,0   
	#define		FBUZ		TC0M,1   
	#define		FT16SEL		TC0M,2   
	#define		FTCCKS		TC0M,3  

	#define		FTC0S0		TC0M,4   
	#define		FTC0S1		TC0M,5   
	#define		FTC0S2		TC0M,6   
	#define		FTC0TR		TC0M,7 

	#define		PWM0		TC0M,0   
	#define		BUZ			TC0M,1   
	#define		T16SEL		TC0M,2   
	#define		TCCKS		TC0M,3  
	#define		TC0S0		TC0M,4   
	#define		TC0S1		TC0M,5   
	#define		TC0S2		TC0M,6   
	#define		TC0TR		TC0M,7 

	
;TC0R		EQU		073H   
;TC0H		EQU		074H   
;TC0D1		EQU		075H   
;TC0D2		EQU		076H   
;PWMCON		EQU		077H   
   
;PADCON		EQU		078H   
;OSCM		EQU		079H   
	#define		FCLKMD		OSCM,0   
	#define		FSTPHX		OSCM,1   
	#define		FXTSEL		OSCM,2   
	#define		FSLCON		OSCM,3   
	   
	#define		FSLT0CON	OSCM,4   
	#define		FGREENEN	OSCM,5   
	#define		FWAKEMODE	OSCM,6   
  
;EECON1		EQU		07AH   
;EEADRH		EQU		07BH   
;EEADRL		EQU		07CH   
;EEDATL		EQU		07EH      
	#define    B_E2TIME       EECON1,6	;E2操作时长  
	#define    B_E2ERSALL     EECON1,3 	;E2全擦除
	#define    B_E2ERASE      EECON1,2	;E2位擦除
	#define    B_E2PROG       EECON1,1	;E2写
	#define    B_E2READ       EECON1,0	;E2读 

;*****************************************************   
;BANK1-BIT-定义   
;*****************************************************   
;TKC0		EQU		050H   
	#define		FTKPS0		TKC0,0   
	#define		FTKPS1		TKC0,1   
	#define		FTKPS2		TKC0,2   
	#define		FTKPS3		TKC0,3   
	   
	#define		FCVS		TKC0,4   
	;#define	FTKPS1		TKC0,5   
	#define		FTKST		TKC0,6	   
	#define		FTKEN		TKC0,7   
;TK16DH		EQU		051H   
;TK16DL		EQU		052H   
;TKC1		EQU		053H   
;TKC2		EQU		054H   
;TKC3		EQU		055H   
;TKSTA		EQU		056H   
	#define		FSACMPO		TKSTA,1   
	#define		FACMPO		TKSTA,2   
	#define		FDCMPO		TKSTA,3   
  
	#define		FTMOUT		TKSTA,7   
;TKPDH		EQU		057H      
;TKPDL		EQU		058H   


;CMPCON		EQU		059H
	#define    B_COPOL	CMPCON,1	;输出极性 1取反 0不取反
	#define    B_CVEN	CMPCON,2	;正端内部1.25V基准
	#define    B_CPEN	CMPCON,3	;正端PA0接口
	#define    B_CODEB	CMPCON,4	;输出滤波 1滤波3个时钟 0不滤波
	#define    B_FTCKS	CMPCON,5	;滤波时钟选择 1低速 0系统
	#define    B_COMIF	CMPCON,6	;比较器输出
	#define    B_COMEN	CMPCON,7	;CMP使能


;CMPM		EQU		05AH
	#define    B_VRS0	CMPM,0	;输入电压选择
	#define    B_VRS1	CMPM,1	;
	#define    B_VRS2	CMPM,2	;
	#define    B_VRS3	CMPM,3	;
	#define    B_XRVSEL	CMPM,4	;
	#define    B_CPINS0	CMPM,5	;比较器负端选择
	#define    B_CPINS1	CMPM,6	;
;---------------------------------------
;OPAM		EQU	05BH
	#define    B_MULTS0	OPAM,0	;外灌电压放大倍数
	#define    B_MULTS1	OPAM,1	;
	#define    B_OPAMEN	OPAM,2	;PB2做为外灌使能
	#define    B_COMMS	OPAM,3	;负端输入选择 0其他口 1PB2放大后做为输入



;FLCON1		EQU		079H	;
	#define    	B_READL       FLCON1,0		;1使能读
	#define    	B_PROGL       FLCON1,1		;1使能写
	#define    	B_ERASEL      FLCON1,2		;1使能页擦
	#define    	B_TIMEL       FLCON1,6		;1默认时长的2倍 0默认时长
	#define    	B_CEFL	      FLCON1,7		;1使能FLASH操作
;FLerrf		EQU		07FH  	;flash操作异常标志
	#define    B_FOV       FLerrf,0	;1操作异常
   

;*****************************************************   
;PIN-DEFINE   
;****************************************************   
;	    PA0	-1	14- PA1	                    *   
;	    PB7	-2	13- PA2	                    *   
;	    PB6	-3	12- PA3	                    *   
;	    VDD -4	11- VSS	                    *   
;	    PB5	-5	10- PB0	                    *   
;	    PB4	-6	9 - PB1	                    *   
;	    PB3	-7	8 - PB2	                    *   
;****************************************************      




;*****************************************************   
;位定义 方便兼容
;*****************************************************   
;-------------------------------
;STATUS		REG	0x03
	C_B			EQU	0x0
	DC_B		EQU	0x1
	Z_B			EQU	0x2
	PD_B		EQU	0x3
	TO_B		EQU	0x4
	GP1_B		EQU	0x6
	RST_B		EQU	0x7
;--------------------------------------     
;状态标志位                                               
;--------------------------------------
#define    B_C          STATUS,C_B
#define    B_DC         STATUS,DC_B                
#define    B_Z          STATUS,Z_B                             
#define    B_PD         STATUS,PD_B                          
#define    B_TO         STATUS,TO_B    

;-------------------------------
;INTEN		REG	0x0E
	T0IE_B		EQU	0x0
	PBIE_B		EQU	0x1
	INTIE_B		EQU	0x2
	TC0IE_B		EQU	0x3
	TP0IE_B		EQU	0x4
	INT1IE_B	EQU	0x5
	GIE_B		EQU	0x7
;--------------------------------------               
;定义中断使能位                                        
;--------------------------------------                      
#define    B_T0IE       INTEN,T0IE_B
#define    B_PBIE       INTEN,PBIE_B
#define    B_INTIE      INTEN,INTIE_B
#define    B_GIE        INTEN,GIE_B

;-------------------------------
;INTFLAG	REG	0x0F
	T0IF_B		EQU	0x0
	PBIF_B		EQU	0x1
	INTIF_B		EQU	0x2
	TC0IF_B		EQU	0x3
	TP0IF_B		EQU	0x4
	INT1IF_B	EQU	0x5

;--------------------------------------
;定义中断标志位                                          
;--------------------------------------                            
#define    B_T0IF       INTFLAG,T0IF_B              
#define    B_PBIF       INTFLAG,PBIF_B                    
#define    B_INTIF      INTFLAG,INTIF_B 
;-------------------------------
;PORTA		REG	0x05
	IOA0_B		EQU	0x0
	IOA1_B		EQU	0x1
	IOA2_B		EQU	0x2
	IOA3_B		EQU	0x3
	IOA4_B		EQU	0x4
	IOA5_B		EQU	0x5
;-------------------------------
;PORTB		REG	0x06
	IOB0_B		EQU	0x0
	IOB1_B		EQU	0x1
	IOB2_B		EQU	0x2
	IOB3_B		EQU	0x3
	IOB4_B		EQU	0x4
	IOB5_B		EQU	0x5
	IOB6_B		EQU	0x6
	IOB7_B		EQU	0x7


 
	
