Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list p=16f1827
- include p16f1827.inc
- cblock 0x20
- aargh, aargl, bargh, bargl
- dargh, dargl, gargh, gargl
- count1, count2, count3, count4
- dg, lgh, lgl
- prot2, count0,ibuf,cousleep
- ndiv, basl, bash, n, flb
- dbuf, dbuf1,buf,nm
- d1,d2,d3,d4,d5
- dc1,tf1,dc2,tf2,dc3,tf3,dc4,tf4
- dg1,fl1,acorh,acorl,inn,count2a
- inn1,count5,fl2,pb
- endc
- cblock 0x70
- fadr,fdata,flag,prot1,flwr,nf
- ;
- endc
- ;portb bit
- #define date portb,1
- #define clock portb,2
- #define s2 portb,4
- #define s1 portb,5
- #define s3 portb,6
- ;porta bit
- ;#define s1 porta,5
- ;#define relay porta,2
- #define led porta,3;2
- ;flag bits
- #define cc flag,0
- #define over flag,2
- #define lobatt flag,3
- #define flz flag,4
- #define flc flag,5
- #define fldg flag,6
- #define mes flag,7
- ;flb bits
- #define en1 flb,0
- #define en2 flb,1
- #define gen flb,2
- #define entr flb,3
- #define entrans flb,4
- #define first flb,5
- #define freq flb,7
- ;fl1
- #define light fl1,0
- #define lightc fl1,1
- #define dark fl1,2
- #define cc1 fl1,3
- #define cc2 fl1,4
- #define cc3 fl1,5
- #define enind1 fl1,6
- #define enind2 fl1,7
- ;flb fl2
- #define enind fl2,0
- ; org 0x2102
- ; data 0
- ; data 0
- ; __config 0x0005;01;1;
- org 0xF002;2100;
- de 0,0
- org 0xF042
- de 0,0
- __config _config1, 0x0C12;4;0E1C
- __config _config2, 0x18FC;1AFC
- org 0
- begin movlw 10
- movwf prot1
- movwf prot2
- goto init
- ;
- org 4
- goto intt;
- ;
- indi2 btfsc cc2
- goto num13
- btfsc cc3
- goto num10
- andlw 15 ;1
- ; addwf pcl
- brw ;b a f g e d c p
- num0 retlw 0xEE ;1 1 1 0 1 1 1 0
- num1 retlw 0x82 ;1 0 0 0 0 0 1 0
- num2 retlw 0xDC ;1 1 0 1 1 1 0 0
- num3 retlw 0xD6 ;1 1 0 1 0 1 1 0
- num4 retlw 0xB2 ;1 0 1 1 0 0 1 0
- num5 retlw 0x76 ;0 1 1 1 0 1 1 0
- num6 retlw 0x7E ;0 1 1 1 1 1 1 0
- num7 retlw 0xC2 ;1 1 0 0 0 0 1 0
- num8 retlw 0xFE ;1 1 1 1 1 1 1 0
- num9 retlw 0xF6 ;1 1 1 1 0 1 1 0
- num10 retlw 0x0 ;0 0 0 0 0 0 0 0 over
- num11 retlw 0x6C ;0 1 1 0 1 1 0 0 CC
- num12 retlw 0x10 ;0 0 0 1 0 0 0 0 --
- num13 retlw 0x04 ;0 0 0 0 0 1 0 0 ___
- num14 retlw 0x84 ;1 0 0 0 0 1 0 0
- ;
- ;;;;;;;;;;;;;;;;;
- intt movlb 0
- ; clrf status
- bcf pir1,tmr2if
- bsf en2
- ;
- bsf porta,0
- decfsz count1 ;/250=2hz;/50=10hz
- goto pop
- movlw 250;50;
- movwf count1
- ;
- btfss cc
- btfsc freq
- goto intt2
- ;
- movf portb,w
- movwf pb
- btfsc pb,0
- goto intt1
- ;
- bsf enind1
- btfss enind2
- goto intt2
- bcf enind2
- ;
- bsf enind
- bsf enind1
- bsf mes
- goto intt2
- intt1 bsf enind2
- btfss enind1
- goto intt2
- bsf enind
- bcf enind1
- movlw 2
- movwf count2
- ;
- intt2;; bcf porta,0
- ; decfsz count1 ;/250=2hz;/50=10hz
- ; goto pop
- ; movlw 250;50;
- ; movwf count1
- ;
- bsf portb,7
- decfsz count2 ;/1hz
- goto blink0
- movlw 2
- movwf count2
- ; bsf portb,7
- bsf flwr,7
- btfsc cc
- goto blink0
- bsf mes
- btfss pb,0
- bsf enind
- ; bsf porta,0
- ; goto pop
- ;
- blink0 btfsc freq
- btfss dark
- goto blink
- btfss count2,0
- goto blink2
- clrf tf1
- clrf tf2
- clrf tf3
- call trans
- goto pop
- blink; btfsc portb,7
- btfss cc
- goto pop;indi
- btfss count2,0
- goto blink1
- movlw 0x0A
- movwf dc1
- movwf dc2
- movwf dc3
- goto blink2
- blink1 call indic
- blink2 call indi
- pop movf portb,w
- xorlw 0x04
- btfss entr
- movwf portb
- pop1 bcf pir1,tmr2if
- ; swapf temp1,w
- ; movwf status
- ; swapf temp0,w
- retfie
- ;
- indi
- btfss freq
- btfsc cc
- goto indi1
- btfss cc2
- btfsc cc3
- goto indi1
- btfss enind
- return
- ; btfsc pb,0
- bcf enind
- indi1
- movlb 2
- bsf cm1con0,c1on
- movlw 0xe0
- movwf daccon0
- movlb 0
- ;
- clrf tf1
- clrf tf2
- clrf tf3
- movf dc3,w
- call indi2
- movwf buf
- andlw 0xF0
- movwf tf1
- movf buf,w
- andlw 0x0E
- movwf tf3
- ; btfsc cmcon,c2out
- movlb 2
- btfsc cm1con0,c1out
- bsf lobatt
- bcf cm1con0,c1on
- clrf daccon0
- movlb 0
- ; movlw 0x07
- ; movwf cmcon
- ;;;;;;;;;;
- movf dc2,w
- call indi2
- movwf buf
- swapf buf,w
- andlw 0x0F
- iorwf tf1
- swapf buf,w
- andlw 0xF0
- btfsc dc2,4
- iorlw 0x10
- iorwf tf3
- ;;;;;;;;;;
- ;
- ; bcf portb,3
- ;
- movf dc1,w
- call indi2
- btfsc dc1,4
- iorlw 1
- movwf tf2
- ;;;;;;;;;
- ;;;;;;;;;;;
- trans bsf entr
- bcf date ;start bit
- nop
- nop
- bsf clock
- nop
- nop
- bcf clock
- nop
- nop
- ;;;;;;;;;;;;;;
- bsf date
- nop
- nop
- bsf clock ;1
- nop
- nop
- bcf clock
- nop
- nop
- ;;;;;;;;;;;;;;
- bcf date
- nop
- nop
- bsf clock ;2
- nop
- nop
- bcf clock
- nop
- nop
- ;;;;;;;;;;;;;
- btfsc lobatt ;lo batt
- bsf date
- movlw 24
- bsf clock ;3
- movwf inn1
- ; bcf date
- trans1 bcf status,c
- bcf clock
- rlf tf3
- rlf tf2
- rlf tf1
- ; bcf date
- btfss status,c
- goto tran1a
- bsf date
- nop
- nop
- tran2a bsf clock ;+24=27
- nop
- ; bcf date
- decfsz inn1
- goto trans1
- ;;;;;;;;;;;;;;;;;;;
- movlw 15;8;9;10
- bcf clock
- movwf inn1
- bcf date
- nop
- nop
- trans2 bsf clock ;+8=35
- nop
- nop
- bcf clock
- decfsz inn1
- goto trans2
- ;
- ; bsf date
- nop
- nop
- bsf clock ;36
- nop
- nop
- nop
- bcf clock
- nop
- nop
- nop
- bcf date
- nop
- nop
- ;
- bsf clock
- nop
- nop
- bcf clock
- ; bsf portb,3
- ; bsf intcon,gie
- ; bcf pir1,tmr2if
- bcf entr
- return
- ;
- tran1a bcf date
- nop
- goto tran2a
- ; MAIN LOOP - butt
- butt clrwdt ; Clear watchdog
- butt1 movlw 10 ;
- subwf prot1,w ; w = prot1 - 10 (prot1 is init 10)
- btfss status,z ; prot1 - 10 != 0 then
- reset ; reset PIC
- butt1_
- btfsc mes ; if mes==1 then
- goto messur ; goto measur
- btfss en2 ; if en2==0 then
- goto butt1 ; goto butt1
- btfss s1 ; if s1==0 then if pushbutton SB1 (setup) is pressed
- goto choce ; goto choce
- btfss s2 ; if s2==0 then if pushbutton SB2 (install) is pressed
- goto b1 ; goto b1
- goto b2 ; goto b2
- ; MAIN LOOP END
- ;
- ;
- ;
- ;Happens after pressed setup button
- ;
- choce btfss en1 ; if( en1 ==0) then
- goto b3 ; goto b3
- btfss freq ; if(freq == 0) then
- bsf cc ; cc = 1
- bcf freq ; freq = 0
- bcf en1 ; en1 = 0
- btfss cc ; if(cc == 1) then
- goto exb ; goto exb
- clrf count4 ; count4 = 0
- decf n,w ; w = n - 1
- btfss status,z ; if((n - 1) != 0) then)
- goto nn; ; goto nn
- btfss lightc ; if( lightc == 0)
- goto b4 ; goto b4
- goto exb; ; goto exb
- ;
- ;
- ;Routine nn
- nn incf n ; ++n
- movf n,w ; w = n
- sublw 9 ; w = n - 9
- btfsc status,z ; if(n = 9) then
- goto nn1 ; goto nn1
- call indic ;
- goto exb ; goto exb
- nn1 bcf cc ;
- bcf flwr,0
- clrf n
- clrf fadr
- bcf lightc
- goto exb
- b1 btfss cc
- goto b3a;b1a
- btfss en1
- goto b1a
- bcf en1
- ;
- ; btfsc lightc
- ; goto b11
- ; bsf lightc
- ; goto b12
- ;
- b11 movf n,w
- btfsc status,z
- goto nn1
- b12 bsf mes
- bsf porta,0
- bsf flwr,0
- goto exb
- b1a movlw 80
- movwf count3
- bcf cc2
- bcf cc3
- goto exb
- b2 btfsc en1
- goto b2a
- decfsz count3
- goto exb
- b2a bsf en1
- movlw 80
- movwf count3
- clrf count4
- clrf count5
- goto exb
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- b3a btfsc freq
- ;
- ; btfss freq
- ; btfss cc1
- goto b1a
- btfss en1
- goto b1a
- movlw 80
- movwf count3
- btfss flwr,7
- goto exb
- bcf flwr,7
- ;
- btfsc cc1
- ;
- bsf cc2
- ;
- btfss cc1
- bsf cc3
- ;
- btfsc count5,2
- goto exb
- incf count5
- btfss count5,2
- goto exb
- ;;;;;;;;;;;;;;
- BCF en1
- ;;;;;;;;;;;;;;
- btfss cc1
- goto B3B
- call _copy1
- goto b4
- ;;;;;;;;;;;;;;;;;;;;;;
- b3b call _copy0r
- goto b4
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Routine b3
- b3 movlw 80 ;
- movwf count3 ; count3 = 80
- btfss flwr,7 ; if( flwr,7 == 0) then
- goto exb ; goto exb
- bcf flwr,7 ; clear flwr,7
- movf n,w ;
- sublw 1 ; w = n - 1
- btfsc status,c ; if(n - 1 < 0) then
- btfsc count4,2 ; if(count4 == 4) then
- goto exb ; goto exb
- incf count4 ; ++count4
- btfss count4,2 ; if(count4 == 4) then
- goto exb ; goto exb
- bsf freq ; freq = 1
- b4 bcf cc ; cc = 0
- bcf flwr,0 ; flwr, 0 = 0
- clrf n ; n = 0
- clrf fadr ; fadr = 0
- exb bcf en2 ; clear en2
- goto butt ; goto butt(main loop)
- ; b3 END
- ;
- ; routine indic
- indic movf n,w
- btfss status,z ; if(n
- goto indic1
- indicin movlw 11
- movwf dc1
- movwf dc2
- movlw 10
- movwf dc3
- return
- indic1 movwf dbuf
- ;
- btfsc lightc
- goto indic1a
- movlw 12
- movwf dc1
- movwf dc2
- movwf dc3
- return
- ;
- indic1a decf dbuf
- ;
- sublw 2
- btfss status,z
- goto indic2
- ;
- ; movf dbuf,w
- ; btfss status,z
- ; goto indic2
- movlw 5
- movwf dc2
- clrf dc1
- goto indic3
- indic2 movf dbuf,w
- ;
- btfss status,z
- decf dbuf,w
- ;
- movwf dc1
- clrf dc2
- indic3 bsf dc1,4
- clrf dc3
- return
- ;Measure routine
- messur
- bcf intcon,gie
- bsf flwr,5
- bsf led ; Turn on LED
- bsf light ; Set light bit
- bcf t2con,tmr2on ; Stop timer 2
- movlb 2
- bsf cm1con0,c1on ; Enable Comparator
- movlw 0xe0 ;
- movwf daccon0 ; DAC output enable
- movlb 0
- bcf lobatt ;
- clrf dargh ; bargh overflow counter
- clrf bargh ; timer 0 overflow counter
- call delay ; Delay and measure frequency and check TUBS status
- movlb 2
- btfsc cm1con0,c1out ; if c1out == 1 then
- bsf lobatt ; set lobatt
- movlb 0
- meas1 bcf led ; Turn off LED
- movf bargh,w ;
- movwf aargh ; aargh = bargh (timer 0 overflow counter)
- movf bargl,w ;
- movwf aargl ; aargl = bargl (timer 0 counter register)
- btfsc portb,0 ; if( TUBS == 1) then
- bcf light ; clear light
- movf bargh,w ;
- subwf dargh,w ; w = dargh - bargh (bargh overflow - tm0 overflow counter)
- bcf over ; over = 0
- btfss status,z ; if(w != 0)
- bsf over ; over = 1
- ; clrf dargh
- clrf bargh ; tm0 overflow counter clear
- call delay ;
- btfsc portb,0;2 ;
- bcf light ;
- ;; movf tmr1h,w
- ;; movwf burgh
- call test ;
- btfsc status,c ;
- goto mes1 ;
- clrf aargh ;
- clrf aargl ;
- bsf over ;
- goto mes2 ;
- ;
- mes1 call dtoa
- mes2
- ; bsf dark
- ;;;; btfss freq
- btfss light
- goto mes3
- bsf dark
- goto mes4
- mes3 bcf dark
- mes4; bcf porta,0
- bcf mes
- bsf t2con,tmr2on
- clrf tmr2
- bcf pir1,tmr2if
- movlw 250
- movwf count1
- bsf intcon,gie
- ;
- ; call indi
- ;
- bcf flwr,5
- btfsc freq;
- goto dcorr;
- ;
- btfsc lightc
- goto acorr;lgment
- btfss cc
- goto acorr;lgment
- movlw 50
- movwf fadr
- movf aargh,w
- movwf acorh
- movwf fdata
- call write
- incf fadr
- movf aargl,w
- movwf acorl
- movwf fdata
- call write
- ;
- movlw 2
- movwf fadr
- clrf fdata
- call write
- incf fadr
- clrf fdata
- call write
- ;
- clrf fadr
- bsf lightc
- goto butt
- ;
- acorr btfss light
- goto acor00
- movf aargh,w
- movwf acorh
- movf aargl,w
- movwf acorl
- goto outdc;lgment
- acor00 movlw 15
- movwf dg
- movwf dg1
- bcf fldg
- acorr0 btfsc aargh,7
- goto acorr1
- call rla
- decfsz dg
- goto acorr0
- goto lgment
- acorr1 movf acorh,w
- movwf bargh
- movf acorl,w
- movwf bargl
- acorr2 btfsc bargh,7
- goto acorr3
- bcf status,c
- rlf bargl
- rlf bargh
- decfsz dg1
- goto acorr2
- goto lgment
- acorr3 call div
- movf dg1,w
- subwf dg
- bcf flc
- btfsc status,c
- bsf flc
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- movlw 16 ;add1,rrgd
- movwf ndiv
- bcorr1 movlw 50
- call read1
- movwf gargh
- movlw 51
- call read1
- movwf gargl
- ; movlw 16 ;add1,rrgd
- ; movwf ndiv
- ; addwf dg,w
- ; movwf ndiv
- clrf dargh
- clrf dargl
- multi bcf status,c
- btfsc gargl,0
- call add1
- decfsz ndiv
- goto multi1
- ;
- ; btfss status,c
- ; goto multi3
- ; call rrgd1
- ; incf dg
- ;
- multi3 call dtoa
- movf dg,w
- btfsc status,z
- goto lgment
- btfsc flc;dg,7;s
- goto multi2
- multi0 call rrgd
- incfsz dg;decfsz dg;
- goto multi0
- call dtoa
- goto lgment
- multi2 call rla
- decfsz dg;
- goto multi2
- goto lgment
- multi1 call rrgd1
- goto multi
- ;
- ; call lg_arg
- lgment clrf lgh
- clrf lgl
- movlw 15
- movwf dg
- movlw 160
- movwf bargh
- clrf bargl
- bcf fldg
- lg10 movlw 3
- subwf dg,w
- btfss status,c
- goto lg20
- btfsc status,z
- goto lg12
- btfsc aargh,7
- goto lg11
- call rla
- decf dg
- goto lg10
- lg12 bsf fldg
- lg11 call div
- btfsc flz
- goto lg20
- ;
- movlw 0xE8;100
- addwf lgl
- movlw 3
- btfsc status,c
- addlw 1
- addwf lgh
- ;
- ; incf lgh
- movlw 3
- subwf dg
- goto lg10
- lg20 movlw 0xA1 ;1.0010.0111.1001.1111
- movwf bargh ;1001.0011.1100.1111
- movlw 0x24 ;147 .207
- movwf bargl ;a1 24
- bcf fldg
- lg20a movf dg,w
- btfsc status,z
- goto lg22
- btfsc aargh,7
- goto lg21
- call rla
- decfsz dg
- goto lg20a
- lg22 bsf fldg
- lg21 call div
- btfsc flz
- goto lg30
- ;
- movlw 100
- addwf lgl
- btfsc status,c
- ;
- incf lgh ;lgl
- goto lg20a
- ;592d,250h
- lg30 movlw 0x82 ;1.0000.0010.0101.0000
- movwf bargh ;1000.0001.0010.1000
- movlw 0xFB ;129 .40
- movwf bargl ;82 fb
- lg30a call div
- btfsc flz
- goto lg40;lgout
- ;
- movlw 10
- addwf lgl
- btfsc status,c
- incf lgh
- ;
- goto lg30a
- ;
- lg40 movlw 0x80 ;1.0000.0000.1001.0110
- movwf bargh ;1000.0000.0100.1011
- movlw 0x4B ;80 .4B
- movwf bargl ;82 fb
- lg40a call div
- btfsc flz
- goto lgout
- ;
- incfsz lgl
- goto lg40a
- incf lgh
- ;
- goto lg40a
- ;
- rla bcf status,c
- rlf aargl
- rlf aargh
- return
- ;
- test movf bargl,w
- subwf aargl,w
- btfss status,c
- goto test1
- movwf dargl
- movf bargh,w
- test2 subwf aargh,w
- movwf dargh
- return
- test1 movwf dargl
- incf bargh,w
- goto test2
- ;
- dtoa movf dargl,w
- movwf aargl
- movf dargh,w
- movwf aargh
- return
- ;
- div movlw 16
- movwf ndiv
- clrf gargh
- clrf gargl
- bcf flc
- bcf flz
- btfsc aargh,7
- goto div0
- goto div2
- div0 call test
- btfss status,c
- goto div2
- div1 call dtoa
- incf gargl
- div4 decfsz ndiv
- goto div5
- movf gargl,w
- movwf aargl
- movf gargh,w
- movwf aargh
- return
- div5 bcf status,c
- rlf gargl
- rlf gargh
- call rla
- btfsc status,c
- bsf flc
- goto div0
- div2 btfss ndiv,4
- goto div3
- btfss fldg
- goto div3
- bsf flz
- return
- div3 btfss flc
- goto div4
- bcf flc
- goto div1
- ;
- read movf fadr,w
- read1
- banksel eeadrl
- movwf eeadrl
- bcf eecon1,cfgs
- bcf eecon1,eepgd
- bsf eecon1,rd
- movf eedatl,w
- movlb 0
- return
- ;
- lgout btfsc flwr,0
- goto calibr ;calibr,select,
- goto select ;mul,add.
- ;
- dcora call dtoa
- clrf fadr
- dcorr clrf dbuf
- movlw 0x10 ;
- movwf bargl ;10000
- movlw 0x27
- movwf bargh
- call dcorr0
- movf dbuf,w
- movwf d1
- ;
- dcorr2 clrf dbuf
- movlw 0xE8 ;11 11101000
- movwf bargl ;3 e8
- movlw 3
- movwf bargh
- call dcorr0
- movf dbuf,w
- movwf d2
- clrf dbuf
- movlw 100
- movwf bargl
- clrf bargh
- call dcorr0
- movf dbuf,w
- movwf d3
- ;
- clrf dbuf
- movlw 10
- movwf bargl
- clrf bargh
- call dcorr0
- movf dbuf,w
- movwf d4
- movf aargl,w
- movwf d5
- ;
- ;
- outdc; bsf enld
- ; goto butt
- ;
- load; movlw 0;255
- ; movwf tf4
- ; btfsc enld
- ;
- btfsc cc
- goto blinki;indi
- ;
- ; movlw 0x05
- ; movwf cmcon
- ;
- btfsc dark
- goto load5
- ;
- load0 btfsc over
- goto load3
- movf d1,w
- btfsc status,z
- goto load1
- loadn movwf dc1
- movf d2,w
- movwf dc2
- movf d3,w
- movwf dc3
- goto load4
- load1 bsf d3,4
- movf d2,w
- btfsc status,z
- goto load2
- movwf dc1
- movf d3,w
- movwf dc2
- movf d4,w
- movwf dc3
- goto load4
- load2 movf d3,w
- movwf dc1
- movf d4,w
- movwf dc2
- movf d5,w
- movwf dc3
- goto load4
- ;
- load5; movlw 13
- ; movwf dc1
- ; movwf dc2
- ; movwf dc3
- btfsc freq
- goto load0
- ;
- clrf dc2
- clrf dc3
- movlw 0x10
- movwf dc1
- incf cousleep
- btfss cousleep,6
- goto load4a
- clrf cousleep
- bcf portb,7
- clrf porta;;;
- clrf t2con
- movlw 0x08
- movwf intcon
- ;
- ; movlb 1
- ; movlw 0x02
- ; movwf osccon
- movlb 2
- clrf cm1con0
- clrf fvrcon
- clrf daccon0
- movlb 0
- ;
- _sleep sleep
- nop
- btfsc intcon,IOCIF;rbif
- btfsc portb,6
- goto _sleep
- ;
- movlb 7
- bcf iocbf,6
- movlb 0
- ;
- clrwdt
- clrf status
- movlw 2
- movwf count2
- goto 0;initsl
- ;
- load3 movlw 0x1A
- movwf dc1
- movlw 10
- movwf dc2
- movwf dc3
- ; bcf enld
- load4
- clrf cousleep
- btfss dark
- ; movlw 250
- ; movwf count1
- ; bcf lobatt
- ; bsf t2con,tmr2on
- ; clrf tmr2
- ; bcf pir1,tmr2if
- ; btfsc cmcon,c2out
- ; bsf lobatt
- ;
- ; movlw 0x07
- ; movwf cmcon
- load4a; bcf intcon,gie
- call indi;pop
- ;
- ; bsf intcon,gie
- ;
- goto butt
- ;
- blinki btfss count2,0
- goto blinki1
- movlw 0x0A
- movwf dc1
- movwf dc2
- movwf dc3
- goto blink2
- blinki1; bcf intcon,gie
- call indic
- blinki2 call indi
- ; bsf intcon,gie
- goto butt
- ;
- dcorr0 call test
- btfss status,c
- return
- incf dbuf
- call dtoa
- goto dcorr0
- ;
- select movlw 2
- call read1
- btfss status,z
- goto sel0a
- clrf fadr
- goto init1
- sel0a clrf fadr
- sel0 movlw 6
- addwf fadr
- sel2 call sela
- btfsc status,c
- goto sel1
- movlw 7
- subwf fadr
- call sela
- ;
- bcf flc
- ;
- btfss status,c
- bsf flc
- goto mull
- sel1 movlw 5
- addwf fadr
- goto sel2
- ;
- sela call read
- movwf bash
- incf fadr
- call read
- movwf basl
- iorwf bash,w
- btfss status,z
- goto sela0
- bcf status,c
- return
- sela0 movf lgl,w
- subwf basl,w
- movwf aargl
- btfss status,c
- goto sela1
- movf lgh,w
- sela2 subwf bash,w
- movwf aargh
- return
- sela1 incf lgh,w
- goto sela2
- ;
- mull
- ;
- btfsc flc
- call neg
- ;
- call rla
- call rla
- call rla
- ;
- clrf dargh
- clrf dargl
- movf aargl,w
- iorwf aargh,w
- btfsc status,z
- goto dcam12
- dcam10 movlw 10
- subwf aargl
- incfsz dargl
- goto dcam11
- incf dargh
- dcam11 btfsc status,c
- goto dcam10
- decf aargh
- btfss aargh,7
- goto dcam10
- movlw 1
- subwf dargl
- btfss status,c
- decf dargh
- call dtoa
- ;
- dcam12
- movlw 16 ;add1,rrgd
- movwf ndiv
- clrf dargh
- clrf dargl
- incf fadr
- call read
- movwf gargh
- incf fadr
- call read
- movwf gargl
- ; btfsc flc
- ; call neg
- ;
- mull0a; call rla
- ; call rla
- ; call rla
- mull0 bcf status,c
- btfsc gargl,0
- call add1
- decfsz ndiv
- goto mull1
- call dtoa
- btfsc flc
- call neg
- goto add
- ;
- neg comf aargh
- comf aargl
- incfsz aargl
- return
- incf aargh
- return
- ;
- mull1 call rrgd1
- goto mull0
- ;
- add1 movf aargl,w
- addwf dargl
- btfsc status,c
- incf dargh
- movf aargh,w
- addwf dargh
- return
- ;
- rrgd bcf status,c
- rrgd1 rrf dargh
- rrf dargl
- bcf status,c
- rrf gargh
- rrf gargl
- return
- ;
- add incf fadr
- call read
- movwf gargh
- incf fadr
- call read
- movwf gargl
- ;
- clrf dargh
- clrf dargl
- movf gargl,w
- iorwf gargh,w
- btfsc status,z
- goto dkam12
- dkam10 movlw 10
- subwf gargl
- incfsz dargl
- goto dkam11
- incf dargh
- dkam11 btfsc status,c
- goto dkam10
- movlw 1
- subwf gargh
- btfsc status,c
- goto dkam10
- movlw 1
- subwf dargl
- btfss status,c
- decf dargh
- ;
- dkam12 call add1
- ;
- btfss flc
- goto dcora
- btfsc status,c
- goto dcora
- ; bcf porta,dout
- ; clrf dbuf1
- clrf dc1
- bsf dc1,4;;;;;;;;;;;;;;
- clrf dc2
- clrf dc3
- clrf fadr
- ; bcf intcon,gie
- call indi
- ; bsf intcon,gie
- goto butt
- ;
- calibr movf lgh,w ;lg
- movwf fdata
- call write
- incf fadr
- movf lgl,w
- movwf fdata
- call write
- ;
- ; swapf dbuf ;A
- movf dbuf,w
- ; btfsc status,z
- ;
- btfss status,z
- goto calib2a
- clrf dargh
- clrf dargl
- goto calib3
- calib2a decf dbuf;,w
- btfsc status,z
- ;
- goto calib1
- clrf dargh
- clrf dargl
- calib2 movlw 0xE8;100
- addwf dargl
- movlw 3
- btfsc status,c
- addlw 1
- addwf dargh
- decfsz dbuf
- goto calib2
- calib3 movlw 3
- addwf fadr ;aa
- movf dargh,w
- movwf fdata
- call write
- incf fadr
- movf dargl,w
- movwf fdata
- call write
- goto calik
- calib1 movlw 1
- movwf dargh
- movlw 0XF4;50
- movwf dargl
- goto calib3
- ;
- calik movlw 11 ;lg-
- subwf fadr
- btfsc status,c
- goto calik1
- movlw 8 ;k1
- addwf fadr
- clrf fdata
- call write
- incf fadr ;k2
- clrf fdata
- call write
- goto outca
- calik1 call sela
- btfss status,c
- goto outcb
- clrf dg
- calik2 btfsc aargh,7
- goto calik3
- call rla
- incf dg
- btfss dg,4
- goto calik2
- goto outcb
- calik3 movf aargh,w
- movwf bargh
- movf aargl,w
- movwf bargl
- call dtoa
- movlw 4
- addwf fadr ;a2-
- call read
- subwf aargl
- btfss status,c
- decf aargh
- decf fadr ;a1-
- call read
- subwf aargh
- bcf fldg
- calik4 btfsc aargh,7
- goto calik5
- call rla
- decfsz dg
- goto calik4
- bsf fldg
- calik5 call div
- btfsc flz
- goto outcc
- calik6 movf dg,w
- sublw 3
- btfsc status,z
- goto wrk
- btfss status,c
- goto ddg
- bcf status,c
- rrf aargh
- rrf aargl
- incf dg
- goto calik6
- ddg btfsc aargh,7
- goto outcc
- call rla
- decf dg
- goto calik6
- wrk movlw 2 ;k1-
- subwf fadr
- call wrkk
- movlw 5
- addwf fadr ;k1
- call wrkk
- outca movlw 3
- outca1 addwf fadr
- clrf aargh
- clrf aargl
- call wrkk
- decf fadr
- bcf flwr,0
- goto nn
- ;
- wrkk movf aargh,w
- movwf fdata
- call write
- incf fadr ;k2-,k2
- movf aargl,w
- movwf fdata
- call write
- return
- ;
- outcb decf n
- movlw 5
- goto outca1
- outcc decf n
- movlw 2
- goto outca1
- ;
- ;
- ; Delay routine delay and measure light frequency and check TUBS==1 status ->
- ; Return -> bargl - tmr0 value, bargh -> t0if overflow coutner, dargh -> bargh overflow counter
- delay movlw 50 ;
- movwf count1 ; count1 = 50
- clrf tmr0 ;
- bcf intcon,t0if ;
- del0 call mindel ; Delay for 18ns ;indi ;39cycles
- nop ;
- movlw 7 ;
- movwf count0 ; count0 = 7
- ;
- del1 btfss intcon,t0if ;if t0if == 0 then ( t0if timer 0 overflow bit status)
- goto win1 ; goto win1->win2
- bcf intcon,t0if ; clear t0if
- incfsz bargh ; if (++bargh != 0) then
- incf dargh ; ++dargh
- win2 incfsz count0 ; if (++count0 != 0) then ;1 249 1992-1
- goto del1 ; goto del1 ;2=(8*250)=2000-1;1960-1
- btfss intcon,t0if ; if t0if == 0 then
- goto win3 ; goto win3->win4
- bcf intcon,t0if ; clear t0if
- incfsz bargh ; if (++bargh != 0) then; ;tmr1h ;5+42=47
- incf dargh ; ++dargh ;5+40=45;32=37;43
- win4 btfsc portb,0; ; if( TUBS == 1)
- bcf light ; clear light
- btfss intcon,t0if ; if( t0if == 0 then
- goto win5 ; goto win5->win7
- bcf intcon,t0if ;
- incfsz bargh ;
- incf dargh ;
- win7
- decfsz count1 ; if( --decfsz != 0) then ;1=((10+47)+1991)*50)-1=100000-1;37
- goto del0 ; goto del0 ;2=((4+45)+1999)*50)-1=100000-1;37
- movf tmr0,w ;
- movwf bargl ; bargl = tmr0
- btfsc intcon,t0if ; if( t0if == 1) then
- decf bargl ; --bargl;
- bcf intcon,t0if ; clear t0if
- return
- win1 goto win2
- win3 goto win4
- win5 goto win7
- mindel movlw 11
- movwf inn
- mindel1 decfsz inn ;\3
- goto mindel1 ;\
- nop
- return
- ;
- ;init Routine -> PIC SETUP Functions
- init
- initsl clrf intcon
- bsf intcon,peie ;Enable Peripheral Interrupt
- ;
- movlb 0
- bcf pir1,tmr2if ;Clear Timer2 Intterupt flag
- movlw 0x30
- movwf porta ;PORTA all outputs 0
- movlw 0x0;80;255
- movwf portb ;PORTB all output 0
- movlw 255;249
- movwf pr2 ;Timer 2 Period Register 255
- movlw 0x38
- movwf t2con ;Timer 2 prescaler - 0, timer is off, timmer postscaler -> 8 (1.024Mhz/8 -> 128kHz) (IT Tick 2ms)
- ;
- movlb 1
- movlw 0x2F;98;
- movwf option_reg ;Timer0 prescaler 256, prescaler is not assigned, T0CKI timer0 clock input, TSL Light to freq output
- movlw 0x71;9;4 ;TUBES input and all S (pushbuttons) are inputs
- movwf trisb ;RA1 -> Input, FR(on PCB) is input
- movlw 0x32;6;0 ;110000
- movwf trisa
- movlw 2
- movwf pie1 ;Enable Timer2 interrupt on PR2 match
- movlw 0x14
- movwf wdtcon ;Whatch dog 1S interval (1:132768)
- movlb 2
- movlw 0x06
- movwf cm1con0 ;Comparator Control Register: Comp hyst enable, Comp in normal mode(high speed), Comp disabled
- movlw 0x21
- movwf cm1con1 ;Comp neg pin connects to C12IN1 (RA1 pin (RA1 pin is connected to RA2 dac 1.32V) pin, Comp pos pin connects to FVR voltage reg, no interrupt
- movlw 0x88
- movwf fvrcon ;Comp and DAC voltage ref output is 2.048V, FVR is enabled
- movlw 0xe0
- movwf daccon0 ;DAC output is on DACOUT pin (RA2),DAC pos ref source selected, DAC is enaled
- movlw 19; ;Change: was 20 now 19
- movwf daccon1 ;DAC output is 20, (1.32V?)
- ;
- movlb 3
- clrf eecon1 ; RA1 is analog input
- movlw 0x02
- movwf ansela
- clrf anselb
- ;
- movlb 4
- movlw 0x71
- movwf wpub ;RB1 and all switches have weak-pullup
- movlw 0x20
- movwf wpua ;RA5 have weak-pullup
- ;
- movlb 7
- movlw 0x40
- movwf iocbn ;RB6 have interrupt on neg edge
- ;
- movlb 0
- bcf lobatt ;clear lowbatt flag
- clrf dc1 ;clear dc1
- clrf dc2 ;
- clrf dc3 ;
- ;
- movlw 125
- movwf count1 ;
- clrf tmr2 ;
- bcf pir1,tmr2if ;
- bsf t2con,tmr2on ; Start timer 2
- initrep btfss pir1,tmr2if
- goto initrep ; 2ms (innter loop delay delay)
- bcf pir1,tmr2if
- decfsz count1
- goto initrep ; 250ms (whole delay)
- bcf t2con,tmr2on ; Stop timer 2
- ;
- movlw 250
- movwf count1 ;count1 = 250 (0.5s delay)
- movlw 20 ;count2 = 2 (4 ms delay)
- movwf count3 ;count3 = 20 (40ms delay)
- movwf count4 ;count4 = 20 (40ms delay)
- movlw 2;10;
- movwf count2
- clrf fl1;bcf lightc
- clrf ibuf
- clrf cousleep
- clrf flag
- clrf flwr
- clrf flb
- clrf bash
- clrf basl
- clrf dbuf
- clrf dbuf1
- movlw 50
- call read1 ; Read EEPROM at adress 50
- movwf acorh ; acorh = EEPROM data at adress 50
- movlw 51
- call read1 ; Read EEPROM at adress 51
- movwf acorl ;acor1 = EEPROM data at adress 51
- clrf tmr0
- clrf n
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- init1 movlw 0x42
- call read1
- btfsc status,z ; if EEPROM data at adrr 0x42 = 0 then
- bsf cc1 ; set cc1
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- movlw 2
- call read1
- btfss status,z ; if EEPROM data at addr 0x02 != 0 then
- goto init2 ; goto init2
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- btfsc cc1 ; if cc1==1 then if 0x42==0 and 0x02 == 0 then
- goto init1a ; goto init1a don't copy eeprom data,
- ;
- clrf tmr0
- inittmr clrwdt
- ;btfss intcon,t0if
- ;goto inittmr
- ;bcf intcon,t0if
- ;decfsz count1
- ;goto inittmr ; infinite delay part (ERROR)
- movlw 250
- movwf count1
- delay_250_cycles
- nop
- decfsz count1
- goto delay_250_cycles
- movlw 250
- movwf count1
- goto _copy0 ;copy EEPROM memory from 0x40->0x70 to 0x00->0x3F
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- init1a
- bsf cc
- call indicin ; init variables dc1,dc2 = 11 and dc3 = 10
- init2; call indi
- movlb 0
- init3 clrf fadr
- bsf t2con,tmr2on
- clrf tmr2
- bsf enind2
- bsf enind1
- bcf pir1,tmr2if
- bsf portb,7 ; Turn on TSL light to freq converter
- bsf intcon,gie ; Enable global interrupt
- goto butt ; goto butt -> Main loop
- ;
- ; SETUP ENDS HERE
- ;
- ;
- write movlw 10
- subwf prot1,w
- btfss status,z
- reset;goto cycle;init;
- btfsc cc
- btfss flwr,0
- reset;goto cycle
- ; clrwdt
- bcf intcon,gie
- clrf tmr0
- ;
- ;
- ; bsf status,rp0
- ; bsf eecon1,wren
- ; bcf status,rp0
- BANKSEL EEADRL ;
- movf fadr,w
- movwf eeadrl
- movf fdata,w
- movwf eedatl
- bcf eecon1,cfgs
- bcf eecon1,eepgd
- bsf eecon1,wren
- goto wr1
- ;
- _copy0r
- bcf intcon,gie
- BANKSEL EEADRL
- bcf eecon1,cfgs
- bcf eecon1,eepgd
- movlw 0x40
- movwf eeadrl
- clrf nf
- bcf cc3
- _copy01r
- clrwdt
- bsf eecon1,rd
- movf eedatl,w
- bcf eeadrl,6
- movwf eedatl
- ;
- bsf eecon1,wren
- call write1a
- ;
- incf nf
- btfsc nf,6
- goto _copy11r
- incf eeadrl
- bsf eeadrl,6
- goto _copy01r
- ;Routine -> Copy eeprom data from location 0x40->0x6F to 0x00->0x3F
- _copy0
- bcf intcon,gie ;
- BANKSEL EEADRL ;
- bcf eecon1,cfgs ;
- bcf eecon1,eepgd ;
- movlw 0x40 ;
- movwf eeadrl ;EEPROM addr -> 0x40
- clrf nf ;
- bcf cc3 ;
- _copy01
- clrwdt ; This function copys epprom data from memory location 0x40-0x70 to
- bsf eecon1,rd ; memory location 0x00-0x40
- movf eedatl,w ; w = EEPROM data at 0x40
- bcf eeadrl,6 ; EEPROM addr -> 0x00
- movwf eedatl ; EEPROM data at 0x00 is w or EEPROM data at 0x40
- bsf eecon1,wren ;
- call write1a ; Write byte to memmory location
- incf nf ;
- btfsc nf,6 ; if all data is copied then
- goto init2 ; Start timer 2 and interrupt and go to main loop
- incf eeadrl ;
- bsf eeadrl,6 ;
- goto _copy01 ;
- ;
- _copy1 bcf intcon,gie
- BANKSEL EEADRL
- bcf eecon1,cfgs
- bcf eecon1,eepgd
- movlw 0;x40
- movwf eeadrl
- clrf nf
- _copy11
- clrwdt
- bsf eecon1,rd
- movf eedatl,w
- bsf eeadrl,6
- movwf eedatl
- ;
- bsf eecon1,wren
- call write1a
- ;
- incf nf
- incf eeadrl
- bcf eeadrl,6
- btfss nf,6
- goto _copy11
- _copy11r movlb 0
- bcf cc1
- bcf cc2
- bcf cc3
- clrf tmr0
- bsf intcon,gie
- return
- ;
- org 2000
- reset;goto cycle
- wr1 movlw 10
- subwf prot1,w
- btfss status,z
- reset;goto cycle;init;
- btfsc cc
- btfss flwr,0
- reset; goto cycle
- ;
- movlw 0x55
- movwf eecon2
- movlw 0xAA
- movwf eecon2
- bsf eecon1,wr
- bcf eecon1,wren
- write1 btfsc eecon1,wr
- goto write1
- movlb 0
- write2 clrf tmr0
- bcf pir2,eeif
- bsf intcon,gie
- return
- ;write1a routine -> Routine writes to EEPROM
- write1a movlw 0x55
- movwf eecon2
- movlw 0xAA
- movwf eecon2
- bsf eecon1,wr
- bcf eecon1,wren
- write1b btfsc eecon1,wr
- goto write1b
- return
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement