;--------------------------------------------------------
; File Created by ChiponCC : aolisn inc.
; Version 3.0.4#6752 (Nov 19 2015 16:48:50) (MSVC)
; This file was generated Fri May 20 14:52:14 2016
;--------------------------------------------------------
; chipon port for the 16-bit core
;--------------------------------------------------------
;	.file	"../main.c"
	.list	p=KF8V216
	.radix dec
	.include "KF8V216.inc"
;--------------------------------------------------------
; external declarations
;--------------------------------------------------------
	.extern	_PSW_bits
	.extern	_P0_bits
	.extern	_P2_bits
	.extern	_P1_bits
	.extern	_INTCTL_bits
	.extern	_EIF1_bits
	.extern	_T1CTL_bits
	.extern	_T2CTL_bits
	.extern	_PWMCTL_bits
	.extern	_CM1CTL_bits
	.extern	_AMPCTL_bits
	.extern	_ANSEH_bits
	.extern	_ADCCTL0_bits
	.extern	_AMPDT_bits
	.extern	_OPTR_bits
	.extern	_IP0_bits
	.extern	_IP1_bits
	.extern	_TR0_bits
	.extern	_TR2_bits
	.extern	_TR1_bits
	.extern	_VRECTL1_bits
	.extern	_EIE1_bits
	.extern	_PCTL_bits
	.extern	_OSCCTL_bits
	.extern	_ANSEL_bits
	.extern	_PUR_bits
	.extern	_IOCL_bits
	.extern	_ADCCTL1_bits
	.extern	_P0LR_bits
	.extern	_P2LR_bits
	.extern	_P1LR_bits
	.extern	_PWM4CTL0_bits
	.extern	_PWM4CTL1_bits
	.extern	_P4ASCTL_bits
	.extern	_PATRCTL_bits
	.extern	_T0
	.extern	_PCL
	.extern	_PSW
	.extern	_P0
	.extern	_P2
	.extern	_P1
	.extern	_PCH
	.extern	_INTCTL
	.extern	_EIF1
	.extern	_T1L
	.extern	_T1H
	.extern	_T1CTL
	.extern	_T2L
	.extern	_T2CTL
	.extern	_PWM1L
	.extern	_PWM1H
	.extern	_PWMCTL
	.extern	_PP1
	.extern	_CM1CTL
	.extern	_AMPCTL
	.extern	_VRECAL1
	.extern	_ANSEH
	.extern	_ADCDATAH
	.extern	_ADCCTL0
	.extern	_AMPDT
	.extern	_OPTR
	.extern	_IP0
	.extern	_IP1
	.extern	_TR0
	.extern	_TR2
	.extern	_TR1
	.extern	_VRECAL2
	.extern	_VRECTL1
	.extern	_EIE1
	.extern	_PCTL
	.extern	_OSCCTL
	.extern	_OSCCAL0
	.extern	_ANSEL
	.extern	_PP2
	.extern	_PWM2L
	.extern	_PWM2H
	.extern	_PUR
	.extern	_IOCL
	.extern	_OSCCAL1
	.extern	_ADCDATAL
	.extern	_ADCCTL1
	.extern	_T2CCRH
	.extern	_T2H
	.extern	_PP4H
	.extern	_PWM4L1
	.extern	_PWM4H1
	.extern	_P0LR
	.extern	_P2LR
	.extern	_P1LR
	.extern	_OSCCAL2
	.extern	_OSCCAL3
	.extern	_PP4L
	.extern	_T2CCRL
	.extern	_PWM4L0
	.extern	_PWM4H0
	.extern	_PWM4CTL0
	.extern	_PWM4CTL1
	.extern	_P4ASCTL
	.extern	_PATRCTL
	.extern	_startup
	.extern	__sdcc_gsinit_startup
;--------------------------------------------------------
; global declarations
;--------------------------------------------------------
	.global	_Delay_ms
	.global	_init_mcu
	.global	_init_pwm
	.global	_pwm_function
	.global	_main
	.global	_int_fun0
	.global	_int_fun1

	.global I0R1
	.global I0PCH
	.global I1R1
	.global I1PCH
	.global STK11
	.global STK10
	.global STK09
	.global STK08
	.global STK07
	.global STK06
	.global STK05
	.global STK04
	.global STK03
	.global STK02
	.global STK01
	.global STK00

sharebank .udata 0x0080
I0R1		.res 1
I0PCH		.res 1
I1R1		.res 1
I1PCH		.res 1
STK11	.res 1
	.type STK11, 108
STK10	.res 1
	.type STK10, 108
STK09	.res 1
	.type STK09, 108
STK08	.res 1
	.type STK08, 108
STK07	.res 1
	.type STK07, 108
STK06	.res 1
	.type STK06, 108
STK05	.res 1
	.type STK05, 108
STK04	.res 1
	.type STK04, 108
STK03	.res 1
	.type STK03, 108
STK02	.res 1
	.type STK02, 108
STK01	.res 1
	.type STK01, 108
STK00	.res 1
	.type STK00, 108

;--------------------------------------------------------
; global definitions
;--------------------------------------------------------
;--------------------------------------------------------
; absolute symbol definitions
;--------------------------------------------------------
;--------------------------------------------------------
; compiler-defined variables
;--------------------------------------------------------
UDL_main_0	.udata
r0x1002	.res	1
UDL_main_1	.udata
r0x1001	.res	1
UDL_main_2	.udata
r0x1003	.res	1
UDL_main_3	.udata
r0x1004	.res	1
;--------------------------------------------------------
; initialized data
;--------------------------------------------------------
LDS_00000	.idata
_pwm_function_direction_1_1
	.db 0

;--------------------------------------------------------
; overlayable items in internal ram 
;--------------------------------------------------------
;	.udata_ovr
;--------------------------------------------------------
; reset vector 
;--------------------------------------------------------
STARTUP	.code 0x0000
	NOP
	PAGESEL	init_imp
	JMP		init_imp

	.global	init_imp
INIT_IMP	.code
init_imp
	PAGESEL	_startup
	CALL	_startup
	PAGESEL	__sdcc_gsinit_startup
	CALL	__sdcc_gsinit_startup
	PAGESEL	_main
	JMP		_main
;--------------------------------------------------------
; interrupt and initialization code
;--------------------------------------------------------



func._int_fun0	.code
;***
;  PostBlock Stats: dbName = I
;***
;entry:  _int_fun0	;Function start
; 0 exit points
;; Starting PostCode block
;	op : LABEL
;	op : FUNCTION
_int_fun0	;Function start
; 0 exit points
;	op : LABEL
;	op : ENDFUNCTION
; R3 resprent for wsave,R4 resprent for ssave, R5 resprent for psave
interrupt_service_routine_0x04
_00038_DS_
;	.line	132; "../main.c"	}
	IRET	



func._int_fun1	.code
;***
;  PostBlock Stats: dbName = I
;***
;entry:  _int_fun1	;Function start
; 0 exit points
;; Starting PostCode block
;	op : LABEL
;	op : FUNCTION
_int_fun1	;Function start
; 0 exit points
;	op : LABEL
;	op : ENDFUNCTION
; R3 resprent for wsave,R4 resprent for ssave, R5 resprent for psave
interrupt_service_routine_0x14
_00040_DS_
;	.line	139; "../main.c"	}
	IRET	



func._main	.code
;***
;  PostBlock Stats: dbName = M
;***
;entry:  _main	;Function start
; 2 exit points
;has an exit
;functions called:
;   _init_mcu
;   _init_pwm
;   _Delay_ms
;   _pwm_function
;   _Delay_ms
;   _init_mcu
;   _init_pwm
;   _Delay_ms
;   _pwm_function
;   _Delay_ms
;1 compiler assigned register :
;   STK00
;; Starting PostCode block
;	op : LABEL
;	op : FUNCTION
_main	;Function start
; 2 exit points
;	op : CALL
;	.line	118; "../main.c"	init_mcu();
	PAGESEL	_init_mcu
	CALL	_init_mcu
	PAGESEL	$
;	op : CALL
;	.line	119; "../main.c"	init_pwm();
	PAGESEL	_init_pwm
	CALL	_init_pwm
	PAGESEL	$
;	op : SEND
;	op : CALL
;	.line	120; "../main.c"	Delay_ms(10);
	MOV	R0,# 0x0a
	BANKSEL	STK00
	MOV	STK00, R0
	MOV	R0,# 0x00
	PAGESEL	_Delay_ms
	CALL	_Delay_ms
	PAGESEL	$
;	op : LABEL
;	op : CALL
_00033_DS_
;	.line	123; "../main.c"	pwm_function();
	PAGESEL	_pwm_function
	CALL	_pwm_function
	PAGESEL	$
;	op : SEND
;	op : CALL
;	.line	124; "../main.c"	Delay_ms(10);
	MOV	R0,# 0x0a
	BANKSEL	STK00
	MOV	STK00, R0
	MOV	R0,# 0x00
	PAGESEL	_Delay_ms
	CALL	_Delay_ms
	PAGESEL	$
;	op : GOTO
	JMP	_00033_DS_
;	op : LABEL
;	op : ENDFUNCTION
	CRET	
; exit point of _main



func._pwm_function	.code
;***
;  PostBlock Stats: dbName = C
;***
;entry:  _pwm_function	;Function start
; 2 exit points
;has an exit
;; Starting PostCode block
;	op : LABEL
;	op : FUNCTION
_pwm_function	;Function start
; 2 exit points
;	op : IFX
;	.line	92; "../main.c"	if(direction)
	MOV	R0,# 0x00
	BANKSEL	_pwm_function_direction_1_1
	ORL	R0, _pwm_function_direction_1_1
	JNB	PSW, 2
	JMP	_00023_DS_
;	op : +
;	.line	94; "../main.c"	PWM4L0++;
	INC	_PWM4L0
;	op : <
;unsigned compare: left < lit(0xFF=255), size=1
;	.line	95; "../main.c"	if(PWM4L0>=255)
	MOV	R0,# 0xff
	SUB	R0, _PWM4L0
;comparing bytes at offset 0
	JB	PSW, 0
	JMP	_00025_DS_
;	op : =
;	.line	97; "../main.c"	direction=0;
	BANKSEL	_pwm_function_direction_1_1
	CLR	_pwm_function_direction_1_1
;	op : GOTO
	JMP	_00025_DS_
;	op : LABEL
;	op : -
_00023_DS_
;	.line	102; "../main.c"	PWM4L0--;
	DEC	_PWM4L0
;	op : IFX
;	.line	103; "../main.c"	if(PWM4L0==0)
	MOV	R0,# 0x00
	ORL	R0, _PWM4L0
	JB	PSW, 2
	JMP	_00025_DS_
;	op : =
;	.line	105; "../main.c"	direction=1;
	MOV	R0,# 0x01
	BANKSEL	_pwm_function_direction_1_1
	MOV	_pwm_function_direction_1_1, R0
;	op : LABEL
;	op : ENDFUNCTION
_00025_DS_
	CRET	
; exit point of _pwm_function



func._init_pwm	.code
;***
;  PostBlock Stats: dbName = C
;***
;entry:  _init_pwm	;Function start
; 2 exit points
;has an exit
;; Starting PostCode block
;	op : LABEL
;	op : FUNCTION
_init_pwm	;Function start
; 2 exit points
;	op : =
;	.line	65; "../main.c"	PWM4CTL1=0x00;	// 不开启自动使能，死区仅对半桥有效。
	CLR	_PWM4CTL1
;	op : =
;	.line	66; "../main.c"	P4ASCTL=0x00;	// 禁止自动关闭源，默认关闭状态为1。
	CLR	_P4ASCTL
;	op : =
;	.line	67; "../main.c"	PATRCTL=0x1F;	// 开启转向同步，全部输出，0x11 P3A 0x12 P3B  0x14 P3C 0x18 P3D
	MOV	R0,# 0x1f
	MOV	_PATRCTL, R0
;	op : =
;	.line	69; "../main.c"	PP4H=0X00;
	CLR	_PP4H
;	op : =
;	.line	70; "../main.c"	PP4L=0XFF;		//T=(0X00FF+1)*(1/16MHz)*1=16us，F=1/T=62.5KHz
	MOV	R0,# 0xff
	MOV	_PP4L, R0
;	op : =
;	.line	72; "../main.c"	PWM4L0=0X80;	//初始化占空比0X0080/(0X00FF+1)=50%
	MOV	R0,# 0x80
	MOV	_PWM4L0, R0
;	op : =
;	.line	73; "../main.c"	PWM4L1=0X00;
	CLR	_PWM4L1
;	op : =
;	.line	76; "../main.c"	T2H=0;
	CLR	_T2H
;	op : =
;	.line	77; "../main.c"	T2L=0;
	CLR	_T2L
;	op : =
;	.line	78; "../main.c"	T2CTL=0X04;		// 启动T2，T2分频比1
	MOV	R0,# 0x04
	MOV	_T2CTL, R0
;	op : =
;	.line	80; "../main.c"	PWM4CTL0=0x0C;  // 单输出模式，开启PWM4，默认有效状态高电平。
	MOV	R0,# 0x0c
	MOV	_PWM4CTL0, R0
;	op : LABEL
;	op : ENDFUNCTION
	CRET	
; exit point of _init_pwm



func._init_mcu	.code
;***
;  PostBlock Stats: dbName = C
;***
;entry:  _init_mcu	;Function start
; 2 exit points
;has an exit
;; Starting PostCode block
;	op : LABEL
;	op : FUNCTION
_init_mcu	;Function start
; 2 exit points
;	op : =
;	.line	42; "../main.c"	OSCCTL = 0X70;      // 16M时钟
	MOV	R0,# 0x70
	MOV	_OSCCTL, R0
;	op : =
;	.line	45; "../main.c"	TR0 = 0x08;				//设置P03端口为输入，P0其他I/O口为输出
	MOV	R0,# 0x08
	MOV	_TR0, R0
;	op : =
;	.line	46; "../main.c"	TR1 = 0x00;				//设置P1端口为输出
	CLR	_TR1
;	op : =
;	.line	47; "../main.c"	TR2 = 0x00;				//设置P2端口为输出
	CLR	_TR2
;	op : =
;	.line	48; "../main.c"	P0 = 0;
	CLR	_P0
;	op : =
;	.line	49; "../main.c"	P1 = 0;
	CLR	_P1
;	op : =
;	.line	50; "../main.c"	P2 = 0;
	CLR	_P2
;	op : =
;	.line	51; "../main.c"	P0LR = 0;				//P0口输出低电平
	CLR	_P0LR
;	op : =
;	.line	52; "../main.c"	P1LR = 0;				//P1口输出低电平
	CLR	_P1LR
;	op : =
;	.line	53; "../main.c"	P2LR = 0;				//P2口输出低电平
	CLR	_P2LR
;	op : LABEL
;	op : ENDFUNCTION
	CRET	
; exit point of _init_mcu



func._Delay_ms	.code
;***
;  PostBlock Stats: dbName = C
;***
;entry:  _Delay_ms	;Function start
; 2 exit points
;has an exit
;5 compiler assigned registers:
;   r0x1001
;   STK00
;   r0x1002
;   r0x1003
;   r0x1004
;; Starting PostCode block
;	op : LABEL
;	op : FUNCTION
_Delay_ms	;Function start
; 2 exit points
;	op : RECEIVE
;	.line	23; "../main.c"	void Delay_ms(uint ms_data)
	BANKSEL	r0x1001
	MOV	r0x1001, R0
	BANKSEL	STK00
	MOVZ	R0, STK00
	BANKSEL	r0x1002
	MOV	r0x1002, R0
;	op : =
;	op : LABEL
;	op : =
_00004_DS_
;	.line	26; "../main.c"	while(ms_data--)
	BANKSEL	r0x1002
	MOVZ	R0, r0x1002
	BANKSEL	r0x1003
	MOV	r0x1003, R0
	BANKSEL	r0x1001
	MOVZ	R0, r0x1001
	BANKSEL	r0x1004
	MOV	r0x1004, R0
;	op : -
	MOV	R0,# 0xff
	BANKSEL	r0x1002
	ADD	r0x1002, R0
	JNB	PSW, 0
	JMP	_00042_DS_
	BANKSEL	r0x1001
	DEC	r0x1001
;	op : IFX
_00042_DS_
	BANKSEL	r0x1003
	MOVZ	R0, r0x1003
	BANKSEL	r0x1004
	ORL	R0, r0x1004
	JNB	PSW, 2
	JMP	_00007_DS_
;	op : =
;	.line	29; "../main.c"	while(i--);
	MOV	R0,# 0x7c
	BANKSEL	r0x1003
	MOV	r0x1003, R0
;	op : LABEL
;	op : =
_00001_DS_
	BANKSEL	r0x1003
	MOVZ	R0, r0x1003
	BANKSEL	r0x1004
	MOV	r0x1004, R0
;	op : -
	BANKSEL	r0x1003
	DEC	r0x1003
;	op : IFX
	MOV	R0,# 0x00
	BANKSEL	r0x1004
	ORL	R0, r0x1004
	JNB	PSW, 2
	JMP	_00004_DS_
;	op : GOTO
	JMP	_00001_DS_
;	op : LABEL
;	op : ENDFUNCTION
_00007_DS_
	CRET	
; exit point of _Delay_ms


;	code size estimation:
;	  101+   21 =   122 instructions (  286 byte)


	.end
