;--------------------------------------------------------
; 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 15:05:05 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	_Full_Bridge_Way
	.global	_Full_PWM_Bak

	.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
;--------------------------------------------------------
UD_main_0	.udata
_Full_Bridge_Way	.res	1

UD_main_1	.udata
_Full_PWM_Bak	.res	1

;--------------------------------------------------------
; absolute symbol definitions
;--------------------------------------------------------
;--------------------------------------------------------
; compiler-defined variables
;--------------------------------------------------------
UDL_main_0	.udata
r0x1003	.res	1
UDL_main_1	.udata
r0x1002	.res	1
UDL_main_2	.udata
r0x1004	.res	1
UDL_main_3	.udata
r0x1005	.res	1
;--------------------------------------------------------
; initialized data
;--------------------------------------------------------
;--------------------------------------------------------
; 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
_00030_DS_
;	.line	143; "../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
_00032_DS_
;	.line	150; "../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	129; "../main.c"	init_mcu();
	PAGESEL	_init_mcu
	CALL	_init_mcu
	PAGESEL	$
;	op : CALL
;	.line	130; "../main.c"	init_pwm();
	PAGESEL	_init_pwm
	CALL	_init_pwm
	PAGESEL	$
;	op : SEND
;	op : CALL
;	.line	131; "../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
_00025_DS_
;	.line	134; "../main.c"	pwm_function();
	PAGESEL	_pwm_function
	CALL	_pwm_function
	PAGESEL	$
;	op : SEND
;	op : CALL
;	.line	135; "../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	_00025_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
;functions called:
;   _Delay_ms
;   _Delay_ms
;   _Delay_ms
;   _Delay_ms
;1 compiler assigned register :
;   STK00
;; Starting PostCode block
;	op : LABEL
;	op : FUNCTION
_pwm_function	;Function start
; 2 exit points
;	op : IFX
;	.line	101; "../main.c"	if(Full_Bridge_Way)
	MOV	R0,# 0x00
	BANKSEL	_Full_Bridge_Way
	ORL	R0, _Full_Bridge_Way
	JNB	PSW, 2
	JMP	_00019_DS_
;	op : =
;	.line	103; "../main.c"	Full_PWM_Bak=PWM4L0;
	MOVZ	R0, _PWM4L0
	BANKSEL	_Full_PWM_Bak
	MOV	_Full_PWM_Bak, R0
;	op : =
;	.line	104; "../main.c"	PWM4L0=0x3F;				// 暂时降低占空比
	MOV	R0,# 0x3f
	MOV	_PWM4L0, R0
;	op : SEND
;	op : CALL
;	.line	105; "../main.c"	Delay_ms(1);			// 延后1个周期的时间，使占空比生效
	MOV	R0,# 0x01
	BANKSEL	STK00
	MOV	STK00, R0
	MOV	R0,# 0x00
	PAGESEL	_Delay_ms
	CALL	_Delay_ms
	PAGESEL	$
;	op : |
;	.line	106; "../main.c"	PWM4CTL0|=0x80;
	SET	_PWM4CTL0, 7
;	op : =
;	.line	107; "../main.c"	Full_Bridge_Way=0;
	BANKSEL	_Full_Bridge_Way
	CLR	_Full_Bridge_Way
;	op : =
;	.line	108; "../main.c"	PWM4L0=Full_PWM_Bak;		// 占空比还原
	BANKSEL	_Full_PWM_Bak
	MOVZ	R0, _Full_PWM_Bak
	MOV	_PWM4L0, R0
;	op : GOTO
	JMP	_00021_DS_
;	op : LABEL
;	op : =
_00019_DS_
;	.line	112; "../main.c"	Full_PWM_Bak=PWM4L0;
	MOVZ	R0, _PWM4L0
	BANKSEL	_Full_PWM_Bak
	MOV	_Full_PWM_Bak, R0
;	op : =
;	.line	113; "../main.c"	PWM4L0=0x3F;				// 暂时降低占空比
	MOV	R0,# 0x3f
	MOV	_PWM4L0, R0
;	op : SEND
;	op : CALL
;	.line	114; "../main.c"	Delay_ms(1);			// 延后1个周期的时间，使占空比生效
	MOV	R0,# 0x01
	BANKSEL	STK00
	MOV	STK00, R0
	MOV	R0,# 0x00
	PAGESEL	_Delay_ms
	CALL	_Delay_ms
	PAGESEL	$
;	op : BITWISEAND
;	.line	115; "../main.c"	PWM4CTL0&=0x7F;
	CLR	_PWM4CTL0, 7
;	op : =
;	.line	116; "../main.c"	Full_Bridge_Way=1;
	MOV	R0,# 0x01
	BANKSEL	_Full_Bridge_Way
	MOV	_Full_Bridge_Way, R0
;	op : =
;	.line	117; "../main.c"	PWM4L0=Full_PWM_Bak;		// 占空比还原
	BANKSEL	_Full_PWM_Bak
	MOVZ	R0, _Full_PWM_Bak
	MOV	_PWM4L0, R0
;	op : LABEL
;	op : ENDFUNCTION
_00021_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	71; "../main.c"	PWM4CTL1=0x80;	// 开启自动使能，死区仅对半桥有效
	MOV	R0,# 0x80
	MOV	_PWM4CTL1, R0
;	op : =
;	.line	72; "../main.c"	P4ASCTL=0x44;	// 选择自动关闭源 INT0（P02）为低电平   关闭状态下P3A、P3C端口为高电平    P3B、P3D端口为低电平
	MOV	R0,# 0x44
	MOV	_P4ASCTL, R0
;	op : =
;	.line	73; "../main.c"	PATRCTL=0x10;	// 开启转向同步
	MOV	R0,# 0x10
	MOV	_PATRCTL, R0
;	op : =
;	.line	75; "../main.c"	PP4H=0X00;
	CLR	_PP4H
;	op : =
;	.line	76; "../main.c"	PP4L=0XFF;		//T=(0X00FF+1)*(1/16MHz)*1=16us，F=1/T=62.5KHz
	MOV	R0,# 0xff
	MOV	_PP4L, R0
;	op : =
;	.line	78; "../main.c"	PWM4L0=0X80;	//初始化占空比0X0080/(0X00FF+1)=50%
	MOV	R0,# 0x80
	MOV	_PWM4L0, R0
;	op : =
;	.line	79; "../main.c"	PWM4L1=0X00;
	CLR	_PWM4L1
;	op : =
;	.line	82; "../main.c"	T2H=0;
	CLR	_T2H
;	op : =
;	.line	83; "../main.c"	T2L=0;
	CLR	_T2L
;	op : =
;	.line	84; "../main.c"	T2CTL=0X04;		// 启动T2，T2分频比1
	MOV	R0,# 0x04
	MOV	_T2CTL, R0
;	op : =
;	.line	86; "../main.c"	PWM4CTL0=0x4C;  // 全桥正向输出模式，默认有效状态高电平。
	MOV	R0,# 0x4c
	MOV	_PWM4CTL0, R0
;	op : =
;	.line	88; "../main.c"	Full_Bridge_Way=1;
	MOV	R0,# 0x01
	BANKSEL	_Full_Bridge_Way
	MOV	_Full_Bridge_Way, 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	45; "../main.c"	OSCCTL = 0X70;      // 16M时钟
	MOV	R0,# 0x70
	MOV	_OSCCTL, R0
;	op : =
;	.line	48; "../main.c"	TR0 = 0x0C;				//设置P03端口为输入，P0其他I/O口为输出，P02设为自动关断源，所以设为上拉输入
	MOV	R0,# 0x0c
	MOV	_TR0, R0
;	op : =
;	.line	49; "../main.c"	TR1 = 0x00;				//设置P1端口为输出
	CLR	_TR1
;	op : =
;	.line	50; "../main.c"	TR2 = 0x00;				//设置P2端口为输出
	CLR	_TR2
;	op : =
;	.line	51; "../main.c"	P0 = 0;
	CLR	_P0
;	op : =
;	.line	52; "../main.c"	P1 = 0;
	CLR	_P1
;	op : =
;	.line	53; "../main.c"	P2 = 0;
	CLR	_P2
;	op : =
;	.line	54; "../main.c"	P0LR = 0;				//P0口输出低电平
	CLR	_P0LR
;	op : =
;	.line	55; "../main.c"	P1LR = 0;				//P1口输出低电平
	CLR	_P1LR
;	op : =
;	.line	56; "../main.c"	P2LR = 0;				//P2口输出低电平
	CLR	_P2LR
;	op : =
;	.line	58; "../main.c"	PUPH = 0;        		// 使能总上拉 PUPH
	CLR	_OPTR_bits, 7
;	op : =
;	.line	59; "../main.c"	PUR = 0X04;         	// 使能P02上拉，P02设为自动关断源，所以设为上拉输入
	MOV	R0,# 0x04
	MOV	_PUR, R0
;	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:
;   r0x1002
;   STK00
;   r0x1003
;   r0x1004
;   r0x1005
;; Starting PostCode block
;	op : LABEL
;	op : FUNCTION
_Delay_ms	;Function start
; 2 exit points
;	op : RECEIVE
;	.line	26; "../main.c"	void Delay_ms(uint ms_data)
	BANKSEL	r0x1002
	MOV	r0x1002, R0
	BANKSEL	STK00
	MOVZ	R0, STK00
	BANKSEL	r0x1003
	MOV	r0x1003, R0
;	op : =
;	op : LABEL
;	op : =
_00004_DS_
;	.line	29; "../main.c"	while(ms_data--)
	BANKSEL	r0x1003
	MOVZ	R0, r0x1003
	BANKSEL	r0x1004
	MOV	r0x1004, R0
	BANKSEL	r0x1002
	MOVZ	R0, r0x1002
	BANKSEL	r0x1005
	MOV	r0x1005, R0
;	op : -
	MOV	R0,# 0xff
	BANKSEL	r0x1003
	ADD	r0x1003, R0
	JNB	PSW, 0
	JMP	_00034_DS_
	BANKSEL	r0x1002
	DEC	r0x1002
;	op : IFX
_00034_DS_
	BANKSEL	r0x1004
	MOVZ	R0, r0x1004
	BANKSEL	r0x1005
	ORL	R0, r0x1005
	JNB	PSW, 2
	JMP	_00007_DS_
;	op : =
;	.line	32; "../main.c"	while(i--);
	MOV	R0,# 0x7c
	BANKSEL	r0x1004
	MOV	r0x1004, R0
;	op : LABEL
;	op : =
_00001_DS_
	BANKSEL	r0x1004
	MOVZ	R0, r0x1004
	BANKSEL	r0x1005
	MOV	r0x1005, R0
;	op : -
	BANKSEL	r0x1004
	DEC	r0x1004
;	op : IFX
	MOV	R0,# 0x00
	BANKSEL	r0x1005
	ORL	R0, r0x1005
	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:
;	  124+   28 =   152 instructions (  360 byte)


	.end
