Advertisement
Adminsys_sys

Untitled

Feb 15th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.75 KB | None | 0 0
  1. ; Project: DEN-1B (SenLux version)
  2. ;
  3. ; Company: Biosan
  4. ;
  5. ; Original Name befor modification: DEN-1B-PV02I4
  6. ; After mod name: DEN-1B-PV02I5
  7. ;
  8. ; Author: Robert
  9. ;
  10. ; Modified: By Eizens Poiss
  11. ; Faulty code located at line 1578, faulty code commeted out, Faulty part of code
  12. ; would go in infinte loop, because tm0 connected to light sensor and light sensor
  13. ; at this moment is turned off.
  14. ;
  15. ; New function added delay_250_cycles for delay
  16. ;
  17. ; Modification Date: 30/09/19
  18. ;
  19. ;
  20. ;
  21. ; New modification: Battery low signal is changed from ~3V to ~3.4V
  22. ;
  23. ; Code moficiation on line: 1514. Battery low threshold change from 20 to 19 DAC values.
  24. ; New code version: DEN-1B-PV02I6
  25. ;
  26. ; Modification Date: 18.03.21
  27. ;
  28. ;
  29. ;
  30. ;
  31. ;Crystal 4.096 MHz, Timer 2 INT 2ms
  32.  
  33. list p=16f1827
  34. include p16f1827.inc
  35. cblock 0x20
  36. aargh, aargl, bargh, bargl
  37. dargh, dargl, gargh, gargl
  38. count1, count2, count3, count4
  39. dg, lgh, lgl
  40. prot2, count0,ibuf,cousleep
  41. ndiv, basl, bash, n, flb
  42. dbuf, dbuf1,buf,nm
  43. d1,d2,d3,d4,d5
  44. dc1,tf1,dc2,tf2,dc3,tf3,dc4,tf4
  45. dg1,fl1,acorh,acorl,inn,count2a
  46. inn1,count5,fl2,pb
  47. endc
  48. cblock 0x70
  49. fadr,fdata,flag,prot1,flwr,nf
  50. ;
  51. endc
  52.  
  53. ;portb bit
  54. #define date portb,1
  55. #define clock portb,2
  56. #define s2 portb,4
  57. #define s1 portb,5
  58. #define s3 portb,6
  59. ;porta bit
  60. ;#define s1 porta,5
  61. ;#define relay porta,2
  62. #define led porta,3;2
  63. ;flag bits
  64. #define cc flag,0
  65. #define over flag,2
  66. #define lobatt flag,3
  67. #define flz flag,4
  68. #define flc flag,5
  69. #define fldg flag,6
  70. #define mes flag,7
  71. ;flb bits
  72. #define en1 flb,0
  73. #define en2 flb,1
  74. #define gen flb,2
  75. #define entr flb,3
  76. #define entrans flb,4
  77. #define first flb,5
  78. #define freq flb,7
  79. ;fl1
  80. #define light fl1,0
  81. #define lightc fl1,1
  82. #define dark fl1,2
  83. #define cc1 fl1,3
  84. #define cc2 fl1,4
  85. #define cc3 fl1,5
  86. #define enind1 fl1,6
  87. #define enind2 fl1,7
  88. ;flb fl2
  89. #define enind fl2,0
  90.  
  91. ; org 0x2102
  92. ; data 0
  93. ; data 0
  94. ; __config 0x0005;01;1;
  95. org 0xF002;2100;
  96. de 0,0
  97. org 0xF042
  98. de 0,0
  99. __config _config1, 0x0C12;4;0E1C
  100. __config _config2, 0x18FC;1AFC
  101. org 0
  102. begin movlw 10
  103. movwf prot1
  104. movwf prot2
  105. goto init
  106. ;
  107. org 4
  108. goto intt;
  109. ;
  110. indi2 btfsc cc2
  111. goto num13
  112. btfsc cc3
  113. goto num10
  114. andlw 15 ;1
  115. ; addwf pcl
  116. brw ;b a f g e d c p
  117. num0 retlw 0xEE ;1 1 1 0 1 1 1 0
  118. num1 retlw 0x82 ;1 0 0 0 0 0 1 0
  119. num2 retlw 0xDC ;1 1 0 1 1 1 0 0
  120. num3 retlw 0xD6 ;1 1 0 1 0 1 1 0
  121. num4 retlw 0xB2 ;1 0 1 1 0 0 1 0
  122. num5 retlw 0x76 ;0 1 1 1 0 1 1 0
  123. num6 retlw 0x7E ;0 1 1 1 1 1 1 0
  124. num7 retlw 0xC2 ;1 1 0 0 0 0 1 0
  125. num8 retlw 0xFE ;1 1 1 1 1 1 1 0
  126. num9 retlw 0xF6 ;1 1 1 1 0 1 1 0
  127. num10 retlw 0x0 ;0 0 0 0 0 0 0 0 over
  128. num11 retlw 0x6C ;0 1 1 0 1 1 0 0 CC
  129. num12 retlw 0x10 ;0 0 0 1 0 0 0 0 --
  130. num13 retlw 0x04 ;0 0 0 0 0 1 0 0 ___
  131. num14 retlw 0x84 ;1 0 0 0 0 1 0 0
  132. ;
  133. ;;;;;;;;;;;;;;;;;
  134.  
  135. intt movlb 0
  136. ; clrf status
  137. bcf pir1,tmr2if
  138. bsf en2
  139. ;
  140. bsf porta,0
  141. decfsz count1 ;/250=2hz;/50=10hz
  142. goto pop
  143. movlw 250;50;
  144. movwf count1
  145. ;
  146. btfss cc
  147. btfsc freq
  148. goto intt2
  149. ;
  150. movf portb,w
  151. movwf pb
  152. btfsc pb,0
  153. goto intt1
  154. ;
  155. bsf enind1
  156. btfss enind2
  157. goto intt2
  158. bcf enind2
  159. ;
  160. bsf enind
  161. bsf enind1
  162. bsf mes
  163. goto intt2
  164. intt1 bsf enind2
  165. btfss enind1
  166. goto intt2
  167. bsf enind
  168. bcf enind1
  169. movlw 2
  170. movwf count2
  171. ;
  172. intt2;; bcf porta,0
  173. ; decfsz count1 ;/250=2hz;/50=10hz
  174. ; goto pop
  175. ; movlw 250;50;
  176. ; movwf count1
  177. ;
  178. bsf portb,7
  179. decfsz count2 ;/1hz
  180. goto blink0
  181. movlw 2
  182. movwf count2
  183. ; bsf portb,7
  184. bsf flwr,7
  185. btfsc cc
  186. goto blink0
  187. bsf mes
  188. btfss pb,0
  189. bsf enind
  190. ; bsf porta,0
  191. ; goto pop
  192.  
  193. ;
  194. blink0 btfsc freq
  195. btfss dark
  196. goto blink
  197. btfss count2,0
  198. goto blink2
  199. clrf tf1
  200. clrf tf2
  201. clrf tf3
  202. call trans
  203. goto pop
  204. blink; btfsc portb,7
  205. btfss cc
  206. goto pop;indi
  207. btfss count2,0
  208. goto blink1
  209. movlw 0x0A
  210. movwf dc1
  211. movwf dc2
  212. movwf dc3
  213. goto blink2
  214. blink1 call indic
  215. blink2 call indi
  216. pop movf portb,w
  217. xorlw 0x04
  218. btfss entr
  219. movwf portb
  220. pop1 bcf pir1,tmr2if
  221. ; swapf temp1,w
  222. ; movwf status
  223. ; swapf temp0,w
  224. retfie
  225.  
  226. ;
  227. indi
  228. btfss freq
  229. btfsc cc
  230. goto indi1
  231. btfss cc2
  232. btfsc cc3
  233. goto indi1
  234. btfss enind
  235. return
  236. ; btfsc pb,0
  237. bcf enind
  238. indi1
  239. movlb 2
  240. bsf cm1con0,c1on
  241. movlw 0xe0
  242. movwf daccon0
  243. movlb 0
  244. ;
  245. clrf tf1
  246. clrf tf2
  247. clrf tf3
  248. movf dc3,w
  249. call indi2
  250. movwf buf
  251. andlw 0xF0
  252. movwf tf1
  253. movf buf,w
  254. andlw 0x0E
  255. movwf tf3
  256. ; btfsc cmcon,c2out
  257. movlb 2
  258. btfsc cm1con0,c1out
  259. bsf lobatt
  260. bcf cm1con0,c1on
  261. clrf daccon0
  262. movlb 0
  263. ; movlw 0x07
  264. ; movwf cmcon
  265. ;;;;;;;;;;
  266. movf dc2,w
  267. call indi2
  268. movwf buf
  269. swapf buf,w
  270. andlw 0x0F
  271. iorwf tf1
  272. swapf buf,w
  273. andlw 0xF0
  274. btfsc dc2,4
  275. iorlw 0x10
  276. iorwf tf3
  277. ;;;;;;;;;;
  278. ;
  279. ; bcf portb,3
  280. ;
  281. movf dc1,w
  282. call indi2
  283. btfsc dc1,4
  284. iorlw 1
  285. movwf tf2
  286. ;;;;;;;;;
  287.  
  288. ;;;;;;;;;;;
  289. trans bsf entr
  290. bcf date ;start bit
  291. nop
  292. nop
  293. bsf clock
  294. nop
  295. nop
  296. bcf clock
  297. nop
  298. nop
  299. ;;;;;;;;;;;;;;
  300. bsf date
  301. nop
  302. nop
  303. bsf clock ;1
  304. nop
  305. nop
  306. bcf clock
  307. nop
  308. nop
  309. ;;;;;;;;;;;;;;
  310. bcf date
  311. nop
  312. nop
  313. bsf clock ;2
  314. nop
  315. nop
  316. bcf clock
  317. nop
  318. nop
  319. ;;;;;;;;;;;;;
  320. btfsc lobatt ;lo batt
  321. bsf date
  322. movlw 24
  323. bsf clock ;3
  324. movwf inn1
  325. ; bcf date
  326. trans1 bcf status,c
  327. bcf clock
  328. rlf tf3
  329. rlf tf2
  330. rlf tf1
  331. ; bcf date
  332. btfss status,c
  333. goto tran1a
  334. bsf date
  335. nop
  336. nop
  337. tran2a bsf clock ;+24=27
  338. nop
  339. ; bcf date
  340. decfsz inn1
  341. goto trans1
  342. ;;;;;;;;;;;;;;;;;;;
  343. movlw 15;8;9;10
  344. bcf clock
  345. movwf inn1
  346. bcf date
  347. nop
  348. nop
  349. trans2 bsf clock ;+8=35
  350. nop
  351. nop
  352. bcf clock
  353. decfsz inn1
  354. goto trans2
  355. ;
  356. ; bsf date
  357. nop
  358. nop
  359. bsf clock ;36
  360. nop
  361. nop
  362. nop
  363. bcf clock
  364. nop
  365. nop
  366. nop
  367. bcf date
  368. nop
  369. nop
  370. ;
  371. bsf clock
  372. nop
  373. nop
  374. bcf clock
  375. ; bsf portb,3
  376. ; bsf intcon,gie
  377. ; bcf pir1,tmr2if
  378. bcf entr
  379. return
  380. ;
  381. tran1a bcf date
  382. nop
  383. goto tran2a
  384.  
  385.  
  386. ; MAIN LOOP - butt
  387. butt clrwdt ; Clear watchdog
  388. butt1 movlw 10 ;
  389. subwf prot1,w ; w = prot1 - 10 (prot1 is init 10)
  390. btfss status,z ; prot1 - 10 != 0 then
  391. reset ; reset PIC
  392. butt1_
  393. btfsc mes ; if mes==1 then
  394. goto messur ; goto measur
  395. btfss en2 ; if en2==0 then
  396. goto butt1 ; goto butt1
  397. btfss s1 ; if s1==0 then if pushbutton SB1 (setup) is pressed
  398. goto choce ; goto choce
  399. btfss s2 ; if s2==0 then if pushbutton SB2 (install) is pressed
  400. goto b1 ; goto b1
  401. goto b2 ; goto b2
  402. ; MAIN LOOP END
  403. ;
  404. ;
  405. ;
  406. ;Happens after pressed setup button
  407. ;
  408. choce btfss en1 ; if( en1 ==0) then
  409. goto b3 ; goto b3
  410. btfss freq ; if(freq == 0) then
  411. bsf cc ; cc = 1
  412. bcf freq ; freq = 0
  413. bcf en1 ; en1 = 0
  414. btfss cc ; if(cc == 1) then
  415. goto exb ; goto exb
  416. clrf count4 ; count4 = 0
  417. decf n,w ; w = n - 1
  418. btfss status,z ; if((n - 1) != 0) then)
  419. goto nn; ; goto nn
  420. btfss lightc ; if( lightc == 0)
  421. goto b4 ; goto b4
  422. goto exb; ; goto exb
  423. ;
  424. ;
  425.  
  426. ;Routine nn
  427. nn incf n ; ++n
  428. movf n,w ; w = n
  429. sublw 9 ; w = n - 9
  430. btfsc status,z ; if(n = 9) then
  431. goto nn1 ; goto nn1
  432. call indic ;
  433. goto exb ; goto exb
  434. nn1 bcf cc ;
  435. bcf flwr,0
  436. clrf n
  437. clrf fadr
  438. bcf lightc
  439. goto exb
  440. b1 btfss cc
  441. goto b3a;b1a
  442. btfss en1
  443. goto b1a
  444. bcf en1
  445. ;
  446. ; btfsc lightc
  447. ; goto b11
  448. ; bsf lightc
  449. ; goto b12
  450. ;
  451. b11 movf n,w
  452. btfsc status,z
  453. goto nn1
  454. b12 bsf mes
  455. bsf porta,0
  456. bsf flwr,0
  457. goto exb
  458. b1a movlw 80
  459. movwf count3
  460. bcf cc2
  461. bcf cc3
  462. goto exb
  463. b2 btfsc en1
  464. goto b2a
  465. decfsz count3
  466. goto exb
  467. b2a bsf en1
  468. movlw 80
  469. movwf count3
  470. clrf count4
  471. clrf count5
  472. goto exb
  473. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  474. b3a btfsc freq
  475. ;
  476. ; btfss freq
  477. ; btfss cc1
  478. goto b1a
  479. btfss en1
  480. goto b1a
  481. movlw 80
  482. movwf count3
  483. btfss flwr,7
  484. goto exb
  485. bcf flwr,7
  486. ;
  487. btfsc cc1
  488. ;
  489. bsf cc2
  490. ;
  491. btfss cc1
  492. bsf cc3
  493. ;
  494. btfsc count5,2
  495. goto exb
  496. incf count5
  497. btfss count5,2
  498. goto exb
  499. ;;;;;;;;;;;;;;
  500. BCF en1
  501. ;;;;;;;;;;;;;;
  502. btfss cc1
  503. goto B3B
  504. call _copy1
  505. goto b4
  506. ;;;;;;;;;;;;;;;;;;;;;;
  507.  
  508. b3b call _copy0r
  509. goto b4
  510. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  511. ; Routine b3
  512. b3 movlw 80 ;
  513. movwf count3 ; count3 = 80
  514. btfss flwr,7 ; if( flwr,7 == 0) then
  515. goto exb ; goto exb
  516. bcf flwr,7 ; clear flwr,7
  517. movf n,w ;
  518. sublw 1 ; w = n - 1
  519. btfsc status,c ; if(n - 1 < 0) then
  520. btfsc count4,2 ; if(count4 == 4) then
  521. goto exb ; goto exb
  522. incf count4 ; ++count4
  523. btfss count4,2 ; if(count4 == 4) then
  524. goto exb ; goto exb
  525. bsf freq ; freq = 1
  526. b4 bcf cc ; cc = 0
  527. bcf flwr,0 ; flwr, 0 = 0
  528. clrf n ; n = 0
  529. clrf fadr ; fadr = 0
  530. exb bcf en2 ; clear en2
  531. goto butt ; goto butt(main loop)
  532. ; b3 END
  533. ;
  534.  
  535. ; routine indic
  536. indic movf n,w
  537. btfss status,z ; if(n
  538. goto indic1
  539.  
  540. indicin movlw 11
  541. movwf dc1
  542. movwf dc2
  543. movlw 10
  544. movwf dc3
  545. return
  546. indic1 movwf dbuf
  547. ;
  548. btfsc lightc
  549. goto indic1a
  550. movlw 12
  551. movwf dc1
  552. movwf dc2
  553. movwf dc3
  554. return
  555. ;
  556. indic1a decf dbuf
  557. ;
  558. sublw 2
  559. btfss status,z
  560. goto indic2
  561. ;
  562. ; movf dbuf,w
  563. ; btfss status,z
  564. ; goto indic2
  565. movlw 5
  566. movwf dc2
  567. clrf dc1
  568. goto indic3
  569. indic2 movf dbuf,w
  570. ;
  571. btfss status,z
  572. decf dbuf,w
  573. ;
  574. movwf dc1
  575. clrf dc2
  576. indic3 bsf dc1,4
  577. clrf dc3
  578. return
  579.  
  580. ;Measure routine
  581. messur
  582. bcf intcon,gie
  583. bsf flwr,5
  584. bsf led ; Turn on LED
  585. bsf light ; Set light bit
  586. bcf t2con,tmr2on ; Stop timer 2
  587. movlb 2
  588. bsf cm1con0,c1on ; Enable Comparator
  589. movlw 0xe0 ;
  590. movwf daccon0 ; DAC output enable
  591. movlb 0
  592. bcf lobatt ;
  593. clrf dargh ; bargh overflow counter
  594. clrf bargh ; timer 0 overflow counter
  595. call delay ; Delay and measure frequency and check TUBS status
  596. movlb 2
  597. btfsc cm1con0,c1out ; if c1out == 1 then
  598. bsf lobatt ; set lobatt
  599. movlb 0
  600. meas1 bcf led ; Turn off LED
  601. movf bargh,w ;
  602. movwf aargh ; aargh = bargh (timer 0 overflow counter)
  603. movf bargl,w ;
  604. movwf aargl ; aargl = bargl (timer 0 counter register)
  605. btfsc portb,0 ; if( TUBS == 1) then
  606. bcf light ; clear light
  607. movf bargh,w ;
  608. subwf dargh,w ; w = dargh - bargh (bargh overflow - tm0 overflow counter)
  609. bcf over ; over = 0
  610. btfss status,z ; if(w != 0)
  611. bsf over ; over = 1
  612. ; clrf dargh
  613. clrf bargh ; tm0 overflow counter clear
  614. call delay ;
  615. btfsc portb,0;2 ;
  616. bcf light ;
  617. ;; movf tmr1h,w
  618. ;; movwf burgh
  619. call test ;
  620. btfsc status,c ;
  621. goto mes1 ;
  622. clrf aargh ;
  623. clrf aargl ;
  624. bsf over ;
  625. goto mes2 ;
  626. ;
  627. mes1 call dtoa
  628. mes2
  629. ; bsf dark
  630. ;;;; btfss freq
  631. btfss light
  632. goto mes3
  633. bsf dark
  634. goto mes4
  635. mes3 bcf dark
  636. mes4; bcf porta,0
  637.  
  638. bcf mes
  639. bsf t2con,tmr2on
  640. clrf tmr2
  641. bcf pir1,tmr2if
  642. movlw 250
  643. movwf count1
  644. bsf intcon,gie
  645. ;
  646. ; call indi
  647. ;
  648. bcf flwr,5
  649. btfsc freq;
  650. goto dcorr;
  651. ;
  652. btfsc lightc
  653. goto acorr;lgment
  654. btfss cc
  655. goto acorr;lgment
  656. movlw 50
  657. movwf fadr
  658. movf aargh,w
  659. movwf acorh
  660. movwf fdata
  661. call write
  662. incf fadr
  663. movf aargl,w
  664. movwf acorl
  665. movwf fdata
  666. call write
  667. ;
  668. movlw 2
  669. movwf fadr
  670. clrf fdata
  671. call write
  672. incf fadr
  673. clrf fdata
  674. call write
  675. ;
  676. clrf fadr
  677. bsf lightc
  678. goto butt
  679. ;
  680. acorr btfss light
  681. goto acor00
  682. movf aargh,w
  683. movwf acorh
  684. movf aargl,w
  685. movwf acorl
  686. goto outdc;lgment
  687. acor00 movlw 15
  688. movwf dg
  689. movwf dg1
  690. bcf fldg
  691. acorr0 btfsc aargh,7
  692. goto acorr1
  693. call rla
  694. decfsz dg
  695. goto acorr0
  696. goto lgment
  697. acorr1 movf acorh,w
  698. movwf bargh
  699. movf acorl,w
  700. movwf bargl
  701. acorr2 btfsc bargh,7
  702. goto acorr3
  703. bcf status,c
  704. rlf bargl
  705. rlf bargh
  706. decfsz dg1
  707. goto acorr2
  708. goto lgment
  709. acorr3 call div
  710. movf dg1,w
  711. subwf dg
  712. bcf flc
  713. btfsc status,c
  714. bsf flc
  715. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  716. movlw 16 ;add1,rrgd
  717. movwf ndiv
  718. bcorr1 movlw 50
  719. call read1
  720. movwf gargh
  721. movlw 51
  722. call read1
  723. movwf gargl
  724. ; movlw 16 ;add1,rrgd
  725. ; movwf ndiv
  726. ; addwf dg,w
  727. ; movwf ndiv
  728. clrf dargh
  729. clrf dargl
  730. multi bcf status,c
  731. btfsc gargl,0
  732. call add1
  733. decfsz ndiv
  734. goto multi1
  735. ;
  736. ; btfss status,c
  737. ; goto multi3
  738. ; call rrgd1
  739. ; incf dg
  740. ;
  741. multi3 call dtoa
  742. movf dg,w
  743. btfsc status,z
  744. goto lgment
  745. btfsc flc;dg,7;s
  746. goto multi2
  747. multi0 call rrgd
  748. incfsz dg;decfsz dg;
  749. goto multi0
  750. call dtoa
  751. goto lgment
  752. multi2 call rla
  753. decfsz dg;
  754. goto multi2
  755. goto lgment
  756. multi1 call rrgd1
  757. goto multi
  758. ;
  759. ; call lg_arg
  760. lgment clrf lgh
  761. clrf lgl
  762. movlw 15
  763. movwf dg
  764. movlw 160
  765. movwf bargh
  766. clrf bargl
  767. bcf fldg
  768. lg10 movlw 3
  769. subwf dg,w
  770. btfss status,c
  771. goto lg20
  772. btfsc status,z
  773. goto lg12
  774. btfsc aargh,7
  775. goto lg11
  776. call rla
  777. decf dg
  778. goto lg10
  779. lg12 bsf fldg
  780. lg11 call div
  781. btfsc flz
  782. goto lg20
  783. ;
  784. movlw 0xE8;100
  785. addwf lgl
  786. movlw 3
  787. btfsc status,c
  788. addlw 1
  789. addwf lgh
  790. ;
  791. ; incf lgh
  792. movlw 3
  793. subwf dg
  794. goto lg10
  795. lg20 movlw 0xA1 ;1.0010.0111.1001.1111
  796. movwf bargh ;1001.0011.1100.1111
  797. movlw 0x24 ;147 .207
  798. movwf bargl ;a1 24
  799. bcf fldg
  800. lg20a movf dg,w
  801. btfsc status,z
  802. goto lg22
  803. btfsc aargh,7
  804. goto lg21
  805. call rla
  806. decfsz dg
  807. goto lg20a
  808. lg22 bsf fldg
  809. lg21 call div
  810. btfsc flz
  811. goto lg30
  812. ;
  813. movlw 100
  814. addwf lgl
  815. btfsc status,c
  816. ;
  817. incf lgh ;lgl
  818. goto lg20a
  819. ;592d,250h
  820. lg30 movlw 0x82 ;1.0000.0010.0101.0000
  821. movwf bargh ;1000.0001.0010.1000
  822. movlw 0xFB ;129 .40
  823. movwf bargl ;82 fb
  824. lg30a call div
  825. btfsc flz
  826. goto lg40;lgout
  827. ;
  828. movlw 10
  829. addwf lgl
  830. btfsc status,c
  831. incf lgh
  832. ;
  833. goto lg30a
  834. ;
  835. lg40 movlw 0x80 ;1.0000.0000.1001.0110
  836. movwf bargh ;1000.0000.0100.1011
  837. movlw 0x4B ;80 .4B
  838. movwf bargl ;82 fb
  839. lg40a call div
  840. btfsc flz
  841. goto lgout
  842. ;
  843. incfsz lgl
  844. goto lg40a
  845. incf lgh
  846. ;
  847. goto lg40a
  848. ;
  849. rla bcf status,c
  850. rlf aargl
  851. rlf aargh
  852. return
  853. ;
  854. test movf bargl,w
  855. subwf aargl,w
  856. btfss status,c
  857. goto test1
  858. movwf dargl
  859. movf bargh,w
  860. test2 subwf aargh,w
  861. movwf dargh
  862. return
  863. test1 movwf dargl
  864. incf bargh,w
  865. goto test2
  866. ;
  867. dtoa movf dargl,w
  868. movwf aargl
  869. movf dargh,w
  870. movwf aargh
  871. return
  872. ;
  873. div movlw 16
  874. movwf ndiv
  875. clrf gargh
  876. clrf gargl
  877. bcf flc
  878. bcf flz
  879. btfsc aargh,7
  880. goto div0
  881. goto div2
  882. div0 call test
  883. btfss status,c
  884. goto div2
  885. div1 call dtoa
  886. incf gargl
  887. div4 decfsz ndiv
  888. goto div5
  889. movf gargl,w
  890. movwf aargl
  891. movf gargh,w
  892. movwf aargh
  893. return
  894. div5 bcf status,c
  895. rlf gargl
  896. rlf gargh
  897. call rla
  898. btfsc status,c
  899. bsf flc
  900. goto div0
  901. div2 btfss ndiv,4
  902. goto div3
  903. btfss fldg
  904. goto div3
  905. bsf flz
  906. return
  907. div3 btfss flc
  908. goto div4
  909. bcf flc
  910. goto div1
  911. ;
  912.  
  913. read movf fadr,w
  914. read1
  915. banksel eeadrl
  916. movwf eeadrl
  917. bcf eecon1,cfgs
  918. bcf eecon1,eepgd
  919. bsf eecon1,rd
  920. movf eedatl,w
  921. movlb 0
  922. return
  923. ;
  924. lgout btfsc flwr,0
  925. goto calibr ;calibr,select,
  926. goto select ;mul,add.
  927. ;
  928. dcora call dtoa
  929. clrf fadr
  930. dcorr clrf dbuf
  931. movlw 0x10 ;
  932. movwf bargl ;10000
  933. movlw 0x27
  934. movwf bargh
  935. call dcorr0
  936. movf dbuf,w
  937. movwf d1
  938. ;
  939. dcorr2 clrf dbuf
  940. movlw 0xE8 ;11 11101000
  941. movwf bargl ;3 e8
  942. movlw 3
  943. movwf bargh
  944. call dcorr0
  945. movf dbuf,w
  946. movwf d2
  947. clrf dbuf
  948. movlw 100
  949. movwf bargl
  950. clrf bargh
  951. call dcorr0
  952. movf dbuf,w
  953. movwf d3
  954. ;
  955. clrf dbuf
  956. movlw 10
  957. movwf bargl
  958. clrf bargh
  959. call dcorr0
  960. movf dbuf,w
  961. movwf d4
  962. movf aargl,w
  963. movwf d5
  964. ;
  965.  
  966. ;
  967. outdc; bsf enld
  968. ; goto butt
  969. ;
  970. load; movlw 0;255
  971. ; movwf tf4
  972. ; btfsc enld
  973. ;
  974. btfsc cc
  975. goto blinki;indi
  976. ;
  977. ; movlw 0x05
  978. ; movwf cmcon
  979. ;
  980. btfsc dark
  981. goto load5
  982. ;
  983. load0 btfsc over
  984. goto load3
  985. movf d1,w
  986. btfsc status,z
  987. goto load1
  988. loadn movwf dc1
  989. movf d2,w
  990. movwf dc2
  991. movf d3,w
  992. movwf dc3
  993. goto load4
  994. load1 bsf d3,4
  995. movf d2,w
  996. btfsc status,z
  997. goto load2
  998. movwf dc1
  999. movf d3,w
  1000. movwf dc2
  1001. movf d4,w
  1002. movwf dc3
  1003. goto load4
  1004. load2 movf d3,w
  1005. movwf dc1
  1006. movf d4,w
  1007. movwf dc2
  1008. movf d5,w
  1009. movwf dc3
  1010. goto load4
  1011. ;
  1012. load5; movlw 13
  1013. ; movwf dc1
  1014. ; movwf dc2
  1015. ; movwf dc3
  1016. btfsc freq
  1017. goto load0
  1018. ;
  1019. clrf dc2
  1020. clrf dc3
  1021. movlw 0x10
  1022. movwf dc1
  1023. incf cousleep
  1024. btfss cousleep,6
  1025. goto load4a
  1026. clrf cousleep
  1027. bcf portb,7
  1028. clrf porta;;;
  1029. clrf t2con
  1030. movlw 0x08
  1031. movwf intcon
  1032. ;
  1033. ; movlb 1
  1034. ; movlw 0x02
  1035. ; movwf osccon
  1036. movlb 2
  1037. clrf cm1con0
  1038. clrf fvrcon
  1039. clrf daccon0
  1040. movlb 0
  1041. ;
  1042. _sleep sleep
  1043. nop
  1044. btfsc intcon,IOCIF;rbif
  1045. btfsc portb,6
  1046. goto _sleep
  1047. ;
  1048. movlb 7
  1049. bcf iocbf,6
  1050. movlb 0
  1051. ;
  1052. clrwdt
  1053. clrf status
  1054. movlw 2
  1055. movwf count2
  1056. goto 0;initsl
  1057. ;
  1058. load3 movlw 0x1A
  1059. movwf dc1
  1060. movlw 10
  1061. movwf dc2
  1062. movwf dc3
  1063. ; bcf enld
  1064. load4
  1065. clrf cousleep
  1066. btfss dark
  1067. ; movlw 250
  1068. ; movwf count1
  1069.  
  1070. ; bcf lobatt
  1071. ; bsf t2con,tmr2on
  1072. ; clrf tmr2
  1073. ; bcf pir1,tmr2if
  1074. ; btfsc cmcon,c2out
  1075. ; bsf lobatt
  1076. ;
  1077. ; movlw 0x07
  1078. ; movwf cmcon
  1079.  
  1080. load4a; bcf intcon,gie
  1081. call indi;pop
  1082. ;
  1083. ; bsf intcon,gie
  1084.  
  1085. ;
  1086. goto butt
  1087. ;
  1088. blinki btfss count2,0
  1089. goto blinki1
  1090. movlw 0x0A
  1091. movwf dc1
  1092. movwf dc2
  1093. movwf dc3
  1094. goto blink2
  1095. blinki1; bcf intcon,gie
  1096. call indic
  1097. blinki2 call indi
  1098. ; bsf intcon,gie
  1099. goto butt
  1100. ;
  1101. dcorr0 call test
  1102. btfss status,c
  1103. return
  1104. incf dbuf
  1105. call dtoa
  1106. goto dcorr0
  1107. ;
  1108. select movlw 2
  1109. call read1
  1110. btfss status,z
  1111. goto sel0a
  1112. clrf fadr
  1113. goto init1
  1114. sel0a clrf fadr
  1115. sel0 movlw 6
  1116. addwf fadr
  1117. sel2 call sela
  1118. btfsc status,c
  1119. goto sel1
  1120. movlw 7
  1121. subwf fadr
  1122. call sela
  1123. ;
  1124. bcf flc
  1125. ;
  1126. btfss status,c
  1127. bsf flc
  1128. goto mull
  1129. sel1 movlw 5
  1130. addwf fadr
  1131. goto sel2
  1132. ;
  1133. sela call read
  1134. movwf bash
  1135. incf fadr
  1136. call read
  1137. movwf basl
  1138. iorwf bash,w
  1139. btfss status,z
  1140. goto sela0
  1141. bcf status,c
  1142. return
  1143. sela0 movf lgl,w
  1144. subwf basl,w
  1145. movwf aargl
  1146. btfss status,c
  1147. goto sela1
  1148. movf lgh,w
  1149. sela2 subwf bash,w
  1150. movwf aargh
  1151. return
  1152. sela1 incf lgh,w
  1153. goto sela2
  1154. ;
  1155. mull
  1156. ;
  1157. btfsc flc
  1158. call neg
  1159. ;
  1160. call rla
  1161. call rla
  1162. call rla
  1163. ;
  1164. clrf dargh
  1165. clrf dargl
  1166. movf aargl,w
  1167. iorwf aargh,w
  1168. btfsc status,z
  1169. goto dcam12
  1170. dcam10 movlw 10
  1171. subwf aargl
  1172. incfsz dargl
  1173. goto dcam11
  1174. incf dargh
  1175. dcam11 btfsc status,c
  1176. goto dcam10
  1177. decf aargh
  1178. btfss aargh,7
  1179. goto dcam10
  1180. movlw 1
  1181. subwf dargl
  1182. btfss status,c
  1183. decf dargh
  1184. call dtoa
  1185. ;
  1186. dcam12
  1187. movlw 16 ;add1,rrgd
  1188. movwf ndiv
  1189. clrf dargh
  1190. clrf dargl
  1191. incf fadr
  1192. call read
  1193. movwf gargh
  1194. incf fadr
  1195. call read
  1196. movwf gargl
  1197. ; btfsc flc
  1198. ; call neg
  1199. ;
  1200. mull0a; call rla
  1201. ; call rla
  1202. ; call rla
  1203. mull0 bcf status,c
  1204. btfsc gargl,0
  1205. call add1
  1206. decfsz ndiv
  1207. goto mull1
  1208. call dtoa
  1209. btfsc flc
  1210. call neg
  1211. goto add
  1212. ;
  1213. neg comf aargh
  1214. comf aargl
  1215. incfsz aargl
  1216. return
  1217. incf aargh
  1218. return
  1219. ;
  1220. mull1 call rrgd1
  1221. goto mull0
  1222. ;
  1223. add1 movf aargl,w
  1224. addwf dargl
  1225. btfsc status,c
  1226. incf dargh
  1227. movf aargh,w
  1228. addwf dargh
  1229. return
  1230. ;
  1231. rrgd bcf status,c
  1232. rrgd1 rrf dargh
  1233. rrf dargl
  1234. bcf status,c
  1235. rrf gargh
  1236. rrf gargl
  1237. return
  1238. ;
  1239. add incf fadr
  1240. call read
  1241. movwf gargh
  1242. incf fadr
  1243. call read
  1244. movwf gargl
  1245. ;
  1246. clrf dargh
  1247. clrf dargl
  1248. movf gargl,w
  1249. iorwf gargh,w
  1250. btfsc status,z
  1251. goto dkam12
  1252. dkam10 movlw 10
  1253. subwf gargl
  1254. incfsz dargl
  1255. goto dkam11
  1256. incf dargh
  1257. dkam11 btfsc status,c
  1258. goto dkam10
  1259. movlw 1
  1260. subwf gargh
  1261. btfsc status,c
  1262. goto dkam10
  1263. movlw 1
  1264. subwf dargl
  1265. btfss status,c
  1266. decf dargh
  1267. ;
  1268. dkam12 call add1
  1269. ;
  1270. btfss flc
  1271. goto dcora
  1272. btfsc status,c
  1273. goto dcora
  1274. ; bcf porta,dout
  1275. ; clrf dbuf1
  1276. clrf dc1
  1277. bsf dc1,4;;;;;;;;;;;;;;
  1278. clrf dc2
  1279. clrf dc3
  1280. clrf fadr
  1281. ; bcf intcon,gie
  1282. call indi
  1283. ; bsf intcon,gie
  1284. goto butt
  1285. ;
  1286. calibr movf lgh,w ;lg
  1287. movwf fdata
  1288. call write
  1289. incf fadr
  1290. movf lgl,w
  1291. movwf fdata
  1292. call write
  1293. ;
  1294. ; swapf dbuf ;A
  1295. movf dbuf,w
  1296. ; btfsc status,z
  1297. ;
  1298. btfss status,z
  1299. goto calib2a
  1300. clrf dargh
  1301. clrf dargl
  1302. goto calib3
  1303. calib2a decf dbuf;,w
  1304. btfsc status,z
  1305. ;
  1306. goto calib1
  1307. clrf dargh
  1308. clrf dargl
  1309. calib2 movlw 0xE8;100
  1310. addwf dargl
  1311. movlw 3
  1312. btfsc status,c
  1313. addlw 1
  1314. addwf dargh
  1315. decfsz dbuf
  1316. goto calib2
  1317. calib3 movlw 3
  1318. addwf fadr ;aa
  1319. movf dargh,w
  1320. movwf fdata
  1321. call write
  1322. incf fadr
  1323. movf dargl,w
  1324. movwf fdata
  1325. call write
  1326. goto calik
  1327. calib1 movlw 1
  1328. movwf dargh
  1329. movlw 0XF4;50
  1330. movwf dargl
  1331. goto calib3
  1332. ;
  1333. calik movlw 11 ;lg-
  1334. subwf fadr
  1335. btfsc status,c
  1336. goto calik1
  1337. movlw 8 ;k1
  1338. addwf fadr
  1339. clrf fdata
  1340. call write
  1341. incf fadr ;k2
  1342. clrf fdata
  1343. call write
  1344. goto outca
  1345. calik1 call sela
  1346. btfss status,c
  1347. goto outcb
  1348. clrf dg
  1349. calik2 btfsc aargh,7
  1350. goto calik3
  1351. call rla
  1352. incf dg
  1353. btfss dg,4
  1354. goto calik2
  1355. goto outcb
  1356. calik3 movf aargh,w
  1357. movwf bargh
  1358. movf aargl,w
  1359. movwf bargl
  1360. call dtoa
  1361. movlw 4
  1362. addwf fadr ;a2-
  1363. call read
  1364. subwf aargl
  1365. btfss status,c
  1366. decf aargh
  1367. decf fadr ;a1-
  1368. call read
  1369. subwf aargh
  1370. bcf fldg
  1371. calik4 btfsc aargh,7
  1372. goto calik5
  1373. call rla
  1374. decfsz dg
  1375. goto calik4
  1376. bsf fldg
  1377. calik5 call div
  1378. btfsc flz
  1379. goto outcc
  1380. calik6 movf dg,w
  1381. sublw 3
  1382. btfsc status,z
  1383. goto wrk
  1384. btfss status,c
  1385. goto ddg
  1386. bcf status,c
  1387. rrf aargh
  1388. rrf aargl
  1389. incf dg
  1390. goto calik6
  1391. ddg btfsc aargh,7
  1392. goto outcc
  1393. call rla
  1394. decf dg
  1395. goto calik6
  1396. wrk movlw 2 ;k1-
  1397. subwf fadr
  1398. call wrkk
  1399. movlw 5
  1400. addwf fadr ;k1
  1401. call wrkk
  1402. outca movlw 3
  1403. outca1 addwf fadr
  1404. clrf aargh
  1405. clrf aargl
  1406. call wrkk
  1407. decf fadr
  1408. bcf flwr,0
  1409. goto nn
  1410. ;
  1411. wrkk movf aargh,w
  1412. movwf fdata
  1413. call write
  1414. incf fadr ;k2-,k2
  1415. movf aargl,w
  1416. movwf fdata
  1417. call write
  1418. return
  1419. ;
  1420. outcb decf n
  1421. movlw 5
  1422. goto outca1
  1423. outcc decf n
  1424. movlw 2
  1425. goto outca1
  1426. ;
  1427. ;
  1428. ; Delay routine delay and measure light frequency and check TUBS==1 status ->
  1429. ; Return -> bargl - tmr0 value, bargh -> t0if overflow coutner, dargh -> bargh overflow counter
  1430. delay movlw 50 ;
  1431. movwf count1 ; count1 = 50
  1432. clrf tmr0 ;
  1433. bcf intcon,t0if ;
  1434. del0 call mindel ; Delay for 18ns ;indi ;39cycles
  1435. nop ;
  1436. movlw 7 ;
  1437. movwf count0 ; count0 = 7
  1438. ;
  1439. del1 btfss intcon,t0if ;if t0if == 0 then ( t0if timer 0 overflow bit status)
  1440. goto win1 ; goto win1->win2
  1441. bcf intcon,t0if ; clear t0if
  1442. incfsz bargh ; if (++bargh != 0) then
  1443. incf dargh ; ++dargh
  1444. win2 incfsz count0 ; if (++count0 != 0) then ;1 249 1992-1
  1445. goto del1 ; goto del1 ;2=(8*250)=2000-1;1960-1
  1446. btfss intcon,t0if ; if t0if == 0 then
  1447. goto win3 ; goto win3->win4
  1448. bcf intcon,t0if ; clear t0if
  1449. incfsz bargh ; if (++bargh != 0) then; ;tmr1h ;5+42=47
  1450. incf dargh ; ++dargh ;5+40=45;32=37;43
  1451. win4 btfsc portb,0; ; if( TUBS == 1)
  1452. bcf light ; clear light
  1453. btfss intcon,t0if ; if( t0if == 0 then
  1454. goto win5 ; goto win5->win7
  1455. bcf intcon,t0if ;
  1456. incfsz bargh ;
  1457. incf dargh ;
  1458. win7
  1459. decfsz count1 ; if( --decfsz != 0) then ;1=((10+47)+1991)*50)-1=100000-1;37
  1460. goto del0 ; goto del0 ;2=((4+45)+1999)*50)-1=100000-1;37
  1461. movf tmr0,w ;
  1462. movwf bargl ; bargl = tmr0
  1463. btfsc intcon,t0if ; if( t0if == 1) then
  1464. decf bargl ; --bargl;
  1465. bcf intcon,t0if ; clear t0if
  1466. return
  1467.  
  1468. win1 goto win2
  1469. win3 goto win4
  1470. win5 goto win7
  1471. mindel movlw 11
  1472. movwf inn
  1473. mindel1 decfsz inn ;\3
  1474. goto mindel1 ;\
  1475. nop
  1476. return
  1477. ;
  1478. ;init Routine -> PIC SETUP Functions
  1479. init
  1480. initsl clrf intcon
  1481. bsf intcon,peie ;Enable Peripheral Interrupt
  1482. ;
  1483. movlb 0
  1484. bcf pir1,tmr2if ;Clear Timer2 Intterupt flag
  1485. movlw 0x30
  1486. movwf porta ;PORTA all outputs 0
  1487. movlw 0x0;80;255
  1488. movwf portb ;PORTB all output 0
  1489. movlw 255;249
  1490. movwf pr2 ;Timer 2 Period Register 255
  1491. movlw 0x38
  1492. movwf t2con ;Timer 2 prescaler - 0, timer is off, timmer postscaler -> 8 (1.024Mhz/8 -> 128kHz) (IT Tick 2ms)
  1493. ;
  1494. movlb 1
  1495. movlw 0x2F;98;
  1496. movwf option_reg ;Timer0 prescaler 256, prescaler is not assigned, T0CKI timer0 clock input, TSL Light to freq output
  1497. movlw 0x71;9;4 ;TUBES input and all S (pushbuttons) are inputs
  1498. movwf trisb ;RA1 -> Input, FR(on PCB) is input
  1499. movlw 0x32;6;0 ;110000
  1500. movwf trisa
  1501. movlw 2
  1502. movwf pie1 ;Enable Timer2 interrupt on PR2 match
  1503. movlw 0x14
  1504. movwf wdtcon ;Whatch dog 1S interval (1:132768)
  1505. movlb 2
  1506. movlw 0x06
  1507. movwf cm1con0 ;Comparator Control Register: Comp hyst enable, Comp in normal mode(high speed), Comp disabled
  1508. movlw 0x21
  1509. 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
  1510. movlw 0x88
  1511. movwf fvrcon ;Comp and DAC voltage ref output is 2.048V, FVR is enabled
  1512. movlw 0xe0
  1513. movwf daccon0 ;DAC output is on DACOUT pin (RA2),DAC pos ref source selected, DAC is enaled
  1514. movlw 19; ;Change: was 20 now 19
  1515. movwf daccon1 ;DAC output is 20, (1.32V?)
  1516. ;
  1517. movlb 3
  1518. clrf eecon1 ; RA1 is analog input
  1519. movlw 0x02
  1520. movwf ansela
  1521. clrf anselb
  1522. ;
  1523. movlb 4
  1524. movlw 0x71
  1525. movwf wpub ;RB1 and all switches have weak-pullup
  1526. movlw 0x20
  1527. movwf wpua ;RA5 have weak-pullup
  1528. ;
  1529. movlb 7
  1530. movlw 0x40
  1531. movwf iocbn ;RB6 have interrupt on neg edge
  1532. ;
  1533. movlb 0
  1534.  
  1535. bcf lobatt ;clear lowbatt flag
  1536.  
  1537. clrf dc1 ;clear dc1
  1538. clrf dc2 ;
  1539. clrf dc3 ;
  1540. ;
  1541.  
  1542. movlw 125
  1543. movwf count1 ;
  1544. clrf tmr2 ;
  1545. bcf pir1,tmr2if ;
  1546. bsf t2con,tmr2on ; Start timer 2
  1547. initrep btfss pir1,tmr2if
  1548. goto initrep ; 2ms (innter loop delay delay)
  1549. bcf pir1,tmr2if
  1550. decfsz count1
  1551. goto initrep ; 250ms (whole delay)
  1552. bcf t2con,tmr2on ; Stop timer 2
  1553. ;
  1554. movlw 250
  1555. movwf count1 ;count1 = 250 (0.5s delay)
  1556. movlw 20 ;count2 = 2 (4 ms delay)
  1557. movwf count3 ;count3 = 20 (40ms delay)
  1558. movwf count4 ;count4 = 20 (40ms delay)
  1559. movlw 2;10;
  1560. movwf count2
  1561. clrf fl1;bcf lightc
  1562. clrf ibuf
  1563. clrf cousleep
  1564. clrf flag
  1565. clrf flwr
  1566. clrf flb
  1567. clrf bash
  1568. clrf basl
  1569. clrf dbuf
  1570. clrf dbuf1
  1571. movlw 50
  1572. call read1 ; Read EEPROM at adress 50
  1573. movwf acorh ; acorh = EEPROM data at adress 50
  1574. movlw 51
  1575. call read1 ; Read EEPROM at adress 51
  1576. movwf acorl ;acor1 = EEPROM data at adress 51
  1577. clrf tmr0
  1578. clrf n
  1579. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  1580. init1 movlw 0x42
  1581. call read1
  1582. btfsc status,z ; if EEPROM data at adrr 0x42 = 0 then
  1583. bsf cc1 ; set cc1
  1584. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1585. movlw 2
  1586. call read1
  1587. btfss status,z ; if EEPROM data at addr 0x02 != 0 then
  1588. goto init2 ; goto init2
  1589. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1590. btfsc cc1 ; if cc1==1 then if 0x42==0 and 0x02 == 0 then
  1591. goto init1a ; goto init1a don't copy eeprom data,
  1592. ;
  1593. clrf tmr0
  1594. inittmr clrwdt
  1595. ;btfss intcon,t0if
  1596. ;goto inittmr
  1597. ;bcf intcon,t0if
  1598. ;decfsz count1
  1599. ;goto inittmr ; infinite delay part (ERROR)
  1600. movlw 250
  1601. movwf count1
  1602. delay_250_cycles
  1603. nop
  1604. decfsz count1
  1605. goto delay_250_cycles
  1606. movlw 250
  1607. movwf count1
  1608. goto _copy0 ;copy EEPROM memory from 0x40->0x70 to 0x00->0x3F
  1609. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  1610. init1a
  1611. bsf cc
  1612. call indicin ; init variables dc1,dc2 = 11 and dc3 = 10
  1613. init2; call indi
  1614. movlb 0
  1615. init3 clrf fadr
  1616. bsf t2con,tmr2on
  1617. clrf tmr2
  1618. bsf enind2
  1619. bsf enind1
  1620. bcf pir1,tmr2if
  1621. bsf portb,7 ; Turn on TSL light to freq converter
  1622. bsf intcon,gie ; Enable global interrupt
  1623. goto butt ; goto butt -> Main loop
  1624. ;
  1625. ; SETUP ENDS HERE
  1626. ;
  1627. ;
  1628. write movlw 10
  1629. subwf prot1,w
  1630. btfss status,z
  1631. reset;goto cycle;init;
  1632. btfsc cc
  1633. btfss flwr,0
  1634. reset;goto cycle
  1635. ; clrwdt
  1636. bcf intcon,gie
  1637. clrf tmr0
  1638.  
  1639. ;
  1640.  
  1641. ;
  1642. ; bsf status,rp0
  1643. ; bsf eecon1,wren
  1644. ; bcf status,rp0
  1645. BANKSEL EEADRL ;
  1646. movf fadr,w
  1647. movwf eeadrl
  1648. movf fdata,w
  1649. movwf eedatl
  1650. bcf eecon1,cfgs
  1651. bcf eecon1,eepgd
  1652. bsf eecon1,wren
  1653. goto wr1
  1654. ;
  1655. _copy0r
  1656. bcf intcon,gie
  1657. BANKSEL EEADRL
  1658. bcf eecon1,cfgs
  1659. bcf eecon1,eepgd
  1660. movlw 0x40
  1661. movwf eeadrl
  1662. clrf nf
  1663. bcf cc3
  1664. _copy01r
  1665. clrwdt
  1666. bsf eecon1,rd
  1667. movf eedatl,w
  1668. bcf eeadrl,6
  1669. movwf eedatl
  1670. ;
  1671. bsf eecon1,wren
  1672. call write1a
  1673. ;
  1674. incf nf
  1675. btfsc nf,6
  1676. goto _copy11r
  1677. incf eeadrl
  1678. bsf eeadrl,6
  1679. goto _copy01r
  1680. ;Routine -> Copy eeprom data from location 0x40->0x6F to 0x00->0x3F
  1681. _copy0
  1682. bcf intcon,gie ;
  1683. BANKSEL EEADRL ;
  1684. bcf eecon1,cfgs ;
  1685. bcf eecon1,eepgd ;
  1686. movlw 0x40 ;
  1687. movwf eeadrl ;EEPROM addr -> 0x40
  1688. clrf nf ;
  1689. bcf cc3 ;
  1690. _copy01
  1691. clrwdt ; This function copys epprom data from memory location 0x40-0x70 to
  1692. bsf eecon1,rd ; memory location 0x00-0x40
  1693. movf eedatl,w ; w = EEPROM data at 0x40
  1694. bcf eeadrl,6 ; EEPROM addr -> 0x00
  1695. movwf eedatl ; EEPROM data at 0x00 is w or EEPROM data at 0x40
  1696. bsf eecon1,wren ;
  1697. call write1a ; Write byte to memmory location
  1698. incf nf ;
  1699. btfsc nf,6 ; if all data is copied then
  1700. goto init2 ; Start timer 2 and interrupt and go to main loop
  1701. incf eeadrl ;
  1702. bsf eeadrl,6 ;
  1703. goto _copy01 ;
  1704. ;
  1705. _copy1 bcf intcon,gie
  1706. BANKSEL EEADRL
  1707. bcf eecon1,cfgs
  1708. bcf eecon1,eepgd
  1709. movlw 0;x40
  1710. movwf eeadrl
  1711. clrf nf
  1712. _copy11
  1713. clrwdt
  1714. bsf eecon1,rd
  1715. movf eedatl,w
  1716. bsf eeadrl,6
  1717. movwf eedatl
  1718. ;
  1719. bsf eecon1,wren
  1720. call write1a
  1721. ;
  1722. incf nf
  1723. incf eeadrl
  1724. bcf eeadrl,6
  1725. btfss nf,6
  1726. goto _copy11
  1727. _copy11r movlb 0
  1728. bcf cc1
  1729. bcf cc2
  1730. bcf cc3
  1731. clrf tmr0
  1732. bsf intcon,gie
  1733. return
  1734.  
  1735. ;
  1736. org 2000
  1737. reset;goto cycle
  1738. wr1 movlw 10
  1739. subwf prot1,w
  1740. btfss status,z
  1741. reset;goto cycle;init;
  1742. btfsc cc
  1743. btfss flwr,0
  1744. reset; goto cycle
  1745. ;
  1746. movlw 0x55
  1747. movwf eecon2
  1748. movlw 0xAA
  1749. movwf eecon2
  1750. bsf eecon1,wr
  1751. bcf eecon1,wren
  1752. write1 btfsc eecon1,wr
  1753. goto write1
  1754. movlb 0
  1755. write2 clrf tmr0
  1756. bcf pir2,eeif
  1757. bsf intcon,gie
  1758. return
  1759.  
  1760. ;write1a routine -> Routine writes to EEPROM
  1761. write1a movlw 0x55
  1762. movwf eecon2
  1763. movlw 0xAA
  1764. movwf eecon2
  1765. bsf eecon1,wr
  1766. bcf eecon1,wren
  1767. write1b btfsc eecon1,wr
  1768. goto write1b
  1769. return
  1770. end
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement