RC Tractor Guy Krampe Half-Pipe Dump Trailer Code

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1287
    RC Tractor GuyRC Tractor Guy
    Keymaster

    Here is the assembly code I use on the PIC 16F627 in the Krampe Half-Pipe Dump Trailer build. If you haven’t used PIC MCUs before I’d advise you do this with an Arduino Pro Mini instead, it is a very simple model.

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Author: Oisin O'Conchubhair                       	;   
    ;Date: 18_09_14                                    	; 
    ;Version: 1.0                                      	;   
    ;Title: Krampe Half-Pipe Trailer Code			; 
    ;                                                  	; 
    ;Description: This code is used to control the SIKU     ;
    ;	      Krampe Half-pipe trailer model. It is     ;
    ;             based on a generic RC Tractor Accessories ;
    ;             code.                                    	;  
    ;                                                  	; 
    ;                                                  	;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
                    PROCESSOR PIC16F627	;Specify the processor being used	
                    INCLUDE   <P16F627.inc> ;Specify the header file, this file must be in the same folfer as the .asm file
                    
    
    ;==========================================================================================================================
    ;       Set configuration options, these commands are found at the bottom of the .inc file. 
    ;	Check the spec sheet for ful descriptions
    ;==========================================================================================================================
    
    	__CONFIG        _BODEN_OFF & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_OFF & _INTRC_OSC_NOCLKOUT 
    
    ;==========================================================================
    ;       Variable Definition
    ;==========================================================================
    TIMER1		EQU	H'20'		;Used in delay routine
    TIMER2		EQU	H'21'		; "	"	"	
    PATERN		EQU	H'22'		;Pattern data for effect's
    OP_1		EQU	H'27'
    OP_2		EQU	H'28'
    OP_3		EQU	H'32'
    OP_4		EQU	H'33'
    OP_5		EQU	H'23'
    OP_6		EQU	H'34'
    OP_7		EQU	H'35'
    OP_8		EQU	H'24'
    OP_9		EQU	H'25'
    OP_10		EQU	H'29'
    RX_FUNC		EQU	H'26'
    
    		ORG	0		;Reset vector address
    		GOTO	RESET		;goto RESET routine when boot.
    
    ;		*********************************************
    ;		*       Delay routine	                    *
    ;		*********************************************
    
    DELAY_ROUTINE   MOVLW   D'255'         ;54 Generate approx 10mS delay at 4Mhz CLK
                    MOVWF   TIMER2
    DEL_LOOP1       MOVLW   D'255'	       ;60	
                    MOVWF   TIMER1
    DEL_LOOP2       DECFSZ  TIMER1,F
                    GOTO    DEL_LOOP2
                    DECFSZ  TIMER2,F
                    GOTO    DEL_LOOP1
    		RETLW   0
    
    ;		*********************************************
    ;		*       Transmit Data                       *
    ;		*********************************************
    
    TX_DATA		MOVWF	TXREG		;Transmit data to following trailer
    		BSF 	STATUS,RP0
    WAIT_1		BTFSS	TXSTA,TRMT
    		GOTO	WAIT_1
    		BCF	STATUS,RP0
    		RETURN
    		
    		
    		
    ;		*********************************************
    ;		*       Recieve Data                        *
    ;		*********************************************
    
    RX_DATA		BTFSC  	PIR1,RCIF	;Check if serial data is present
    
           		GOTO   	RX_HIGH 	;If data is present, go to RX_data          		
    
           		RETURN
    
    RX_HIGH    	MOVF  	RCREG,W 	;Check which command has been recieved
    
    		MOVWF	RX_FUNC
    
    		CLRF   	RCREG
    
          		BCF    	RCSTA,CREN
    
           		BSF    	RCSTA,CREN
           		
           		MOVF	RX_FUNC,W
           		XORWF	OP_1,W
           		BTFSC	STATUS,Z
           		GOTO	FUNC1
           		
           		MOVF	RX_FUNC,W
    		XORWF	OP_2,W
    		BTFSC	STATUS,Z
           		GOTO	FUNC2
          
           		MOVF	RX_FUNC,W
    		XORWF	OP_3,W
    		BTFSC	STATUS,Z
           		GOTO	FUNC3      
          
           		MOVF	RX_FUNC,W
    		XORWF	OP_4,W
    		BTFSC	STATUS,Z
           		GOTO	FUNC4         		
      
           		MOVF	RX_FUNC,W
    		XORWF	OP_5,W
    		BTFSC	STATUS,Z
           		GOTO	FUNC5
          
           		MOVF	RX_FUNC,W
    		XORWF	OP_6,W
    		BTFSC	STATUS,Z
           		GOTO	FUNC6      
          
           		MOVF	RX_FUNC,W
    		XORWF	OP_7,W
    		BTFSC	STATUS,Z
           		GOTO	FUNC7  
          
           		MOVF	RX_FUNC,W
    		XORWF	OP_8,W
    		BTFSC	STATUS,Z
           		GOTO	FUNC8      
          
           		MOVF	RX_FUNC,W
    		XORWF	OP_9,W
    		BTFSC	STATUS,Z
           		GOTO	FUNC9  
           		
          		MOVF	RX_FUNC,W
    		XORWF	OP_10,W
    		BTFSC	STATUS,Z
           		GOTO	FUNC10
        
           		RETURN		
    
    FUNC1		BCF	PORTB,7		;Turn off Right Indicator
    		BSF	PORTB,6		;Turn on Left Indicator
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN
    
    FUNC2		BCF	PORTB,6		;Turn off Left Indicator
    		BSF	PORTB,7		;Turn on Right Indicator
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN
    		
    FUNC3		BSF	PORTB,6		;Turn on Left Indicator
    		BSF	PORTB,7		;Turn on Right Indicator
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN
    		
    FUNC4		BCF	PORTB,6		;Turn off Indicators
    		BCF	PORTB,7
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN		
    
    FUNC5		MOVLW	B'01111101'	;Turn on tail lights
    		MOVWF	CCPR1L
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN
    
    FUNC6		MOVLW	B'11111111'	;Turn on brake lights
    		MOVWF	CCPR1L
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN
    
    FUNC7		CLRF 	CCPR1L		;Turn off tail lights
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN		
    
    FUNC8		BCF	PORTA, 1;	;Raises trailer
    		BSF	PORTA, 2;
    		BSF	PORTA, 0;
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN
    
    FUNC9		BSF	PORTA, 1;	;Lowers trailer
    		BCF	PORTA, 2;
    		BSF	PORTA, 0;
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN			
    
    FUNC10		BCF	PORTA, 0;	;Stops lift motor
    		MOVF	RX_FUNC,W
    		CALL	TX_DATA
    		RETURN
    
    ;	       **********************************
    ;              **  RESET :  main boot routine  **
    ;              **********************************
    
    RESET		MOVLW	B'00000111'	;Disable Comparator module's
    		MOVWF	CMCON
    		;
    		BSF	STATUS,RP0	;Switch to register bank 1
    					;Disable pull-ups
    					;INT on rising edge
    					;TMR0 to CLKOUT
    					;TMR0 Incr low2high trans.
    					;Prescaler assign to Timer0
    					;Prescaler rate is 1:256
    		MOVLW	B'11010111'	;Set PIC options (See datasheet).
    		MOVWF	OPTION_REG	;Write the OPTION register.
    		;
    		CLRF	INTCON		;Disable interrupts
    		MOVLW	B'00010010'
    		MOVWF	TRISB		;RB1 to RB7 are inputs.
    					;RB0 is an outputs.
    		MOVLW	B'00000000'	;all RA ports are outputs
    		MOVWF	TRISA
    		
    		movlw 	B'11111111'     ;Maximum timer count 
    		movwf 	PR2        
    		
    		MOVLW	d'25'		;Set baud rate to 9600 @ 4MHz = 25
    		MOVWF	SPBRG		;                19200 @ 4MHz = 12
    		
    		MOVLW	B'00100110'	;Set transmission control
    		MOVWF	TXSTA
    		
    		BCF	STATUS,RP0	;Switch Back to reg. Bank 0
    		
    		MOVLW	B'10010000'	;Set receive control
    		MOVWF	RCSTA
    		
    		movlw	B'00001111'
    					; 00			single output P1A modulated
    					;   00  		lowest significant bits of the PWM duty cycle
    					;     1111		PWM mode
    		movwf 	CCP1CON 
    						
    		MOVLW 	B'00000110'     ;timer 2 settings
    					;  0000			1:1 postscaler
    					;      1		turn timer 2 on
    					;       10		1:16 prescaler   
    		MOVWF 	T2CON   
    						
    		CLRF 	CCPR1L
    		
    		CLRF	PORTB
    		;
    
    					;Define commands
    		MOVLW	B'00000001'	;Hex 01 turns on left indicator
    		MOVWF	OP_1
    		
    		MOVLW	B'00000010'	;Hex 02 turns on right indicator
    		MOVWF	OP_2
    
    		MOVLW	B'00000011'	;Hex 03 turns on both indicators
    		MOVWF	OP_3
    
    		MOVLW	B'00000100'	;Hex 04 turns off both indicator
    		MOVWF	OP_4
    
    		MOVLW	B'00000101'	;Hex 05 turns on tail lights
    		MOVWF	OP_5
    
    		MOVLW	B'00000110'	;Hex 06 turns on brake lights
    		MOVWF	OP_6
    
    		MOVLW	B'00000111'	;Hex 07 turns off tail lights
    		MOVWF	OP_7
    
    		MOVLW	B'00001000'	;Hex 08 raises trailer
    		MOVWF	OP_8
    
    		MOVLW	B'00001001'	;Hex 09 lowers trailer
    		MOVWF	OP_9
    
    		MOVLW	B'00001010'	;Hex 0A stops lift motor
    		MOVWF	OP_10
    
    MAIN		CALL	RX_DATA		;Continualy search for data
    		GOTO	MAIN
    		END

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.