Advertisement
Adminsys_sys

Assembler to C++

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