; Ford Fiesta MK6 üzemanyag fogyasztás minimalizálás
				
; PIC12F675 Configuration Bit Settings
; Assembly source line config statements
#include "p12f675.inc"
;__CONFIG _FOSC_INTRCIO & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _BOREN_ON & _CP_OFF & _CPD_OFF
__CONFIG 0x1CC

#define input		        GPIO,AN0                   
#define output    		GPIO,GP2
#define button_plus		GPIO,GP3
#define button_minus	        GPIO,GP4
#define led		        GPIO,GP5
					
					;cblock 0x20
					udata
					pwm_counter res	1
					pwm_value   res	1
					status_saved	res 1
					work_saved	res 1
					;endc
					
;--------------------------------------------------------------------
                org     0
				goto    start
				org     4
				goto    interrupt
                org	5
start:				clrwdt
				
				bcf	STATUS,RP0
				movlw	0x7
				movwf	CMCON
				movlw	b'10000001'
				movwf	ADCON0

				bsf	STATUS,RP0
				movlw 	b'00011011'
				movwf 	TRISIO
				movlw	b'01010011'
				movwf	ANSEL
				movlw	b'10000110'
				movwf	OPTION_REG
				bcf	STATUS,RP0
;--------------------------------------------------------------------
				;btfss	button+	;statikus mód
				;call	calibrate1
				
				;btfss	button-	;dinamiks mód
				;call	calibrate2
				
				;btfss	STATUS,4
				;call	selftest
				
				;call	load_data
				
				clrf	pwm_counter
				bcf	INTCON,T0IF
				bsf	INTCON,T0IE
				bsf	INTCON,GIE
;--------------------------------------------------------------------
again:				clrwdt
				
				movf	pwm_counter,F
				btfss	STATUS,Z
				goto	main10
				call	anol
				bcf	STATUS,RP0
				bcf	STATUS,C
				rrf	ADRESH,F
				bsf	STATUS,RP0
				rrf	ADRESL,F
				bcf	STATUS,RP0
				bcf	STATUS,C
				rrf	ADRESH,F
				bsf	STATUS,RP0
				rrf	ADRESL,W
				bcf	STATUS,RP0
				movwf	pwm_value
main10:				goto    again
;--------------------------------------------------------------------
interrupt:			movwf	work_saved
				swapf	STATUS,W
				movwf	status_saved
				bcf	STATUS,RP0
;--------------------------------------------------------------------				
				movfw	pwm_counter
				subwf	pwm_value,W
				btfss	STATUS,C
				goto	inter10
				bsf	output
				goto	inter20
inter10:			bcf	output
inter20:			incf    pwm_counter,F
				btfsc	STATUS,Z
				incf    pwm_counter,F
;--------------------------------------------------------------------
inter_end:			swapf	status_saved,W
				movwf	STATUS
				swapf	work_saved,F
				swapf	work_saved,W
				bcf	INTCON,T0IF
				retfie
;--------------------------------------------------------------------
anol:				bcf	INTCON,GIE
				bcf	STATUS,RP0
				bcf	PIR1,ADIF
				bsf	ADCON0,GO_DONE
anol1:				btfss   PIR1,ADIF
				goto	anol1
				retfie
;--------------------------------------------------------------------
				end