⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foc_1.asm.bak

📁 foc 通信程序源码
💻 BAK
📖 第 1 页 / 共 4 页
字号:
		add serialtmp 			;add ACC with lower byte
		sacl p1 				;store it in p1

navail85
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;is there any available (8 LSB)?
		bcnd navail51,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF
		and #0FFh 				;take the 8 LSB
		ldp #04h 			    ;control variable page
		sacl serialtmp 			;if yes, get it and store it in serialtmp

navail86
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;8 MSB available ?
		bcnd navail52,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF,8 		;load ACC the upper byte
		ldp #04h 			    ;control variable page
		add serialtmp 			;add ACC with lower byte
		sacl p2 			    ;store it in p2
		
navail87
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;is there any available (8 LSB)?
		bcnd navail51,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF
		and #0FFh 				;take the 8 LSB
		ldp #04h 			    ;control variable page
		sacl serialtmp 			;if yes, get it and store it in serialtmp

navail88
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;8 MSB available ?
		bcnd navail52,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF,8 		;load ACC the upper byte
		ldp #04h 			    ;control variable page
		add serialtmp 			;add ACC with lower byte
		sacl p3 			    ;store it in p3		
		B menu                               

noteight 
       lacc option
		sub #09h 				;is it option 8 ?
		bcnd notnine,neq 		;if not branch to noteight

**************************************************
*option 9) specify plot data
*************************************************

navail91
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;is there any available (8 LSB)?
		bcnd navail91,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF
		and #0FFh 				;take the 8 LSB
		ldp #04h 			;control variable page
		sacl serialtmp 			;if yes, get it and store it in serialtmp

navail92
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;8 MSB available ?
		bcnd navail92,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF,8 		;load ACC the upper byte
		ldp #04h 			    ;control variable page
		add serialtmp 			;add ACC with lower byte
		sacl adr1 				;store it in adr1	
		
navail93
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;is there any available (8 LSB)?
		bcnd navail93,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF
		and #0FFh 				;take the 8 LSB
		ldp #04h 			;control variable page
		sacl serialtmp 			;if yes, get it and store it in serialtmp

navail94
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;8 MSB available ?
		bcnd navail94,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF,8 		;load ACC the upper byte
		ldp #04h 			    ;control variable page
		add serialtmp 			;add ACC with lower byte
		sacl adr2 				;store it in adr2
		
navail95
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;is there any available (8 LSB)?
		bcnd navail95,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF
		and #0FFh 				;take the 8 LSB
		ldp #04h 			;control variable page
		sacl serialtmp 			;if yes, get it and store it in serialtmp

navail96
		ldp #DP_PF1
		bit SCIRXST,BIT6 		;8 MSB available ?
		bcnd navail96,ntc 		;if not repeat the cycle (polling)
		lacc SCIRXBUF,8 		;load ACC the upper byte
		ldp #04h 			    ;control variable page
		add serialtmp 			;add ACC with lower byte
		sacl adr3 				;store it in adr3	
		
notnine  
        lacc option
		sub #99h 	 			;is it option 8 ?
		bcnd nottrans,neq 		;if not branch to noteight


*********************************************************************************
*    current transmite
********************************************************************************* 
	 		LAR AR4,#BUFFERSTART	
 	 		MAR *,AR4  
	        LDP 	#00H
            splk    #11H, IMR	
XMIT_CHAR
			LDP #05h
			LACL num
			ADD #01h
			SACL num
			SUB #601
			BCND ENDTRASMITE,EQ	 

			LACC *         ;发送低字节
		    AND #00ffh 
            LDP #0E0h
            SACL  SCITXBUF 
XWAITRDY    BIT SCICTL2,8
            BCND XWAITRDY,NTC  

            LACC *+           ;发送高字节
            AND #0FF00h 
            RPT #7
            SFR 
            LDP #0E0h
            SACL SCITXBUF  
XWAITRDY1   BIT SCICTL2,8
            BCND XWAITRDY1,NTC     
			B XMIT_CHAR       ;发送下一字节
		
ENDTRASMITE 
        LDP #05h
        ZAC
        SACL num
         LDP 	#00H
                splk    #13H, IMR	
   
nottrans  
			B menu             

		
		 	
********************************************************************


*************************************************************                                                                                                         
;中断2:定时器1下溢中断(T1UFINT)和过流保护中断(PDP interrupt)
*************************************************************		
GISR2	MAR	*,AR1          ;protect ST0,ST1,ACC
		MAR	*+             ;SP=(AR1)
		SST	#1,*+
		SST	#0, *+                                                                                                                        
		SACH	*+                                                                                                                           
		SACL	*
				

		
		LDP	#232           ;LDP #E8H
		LACC	EVIVRA
		SUB	#29H           ;T1UFINT interrupt vector:0029H
		BCND	TIM,EQ     ;vector=0029H,T1UFINT,GOTO TIM
		B       PDP        ;vector<>0029H,PDPINT,GOTO PDP  
		
		
TIM             
		LACC	EVIFRA     ;clear interrupt flag		
		SACL	EVIFRA                          
		
		B	TIMER1			;跳至定时器中断服务程序   
		
		
                		
PDP     LACC	EVIFRA			;过流保护处理,stop and alarm
		SACL	EVIFRA			;清中断标志	
			
        LDP	#4			;200H-027FH
		STOP
		LDP	#4
		splk    #1,FailFlag
		
		ALARM
		
		Y1ON
	        
		MAR	*,AR1                ;resume values of ACC,ST0,ST1
		LACL	*-
		ADDH	*-
		LST	#0, *-
		LST	#1, *-      
		
 		CLRC	INTM             ;ENABLED INTERRUPT
		RET
;================================================================================



************************************************************
;定时器1下溢中断          
;TIME1 is used to specify the sample time.
;At every TIME1 under flow interrupt,sampleing startes.     
************************************************************
TIMER1:		
		CLRC	INTM         ;enabled interrupts
;-------------------------------------------------------------------
; A/D START FOR ia AND ic
;Scale of current=2^10 ,6.10f
;i(scaled)=AD*18.26601308589056*(2^10/2^10)=AD*18704.4/2^10
;------------------------------------------------------------------- 
				LDP     #05H
				LACC    running
				BCND    NOINIT,NEQ
				LACC    #0
				LDP		#04H
				SACL	Vsalfa_ref
				SACL 	Vsbeta_ref
				B		INIT
				
NOINIT                                                              
                LDP     #0E0H
                splk    #1011100100100101B, ADCTRL1	;启动电流采样
                                
conversion
			BIT ADCTRL1,8
			BCND conversion,TC ;wait for AD conversion end 
			
			LACC ADCFIFO2,10   ;10.6f
			LDP #04h        ;control variables page 
            SACH tmp		   ;10-bits ADC output in ACC low 10 bits	
			LACL tmp   
			AND #3FFh
			SUB #512           ;sub the offset 512 (2.5v)to have position and 
			                   ;negative values of the sampled current
			SACL tmp
			SPM 3              ;PM=11,6 right shift after multiplication
			LT tmp
			MPY kia
			PAC
			SFR
			SFR
			SACL ia            ;6+2=8 right shift
			SPM 0
			SUB #78            ;sub the DC offset
			SACL ia            ;sampled current ia,in 4.12f
			
			LDP #DP_PF1
			LACC ADCFIFO1,10   ;10.6f
			LDP #04h        ;control variables page 
            SACH tmp		   ;10-bits ADC output in ACC low 10 bits	
			LACL tmp   
			AND #3FFh
			SUB #512           ;sub the offset 512 (2.5v)to have position and 
			                   ;negative values of the sampled current
			SACL tmp
			SPM 3              ;PM=11,6 right shift after multiplication
			LT tmp
			MPY kib
			PAC
			SFR
			SFR                ;6+2=8 right shift
			SPM 0
			ADD #-65           ;sub the DC offset
			SACL ib            ;sampled current ib,in 4.12f 
			
			LACC    ia
            ADD     ib
            NEG
            SACL    ic			;ic=-(ia+ib)   
       
**************************
*transmit plot data
**************************            
TRANS       
			ldp #05h 
			LACC showindex			;speedstep is a soft variable
   			                        ;for speed calculate period
			SUB #1
			SACL showindex
			BCND notrance,GT          ;speedstep-1>0,a period not arrive,not calculate

;reset showindex and AR6
           LACL  #99h
           LDP #0E0h
           SACL  SCITXBUF
XMITRDY:   BIT SCICTL2,BIT7 
		   BCND XMITRDY,NTC
           
           LDP #05h
           lacc #SHOWINDEX
           sacl showindex 
           LAR AR6,#BUFFERSTART 
              
;save 100 times variables to the buffer           
notrance         
            LDP #05
            LACC saveindex
            SUB #01
            SACL saveindex
            BCND NOSAVEBUF,GT
            
           	MAR *,AR6  
			LDP #04
			LACL ia
			SACL *+
			LACL ib
			SACL *+
			LACL ic
			SACL *+	
			LDP  #05
            LACC #SAVEINDEX
            SACL saveindex
			
NOSAVEBUF					           	
INIT
;环境恢复返回主程序  
		mar 	*,AR1
		lacl 	*- 		;Accu. restored for context restore
		addh 	*-
		lst 	#0,*-
		lst 	#1,*-
		clrc 	INTM
		RET
;----------------------------------------------------------------------------
;TIMER1中断程序结束
;================================================================================



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -