chravi75
Newbie
; SINE WAVE INVERTER WITH CHARGER
; With TABLE READ and 1XCCP OUT for PWM
CD4081 Gated O/P
; Using PIC16F73 - WITH LCD ONLY
LIST P=16F73,
include "P16F73.inc"
__FUSES _HS_OSC & _PWRTE_ON & _WDT_OFF & _CP_ALL
errorlevel -301,-302,-306
; ***** Variables Definitions *****
selfcheck macro a, bxx
movlw bxx
xorwf a,0
btfsc status,z
endm
selfcheckR macro C,D
movf C,0
xorwf D,0
btfsc status,z
endm
;***** RAM Ddefination ********
RAMbase equ 0x20
cblock RAMbase
PW
CHG_I
r_22
r_23
chg_on
VOLT
COUNT_1
COUNT_2
OL_TRIP
R_29
CHG_DUTY
CHG
r_2C
r_2F
r_30
r_31
S_TEMP
PC_TEMP
TEMP
r_35
r_36
R_37 ;FOR DELAY_1S COUNT
R_38 ;FOR DELAY_1S COUNT
r_39
r_3A
r_3B
r_3C
r_3D
r_3E
r_3F
r_40
r_41
r_42
r_43
r_45
r_46
r_47
r_48
r_49
r_4A
r_4B
r_4C
r_4D
r_4F
r_50
r_51
r_53
r_54
r_56
r_58
r_59
r_70
r_71
r_72
r_73
r_74
r_75
DUTY
BAT_VOLT
OV_LOAD
AC_MAIN
CHG_STAGE
CHG_DELAY
r222
r333
r444
r555
r666
R777
Rxxx
PW_TIMER
PW_BIT
BCDCAL
DUMMY
DUMMY2
TENS
ONES
HUNS
R33
CHAR
R_310
R_560
ENDC
RS EQU 3
EN EQU 2
#DEFINE LCDPORT PORTB
;*******DEFINATION*****************
#DEFINE INV_SW PORTB,1
#DEFINE trickle PORTB,2
#DEFINE MAIN_LED PORTB,3
#DEFINE INV_LED PORTB,4
#DEFINE LB_LED PORTB,5
#DEFINE OL_LED PORTB,6
#DEFINE CHG_LED PORTB,7
#DEFINE UPS PORTC,4
#DEFINE BUZZER PORTC,5
#DEFINE FAN PORTC,6
#DEFINE RELAY PORTC,7
;********************************
; 0.0196V=1 byte *
;********************************
ORG 0x0000
GOTO MAIN_START
ORG 0x0004
;BTFSC CHG,1
;GOTO LED_IND
MOVWF R_72
MOVF STATUS,W
MOVWF R_70 ;satus_temp
MOVF PCLATH,W ;pc_temp
MOVWF R_71
CLRF PCLATH
BTFSC STATUS,RP0
GOTO Label_0002
GOTO Label_0004
Label_0002 MOVF R_72,W
BCF STATUS,RP0
MOVWF R_72
BSF STATUS,RP0
MOVF R_70,W
BCF STATUS,RP0
MOVWF R_70
BSF STATUS,RP0
MOVF R_71,W
BCF STATUS,RP0
MOVWF R_71
Label_0004 BTFSC R_22,5
GOTO Label_000B
MOVLW 0x81
BSF STATUS,RP0
MOVWF T2CON
BCF STATUS,RP0
BCF R_22,6
CLRF R_48
GOTO Label_000C
Label_000B BCF STATUS,Z
movlw 0X0B ;added for table read
subwf duty,w
BTFSS STATUS,Z
GOTO Label_000C
BCF STATUS,Z
MOVF 0x48,W
BTFSC STATUS,Z
BCF R_22,6
BTFSC STATUS,Z
GOTO Label_000C
MOVWF R_41
BSF R_22,6
BSF STATUS,RP0
INCF T2CON,f
BCF STATUS,RP0
Label_000C BCF STATUS,Z
movlw 0X01
subwf duty,w ;added for table read
BTFSS STATUS,Z
GOTO Label_000D
BTFSS R_43,0
GOTO Label_000E
BCF PORTC,2 ;CCP1 out
CLRF CCP1CON
CLRF CCPR1L
CLRF CCPR1H
MOVLW 0x0C
MOVWF CCP1CON
BCF R_43,0
BCF PORTC,1
BSF PORTC,3
MOVF R_45,W
MOVWF R_46
BTFSC R_43,1
BSF R_43,2
BTFSS R_43,1
BCF R_43,2
BTFSC R_22,1
GOTO Label_000F
DECFSZ R_4A,f
BTFSS R_43,2
BSF R_22,1
BTFSS R_43,2
GOTO Label_000F
DECF R_51,f
;MOVLW 0x79
MOVLW 0x40 ;64.8% DUTY
SUBWF R_51,W
;MOVLW 0x79
MOVLW 0x40 ;64.8% DUTY
BTFSS STATUS,C
MOVWF R_51
GOTO Label_000D
Label_000E BCF PORTC,2
CLRF CCP1CON
CLRF CCPR1L
CLRF CCPR1H
MOVLW 0x0C
MOVWF CCP1CON
BSF PORTC,1
BCF PORTC,3
BSF R_43,0
MOVF 0x45,W
MOVWF R_46
BTFSC R_43,1
BSF R_43,2
BTFSS R_43,1
BCF R_43,2
BTFSS R_22,1
GOTO Label_000D
Label_000F BCF STATUS,C
RRF R_46,f
BCF STATUS,C
RRF R_46,f
BTFSS R_43,2
GOTO Label_0010
MOVF R_46,W
SUBWF R_51,f
;MOVLW 0x79
MOVLW 0x40 ;64.8% DUTY
BTFSS STATUS,C
MOVWF R_51
MOVF R_51,W
SUBLW 0x3F
;SUBLW 0x78
;MOVLW 0x79
MOVLW 0x40 ;64.8% DUTY ??????????
BTFSC STATUS,C
MOVWF 0x51
GOTO Label_000D
Label_0010 MOVF R_46,W
ADDWF R_51,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0xFF
SUBWF R_51,W
BTFSS STATUS , C
GOTO Label_000D
MOVLW 0xFE
MOVWF R_51
Label_000D CLRF R_53
movlw 0X07
movwf pclath
call table1
MOVWF R_3A
BCF STATUS,C
RRF R_3A,f
BCF STATUS,C
RRF R_3A,W
MOVWF R_3B
BCF STATUS,C
RRF R_3B,W
MOVWF R_3C
BCF STATUS,C
RRF R_3C,W
MOVWF R_3D
BCF STATUS,C
RRF R_3D,W
MOVWF R_3E
BCF STATUS,C
RRF R_3E,W
MOVWF R_3F
BCF STATUS,C
RRF R_3F,W
MOVWF R_40
COMF R_51,W
MOVWF R_58
DECF R_58,f
;movlw 0X60 ;?????????????????
MOVLW 0x80
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0012
Label_001A MOVLW 0x40
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0013
Label_001B MOVLW 0x20
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0014
Label_001C MOVLW 0x10
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0015
Label_001D MOVLW 0x08
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0016
Label_001E MOVLW 0x04
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0017
Label_001F MOVLW 0x02
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0018
GOTO Label_0019
Label_0012 MOVF R_3A,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x80
SUBWF R_58 , f
GOTO Label_001A
Label_0013 MOVF R_3B,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x40
SUBWF R_58,f
GOTO Label_001B
Label_0014 MOVF R_3C,W
ADDWF R_53,f
BTFSC STATUS , C
GOTO Label_0011
MOVLW 0x20
SUBWF R_58,f
GOTO Label_001C
Label_0015 MOVF R_3D,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x10
SUBWF R_58,f
GOTO Label_001D
Label_0016 MOVF R_3E,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x08
SUBWF R_58,f
GOTO Label_001E
Label_0017 MOVF R_3F,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x04
SUBWF R_58,f
GOTO Label_001F
Label_0018 MOVF R_40,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
Label_0019 BTFSC R_43,0
GOTO Label_0020
BCF PORTC,2 ;CCP1 out
CLRF CCPR1L
MOVF R_53,W
MOVWF CCPR1L
GOTO Label_0021
Label_0020 BCF PORTC,2
CLRF CCPR1L
MOVF R_53,W
MOVWF CCPR1L
; With TABLE READ and 1XCCP OUT for PWM
CD4081 Gated O/P
; Using PIC16F73 - WITH LCD ONLY
LIST P=16F73,
include "P16F73.inc"
__FUSES _HS_OSC & _PWRTE_ON & _WDT_OFF & _CP_ALL
errorlevel -301,-302,-306
; ***** Variables Definitions *****
selfcheck macro a, bxx
movlw bxx
xorwf a,0
btfsc status,z
endm
selfcheckR macro C,D
movf C,0
xorwf D,0
btfsc status,z
endm
;***** RAM Ddefination ********
RAMbase equ 0x20
cblock RAMbase
PW
CHG_I
r_22
r_23
chg_on
VOLT
COUNT_1
COUNT_2
OL_TRIP
R_29
CHG_DUTY
CHG
r_2C
r_2F
r_30
r_31
S_TEMP
PC_TEMP
TEMP
r_35
r_36
R_37 ;FOR DELAY_1S COUNT
R_38 ;FOR DELAY_1S COUNT
r_39
r_3A
r_3B
r_3C
r_3D
r_3E
r_3F
r_40
r_41
r_42
r_43
r_45
r_46
r_47
r_48
r_49
r_4A
r_4B
r_4C
r_4D
r_4F
r_50
r_51
r_53
r_54
r_56
r_58
r_59
r_70
r_71
r_72
r_73
r_74
r_75
DUTY
BAT_VOLT
OV_LOAD
AC_MAIN
CHG_STAGE
CHG_DELAY
r222
r333
r444
r555
r666
R777
Rxxx
PW_TIMER
PW_BIT
BCDCAL
DUMMY
DUMMY2
TENS
ONES
HUNS
R33
CHAR
R_310
R_560
ENDC
RS EQU 3
EN EQU 2
#DEFINE LCDPORT PORTB
;*******DEFINATION*****************
#DEFINE INV_SW PORTB,1
#DEFINE trickle PORTB,2
#DEFINE MAIN_LED PORTB,3
#DEFINE INV_LED PORTB,4
#DEFINE LB_LED PORTB,5
#DEFINE OL_LED PORTB,6
#DEFINE CHG_LED PORTB,7
#DEFINE UPS PORTC,4
#DEFINE BUZZER PORTC,5
#DEFINE FAN PORTC,6
#DEFINE RELAY PORTC,7
;********************************
; 0.0196V=1 byte *
;********************************
ORG 0x0000
GOTO MAIN_START
ORG 0x0004
;BTFSC CHG,1
;GOTO LED_IND
MOVWF R_72
MOVF STATUS,W
MOVWF R_70 ;satus_temp
MOVF PCLATH,W ;pc_temp
MOVWF R_71
CLRF PCLATH
BTFSC STATUS,RP0
GOTO Label_0002
GOTO Label_0004
Label_0002 MOVF R_72,W
BCF STATUS,RP0
MOVWF R_72
BSF STATUS,RP0
MOVF R_70,W
BCF STATUS,RP0
MOVWF R_70
BSF STATUS,RP0
MOVF R_71,W
BCF STATUS,RP0
MOVWF R_71
Label_0004 BTFSC R_22,5
GOTO Label_000B
MOVLW 0x81
BSF STATUS,RP0
MOVWF T2CON
BCF STATUS,RP0
BCF R_22,6
CLRF R_48
GOTO Label_000C
Label_000B BCF STATUS,Z
movlw 0X0B ;added for table read
subwf duty,w
BTFSS STATUS,Z
GOTO Label_000C
BCF STATUS,Z
MOVF 0x48,W
BTFSC STATUS,Z
BCF R_22,6
BTFSC STATUS,Z
GOTO Label_000C
MOVWF R_41
BSF R_22,6
BSF STATUS,RP0
INCF T2CON,f
BCF STATUS,RP0
Label_000C BCF STATUS,Z
movlw 0X01
subwf duty,w ;added for table read
BTFSS STATUS,Z
GOTO Label_000D
BTFSS R_43,0
GOTO Label_000E
BCF PORTC,2 ;CCP1 out
CLRF CCP1CON
CLRF CCPR1L
CLRF CCPR1H
MOVLW 0x0C
MOVWF CCP1CON
BCF R_43,0
BCF PORTC,1
BSF PORTC,3
MOVF R_45,W
MOVWF R_46
BTFSC R_43,1
BSF R_43,2
BTFSS R_43,1
BCF R_43,2
BTFSC R_22,1
GOTO Label_000F
DECFSZ R_4A,f
BTFSS R_43,2
BSF R_22,1
BTFSS R_43,2
GOTO Label_000F
DECF R_51,f
;MOVLW 0x79
MOVLW 0x40 ;64.8% DUTY
SUBWF R_51,W
;MOVLW 0x79
MOVLW 0x40 ;64.8% DUTY
BTFSS STATUS,C
MOVWF R_51
GOTO Label_000D
Label_000E BCF PORTC,2
CLRF CCP1CON
CLRF CCPR1L
CLRF CCPR1H
MOVLW 0x0C
MOVWF CCP1CON
BSF PORTC,1
BCF PORTC,3
BSF R_43,0
MOVF 0x45,W
MOVWF R_46
BTFSC R_43,1
BSF R_43,2
BTFSS R_43,1
BCF R_43,2
BTFSS R_22,1
GOTO Label_000D
Label_000F BCF STATUS,C
RRF R_46,f
BCF STATUS,C
RRF R_46,f
BTFSS R_43,2
GOTO Label_0010
MOVF R_46,W
SUBWF R_51,f
;MOVLW 0x79
MOVLW 0x40 ;64.8% DUTY
BTFSS STATUS,C
MOVWF R_51
MOVF R_51,W
SUBLW 0x3F
;SUBLW 0x78
;MOVLW 0x79
MOVLW 0x40 ;64.8% DUTY ??????????
BTFSC STATUS,C
MOVWF 0x51
GOTO Label_000D
Label_0010 MOVF R_46,W
ADDWF R_51,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0xFF
SUBWF R_51,W
BTFSS STATUS , C
GOTO Label_000D
MOVLW 0xFE
MOVWF R_51
Label_000D CLRF R_53
movlw 0X07
movwf pclath
call table1
MOVWF R_3A
BCF STATUS,C
RRF R_3A,f
BCF STATUS,C
RRF R_3A,W
MOVWF R_3B
BCF STATUS,C
RRF R_3B,W
MOVWF R_3C
BCF STATUS,C
RRF R_3C,W
MOVWF R_3D
BCF STATUS,C
RRF R_3D,W
MOVWF R_3E
BCF STATUS,C
RRF R_3E,W
MOVWF R_3F
BCF STATUS,C
RRF R_3F,W
MOVWF R_40
COMF R_51,W
MOVWF R_58
DECF R_58,f
;movlw 0X60 ;?????????????????
MOVLW 0x80
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0012
Label_001A MOVLW 0x40
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0013
Label_001B MOVLW 0x20
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0014
Label_001C MOVLW 0x10
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0015
Label_001D MOVLW 0x08
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0016
Label_001E MOVLW 0x04
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0017
Label_001F MOVLW 0x02
SUBWF R_58,W
BTFSC STATUS,C
GOTO Label_0018
GOTO Label_0019
Label_0012 MOVF R_3A,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x80
SUBWF R_58 , f
GOTO Label_001A
Label_0013 MOVF R_3B,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x40
SUBWF R_58,f
GOTO Label_001B
Label_0014 MOVF R_3C,W
ADDWF R_53,f
BTFSC STATUS , C
GOTO Label_0011
MOVLW 0x20
SUBWF R_58,f
GOTO Label_001C
Label_0015 MOVF R_3D,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x10
SUBWF R_58,f
GOTO Label_001D
Label_0016 MOVF R_3E,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x08
SUBWF R_58,f
GOTO Label_001E
Label_0017 MOVF R_3F,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
MOVLW 0x04
SUBWF R_58,f
GOTO Label_001F
Label_0018 MOVF R_40,W
ADDWF R_53,f
BTFSC STATUS,C
GOTO Label_0011
Label_0019 BTFSC R_43,0
GOTO Label_0020
BCF PORTC,2 ;CCP1 out
CLRF CCPR1L
MOVF R_53,W
MOVWF CCPR1L
GOTO Label_0021
Label_0020 BCF PORTC,2
CLRF CCPR1L
MOVF R_53,W
MOVWF CCPR1L