LIST P=PIC12F683 INCLUDE P12F683.INC __CONFIG _HS_OSC & _MCLRE_OFF & _WDT_OFF ;*********************************************************** ; Definition of valuables ;*********************************************************** COUNT EQU 20H COUNT1 EQU 21H COUNT2 EQU 22H COUNT3 EQU 23H COUNT4 EQU 24H ADCRES EQU 25H TEMP EQU 26H W_TEMP EQU 27H S_TEMP EQU 28H PWMVAL EQU 29H INT_DIV EQU 2AH PWM_AIM EQU 2BH AIM_SEL EQU 2CH ORG 0 goto INIT org 4 INTERRUPT movwf W_TEMP movf STATUS,W movwf S_TEMP BSF STATUS,RP0 movlw 0fbh ANDWF INTCON,F bcf STATUS,RP0 CALL ADCONV INCF INT_DIV,F movf INT_DIV,W sublw 01h btfsc STATUS,Z GOTO INT_MAIN movf S_TEMP,W movwf STATUS movf W_TEMP,W retfie INT_MAIN CLRF INT_DIV movf ADCRES,W CALL ADCONV movf ADCRES,W subwf PWM_AIM,W btfsc STATUS,Z GOTO OK_PWM movf ADCRES,W subwf PWM_AIM,W btfsc STATUS,C GOTO DEC_PWM GOTO INC_PWM ;850mA->76, 700mA->61, 500mA->46, 200mA->1C PWM_ADJ_END movf S_TEMP,W movwf STATUS movf W_TEMP,W retfie INC_PWM ;Decrease PWM Duty INCF PWMVAL,F btfsc STATUS,Z DECF PWMVAL,F CALL SETPWM BSF GPIO,0 GOTO PWM_ADJ_END DEC_PWM ;Increase PWM Duty DECF PWMVAL,F BTFSC STATUS,Z INCF PWMVAL,F CALL SETPWM BCF GPIO,0 GOTO PWM_ADJ_END OK_PWM GOTO PWM_ADJ_END BTFSS GPIO,0 GOTO OK_PWM2 BCF GPIO,0 GOTO PWM_ADJ_END OK_PWM2 BSF GPIO,0 GOTO PWM_ADJ_END SHUTDOWN movlw 0ffh movwf PWMVAL movlw 3fh movwf CCPR1L movlw 3fh movwf CCP1CON return SETPWM movf PWMVAL,W movwf TEMP rrf TEMP,F bcf STATUS,C rrf TEMP,W andlw 3fh movwf CCPR1L movf PWMVAL,W movwf TEMP SWAPF TEMP,W andlw 30h iorlw 0fh movwf CCP1CON return ADCONV movlw 85h movwf ADCON0 CALL TIME100 BSF ADCON0,GO ADC_LOOP btfsc ADCON0,GO goto ADC_LOOP BSF STATUS,RP0 movf ADRESL,W BCF STATUS,RP0 movwf ADCRES movf ADCRES,W sublw 07dh btfss STATUS,C CALL SHUTDOWN movf ADRESH,W addlw 0 btfss STATUS,Z CALL SHUTDOWN return ;*********************************************************** ; I/O pins Initialize ;*********************************************************** INIT movlw 04h movwf T2CON movlw 3fh ;PWM mode movwf CCP1CON movlw 0ffh movwf CCPR1L CLRF PWMVAL movlw 04h movwf ADCON0 clrf CMCON0 BSF STATUS,RP0 movlw b'11111010' movwf TRISIO movlw 03fh movwf PR2 movlw 043h movwf OPTION_REG movlw 0a0h movwf INTCON movlw 62h movwf ANSEL bcf STATUS,RP0 ;*********************************************************** ; MAIN program ;*********************************************************** ;900mA->7D, 850mA->76, 700mA->61, 500mA->46, 200mA->1C, 150mA->11 movlw 11h movwf PWM_AIM MAIN BTFSS GPIO,3 GOTO HI_MODE GOTO LO_MODE goto MAIN goto MAIN goto MAIN HI_MODE movlw 61h movwf PWM_AIM goto MAIN LO_MODE movlw 11h movwf PWM_AIM goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN goto MAIN ;*********************************************************** ; Timer Sub routines ;*********************************************************** TIME100 MOVLW 0AH MOVWF COUNT NOP NOP LOOP DECFSZ COUNT,F GOTO LOOP RETURN TIME10M MOVLW 0F4H MOVWF COUNT1 NOP NOP LOOP1 CALL TIME100 DECFSZ COUNT1,F GOTO LOOP1 RETURN TIME1S MOVLW 0FFH MOVWF COUNT2 MOVLW 24H MOVWF COUNT3 MOVLW 03H MOVWF COUNT4 NOP LOOP2 CALL TIME10M DECFSZ COUNT2,F GOTO LOOP2 LOOP3 CALL TIME100 DECFSZ COUNT3,F GOTO LOOP3 LOOP4 DECFSZ COUNT4,F GOTO LOOP4 RETURN end