LIST p=P16F1936
INCLUDE <P16F1936.INC>
__CONFIG _CONFIG1, _FOSC_HS& _WDTE_OFF& _PWRTE_OFF& _MCLRE_ON& _CP_OFF& _CPD_OFF& _BOREN_OFF& _CLKOUTEN_ON& _IESO_OFF& _FCMEN_ON
__CONFIG _CONFIG2, _WRT_OFF& _VCAPEN_OFF& _PLLEN_ON& _STVREN_OFF& _BORV_19& _LVP_OFF
INCLUDE <parameters.INC>
;**************************************************************************************
UDATA_SHR
W_TEMP RES 1 ;LOCATION FOR SAVING 'WREG' DURING INTERRUPT
STATUS_TEMP RES 1 ;LOCATION FOR SAVING 'STATUS' DURING INTERRUPT
TEMP_LOC RES 1 ;GENERAL PURPOSE TEMPORARY LOCATION
TEMP_LOC_1 RES 1 ;GENERAL PURPOSE TEMPORARY LOCATION
TEMP_LOC_2 RES 1 ;GENERAL PURPOSE TEMPORARY LOCATION
UDATA
TABLE_Value RES 0X24 ;SINE TABLE
GLOBAL TEMP_LOC
GLOBAL TEMP_LOC_1
GLOBAL TEMP_LOC_2
;**************************************************************************************
;MACRO FOR MULTIPLICATION - 8X8 UNSIGNED
;**************************************************************************************
MULT MACRO BIT ;MACRO FOR UNSIGNEDMULTIPLICATION
BTFSC NO_1_LSB,BIT
ADDWF RESULT_MSB,F
RRF RESULT_MSB,F
RRF RESULT_LSB,F
ENDM ;END OF MACRO FOR MULTIPLICATION
;**************************************************************************************
;POWER ON RESET VECTOR LOCATION
;**************************************************************************************
STARTUP CODE 0X00 ;RESET VECTOR ADDRESS
GOTO START
;******************************************************************
;INTERRUPT SERVICE ROUTINE
;******************************************************************
;******************************************************************
CODE 0x004
MOVWF W_TEMP ;COPY W TO A TEMPORARY REGISTER
SWAPF STATUS,W ;SWAP STATUS NIBBLES AND PLACE INTO W REGISTER
MOVWF STATUS_TEMP ;SAVE STATUS TO A TEMPORARY REGISTER IN BANK0
SWAPF STATUS_TEMP,W ;SWAP ORIGINAL STATUS REGISTER VALUE INTO W (RESTORES ORIGINAL BANK)
MOVWF STATUS ;RESTORE STATUS REGISTER FROM W REGISTER
SWAPF W_TEMP,F ;SWAP W_TEMP NIBBLES AND RETURN VALUE TO W_TEMP
SWAPF W_TEMP,W ;SWAP W_TEMP TO W TO RESTORE ORIGINAL W VALUE WITHOUT AFFECTING STATUS
RETFIE ;RETURN FROM INTERRUPT
;******************************************************************
; CODE 0X04 ;INTERRUPT VECTOR LOCATION
;GOTO ISR_INT ;GOTO INTERRUPT SERVICE ROUTINE
;**************************************************************************************
PROG0 CODE
START
;**************************************************************************************
;INITIALIZATION OF THE PORTS AND TIMERS
CLRWDT
;//////////////////////////////////////////////////////////////////////////////////////////////////////
; PORT DATA DEFINITION
;**************************************************************************************
;***********************************************
; PORTS CONFIGURATION
;**********************************************
MOVLW 0x00
BANKSEL TRISC
MOVWF TRISC
BANKSEL PORTC
CLRF PORTC
; MOVLW 0x03
;BANKSEL TRISB
;MOVWF TRISB
BANKSEL LATC
CLRF LATC
; BANKSEL LATE
;CLRF LATE
;//////////////////////////////////////////////////////////////
; REGISTER DEFINITION
;/////////////////////////////////////////////////////////////
BANKSEL FVRCON
MOVLW 0X00
MOVWF FVRCON
BANKSEL CCP1CON
CLRF CCP1CON
BANKSEL CCP2CON
CLRF CCP2CON
BANKSEL CCP3CON
CLRF CCP3CON
; BANKSEL TRISC
;BSF TRISC,1
;BSF TRISC,2
;BSF TRISC,6
;CLRF TRISC
BANKSEL PORTB
CLRF PORTB
BANKSEL TRISB
CLRF TRISB
BANKSEL LATB
CLRF LATB
MOVLW 0X00
BANKSEL WPUB
MOVWF WPUB
BANKSEL WPUE
MOVWF WPUE
BANKSEL LATE
MOVWF LATE
BANKSEL LATA
MOVWF LATA
BANKSEL LATB
MOVWF LATB
MOVLW 0X00
BANKSEL LATC
MOVWF LATC
BANKSEL OSCCON
MOVLW 0X38
MOVWF OSCCON
BANKSEL APFCON
MOVLW 0X00
MOVWF APFCON
MOVLW 0XBC ;for Half bridge configuration
BANKSEL CCP1CON
MOVWF CCP1CON ;CCP1,CCP2 AND CCP3 CONFIGURED TO PWM
BANKSEL CCP2CON
MOVWF CCP2CON
BANKSEL CCP3CON
MOVWF CCP3CON
BANKSEL PWM1CON
MOVLW 0X80
MOVWF PWM1CON
BANKSEL PWM2CON
MOVWF PWM2CON
BANKSEL PWM3CON
MOVWF PWM3CON
BANKSEL PSTR1CON
BANKSEL CCPTMRS0 ;select the TMR2 on which CCP1,CCP2 and CCP3 are based
MOVLW 0x00
MOVWF CCPTMRS0
BANKSEL PIR1
BCF PIR1,TMR2IF
BANKSEL PR2
;MOVLW PR2_VALUE ;LOAD PR2 VALUE TO PR2 REGISTER
;MOVWF PR2
; CALL STOP_MOTOR
;MOVLW d'7'
;BANKSEL T2CON
;MOVWF T2CON
clrf CCPR1L
prog
BANKSEL PR2
MOVLW PR2_VALUE
MOVWF PR2
MOVLW 0X0C
BANKSEL CCP1CON
MOVWF CCP1CON
BANKSEL T2CON
BSF T2CON,TMR2ON
CALL COPY_TABLE_TO_RAM
GOTO START
RETURN
;*******************************************************************
;Copy Table to RAM
;*****************************************************************
COPY_TABLE_TO_RAM
BANKSEL TABLE_Value
BANKISEL TABLE_Value
MOVLW LOW(TABLE_Value)
MOVWF FSR1L
MOVLW HIGH(TABLE_Value)
MOVWF FSR1H
MOVIW 0[FSR1]
MOVLW 0X79
MOVWF TEMP_LOC
CLRF TEMP_LOC_1
BANKSEL TRISC
BCF TRISC,2
COPY_AGAIN
MOVLW HIGH(SINE_TABLE)
MOVWF PCLATH
MOVIW 0[FSR1]
MOVF TEMP_LOC_1,W
PAGESEL SINE_TABLE
CALL SINE_TABLE
BANKSEL CCPR1L
MOVWF CCPR1L
MOVWF INDF1
INCF TEMP_LOC_1,F
INCF FSR1L,F
DECFSZ TEMP_LOC,F
GOTO COPY_AGAIN
MOVLW HIGH(TABLE_Value)
MOVWF FSR1H
MOVLW LOW(TABLE_Value) ;FSR POINTS TO THE STARTING OF THE TABLE
MOVWF FSR1L
MOVIW 0[FSR1]
RETURN
;*******************************************************************************
;EQUATION USED FOR CALCULATION OF SINE TABLE ENTRIES = (SIN(ANGLE)+1)*FF/2
;ANGLES ARE FROM 270 DEG. TO 90 DEG. STEP SIZE = 10 DEG.
;*******************************************************************************
TABLE CODE 0X0035
SINE_TABLE
BRW
ADDWF PCL,F
RETLW 0x7B
RETLW 0x7F
RETLW 0x81
RETLW 0x85
RETLW 0x87
RETLW 0x8B
RETLW 0x8D
RETLW 0x91
RETLW 0x92
RETLW 0x96
RETLW 0x98
RETLW 0x9C
RETLW 0x9E
RETLW 0xA2
RETLW 0xA4
RETLW 0xA7
RETLW 0xA9
RETLW 0xAD
RETLW 0xAE
RETLW 0xB1
RETLW 0xB3
RETLW 0xB6
RETLW 0xB8
RETLW 0xBB
RETLW 0xBD
RETLW 0xC0
RETLW 0xC2
RETLW 0xC5
RETLW 0xC6
RETLW 0xC9
RETLW 0xCB
RETLW 0xCD
RETLW 0xCF
RETLW 0xD1
RETLW 0xD2
RETLW 0xD5
RETLW 0xD6
RETLW 0xD8
RETLW 0xDA
RETLW 0xDB
RETLW 0xDD
RETLW 0xDE
RETLW 0xDF
RETLW 0xE1
RETLW 0xE2
RETLW 0xE3
RETLW 0xE4
RETLW 0xE5
RETLW 0xE6
RETLW 0xE7
RETLW 0xE7
RETLW 0xE9
RETLW 0xE9
RETLW 0xEA
RETLW 0xEA
RETLW 0xEB
RETLW 0xEB
RETLW 0xEB
RETLW 0xEC
RETLW 0xEC
RETLW 0xEC
RETLW 0xEC
RETLW 0xEC
RETLW 0xEB
RETLW 0xEB
RETLW 0xEB
RETLW 0xEA
RETLW 0xE9
RETLW 0xE9
RETLW 0xE8
RETLW 0xE7
RETLW 0xE7
RETLW 0xE6
RETLW 0xE5
RETLW 0xE4
RETLW 0xE3
RETLW 0xE2
RETLW 0xE0
RETLW 0xDF
RETLW 0xDE
RETLW 0xDD
RETLW 0xDA
RETLW 0xDA
RETLW 0xD7
RETLW 0xD6
RETLW 0xD4
RETLW 0xD2
RETLW 0xD0
RETLW 0xCF
RETLW 0xCC
RETLW 0xCB
RETLW 0xC8
RETLW 0xC6
RETLW 0xC3
RETLW 0xC2
RETLW 0xBF
RETLW 0xBD
RETLW 0xBA
RETLW 0xB8
RETLW 0xB5
RETLW 0xB3
RETLW 0xB0
RETLW 0xAE
RETLW 0xAB
RETLW 0xA9
RETLW 0xA5
RETLW 0xA4
RETLW 0x9F
RETLW 0x9E
RETLW 0x9A
RETLW 0x98
RETLW 0x94
RETLW 0x92
RETLW 0x8E
RETLW 0x8D
RETLW 0x89
RETLW 0x87
RETLW 0x83
RETLW 0x81
RETLW 0x7D
RETLW 0x7B
;*******************************************************************************
;END OF FILE
;*******************************************************************************
END