-
Notifications
You must be signed in to change notification settings - Fork 0
/
lentil4.asm
891 lines (860 loc) · 13.4 KB
/
lentil4.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
; 150W square waveform inverter
; filename:lenti4.asm
; author:Fengjiantao
; Email:fjt@yeah.net
; begin from:1999.10.10
include "e:\comppic\p16c71x.inc"
;Constant definitions
; PWM-module-constant
PWMADJUSTVAL equ 25
VOLTAGER equ 162 ;Voltage request
LOWVOLTAGE equ 184
OVER150 equ 164
OVER125 equ 137
KP equ 40 ;Proportional gain
KI equ 1 ;Integral gain
KD equ 1 ;Differential gain
PWMMAXVAL equ 29
INTCONVAL equ 0b0h ; set GIE, T0IE
OPTIONVAL equ 4fh ; portB have pull-up, tmr0 int.
;Register Equates
HITIMES equ 0ch
HI_ equ 0dh
LOTIMES equ 0eh
LO_ equ 0fh
TIMES equ 10h
STACKW equ 11h ; stack to push/pop the W-register
STACKS equ 12h ; stack to push/pop the STATUS-reg
LOWCOUNT equ 13h ; Low Voltage counter
COUNTER1 equ 14h ; counter2: input frequency
count150 equ 15h;
PWMMAX equ 16h ; register to support generating PWM
count125 equ 17h;
FLAG equ 18h ;
ERR equ 19h ;
SUMLO equ 1ah ;PROGRESSIVE SUM OF the PID terms
ACCUM equ 1bh ;Error accumulator
ERR_O equ 1ch ;error history(last error)
VOLTAGEA equ 1dh ;Voltage actual
mulcnd equ 1eh ;8 bit multiplicand
mulplr equ 1fh ;8 bit multiplier
ACCaLO equ 20h ;for the add routine
ACCbLO equ 21h ;
H_byte equ 22h ;High byte of the 16 bit result
L_byte equ 23h ;Low byte of the 16 bit result
ACCaHI equ 24h
ACCbHI equ 25h
count equ 26h ;Loop counter
SUMHI equ 27h ;High byte of the loop sum
KEYPRESS equ 28h ;KEY counter
LOOPER equ 29H;
polarity equ 0
ER_SGN equ 1 ;Sign bit for the error in flag register
AC_SGN equ 2 ;Sign bit for the error accumulator
DE_SGN equ 3 ;Sign bit for DE/DT
OER_SGN equ 4 ;sign bit for the old error
INT equ 5
;port A:
EN3525 equ 4
TRISAVAL equ 0Fh ; RA0-RA3: input;RA4:Output
ADCON1VAL equ 0 ; A0-A3 analog in
ADCON0VAL equ 89h ; fosc/32, channel 2
ADCON0V0 equ 81h
ADCON0V3 equ 99h
;port B:
LEDR equ 1
LEDG equ 2
PWMA equ 4
PWMB equ 5
KEY equ 7
TRISBVAL equ 81h
;Program entrance
org 0
goto start
org 0004
btfsc INTCON,INTF
goto short
movwf STACKW
swapf STACKW,F
swapf STATUS,W
movwf STACKS
bcf INTCON,T0IF
decfsz TIMES,F
goto ret1
goto pulse
ret1:
swapf STACKS,W
movwf STATUS
swapf STACKW,W
retfie
pulse:
btfsc FLAG,polarity
goto polarityb
btfsc PORTB,PWMA
goto Lowpulse
comf HI_,w
addwf PWMMAX,f
btfss STATUS,C
goto HIGHIMPINT
movf PWMMAX,w
addwf PCL,f
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
bsf PORTB,PWMA
movlw PWMADJUSTVAL+1
movwf TMR0
movf HITIMES,w
movwf TIMES
goto ret2
HIGHIMPINT:
addlw PWMADJUSTVAL
movwf TMR0
bsf PORTB,PWMA
movf HITIMES,w
movwf TIMES
incf TIMES,f
ret2:
; incf COUNTER,F
movlw PWMMAXVAL
movwf PWMMAX
swapf STACKS,W
movwf STATUS
swapf STACKW,W
retfie
Lowpulse:
comf LO_,w
addwf PWMMAX,f
btfss STATUS,C
goto LOWIMPINT
movf PWMMAX,w
addwf PCL,f
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
bcf PORTB,PWMA
movlw PWMADJUSTVAL+3
movwf TMR0
movf LOTIMES,w
movwf TIMES
goto ret3
LOWIMPINT:
movlw PWMADJUSTVAL+3
movwf TMR0
bcf PORTB,PWMA
movf LOTIMES,w
movwf TIMES
incf TIMES,f
ret3:
bsf FLAG,polarity
movlw PWMMAXVAL
movwf PWMMAX
swapf STACKS,W
movwf STATUS
swapf STACKW,W
retfie
polarityb:
btfsc PORTB,PWMB
goto Lowpulse2
comf HI_,w
addwf PWMMAX,f
btfss STATUS,C
goto HIGHIMPINT2
movf PWMMAX,w
addwf PCL,f
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
bsf PORTB,PWMB
movlw PWMADJUSTVAL+5
movwf TMR0
movf HITIMES,w
movwf TIMES
goto ret4
HIGHIMPINT2:
addlw PWMADJUSTVAL+5
movwf TMR0
bsf PORTB,PWMB
movf HITIMES,w
movwf TIMES
incf TIMES,f
ret4:
movlw PWMMAXVAL
movwf PWMMAX
swapf STACKS,W
movwf STATUS
swapf STACKW,W
retfie
Lowpulse2:
comf LO_,w
addwf PWMMAX,f
btfss STATUS,C
goto LOWIMPINT2
movf PWMMAX,w
addwf PCL,f
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
bcf PORTB,PWMB
movlw PWMADJUSTVAL+2
movwf TMR0
movf LOTIMES,w
movwf TIMES
goto ret5
LOWIMPINT2:
movlw PWMADJUSTVAL+2
movwf TMR0
bcf PORTB,PWMB
movf LOTIMES,w
movwf TIMES
incf TIMES,f
ret5:
bcf FLAG,polarity
movlw PWMMAXVAL
movwf PWMMAX
bsf FLAG,INT
incf COUNTER1,f
swapf STACKS,W
movwf STATUS
swapf STACKW,W
retfie
short:
bcf PORTB,PWMA
bcf PORTB,PWMB
bsf PORTB,LEDR
bcf INTCON,T0IE
movlw 100 ;delay 100 times
movwf LOOPER
bsf STATUS,RP0
movlw 47h
movwf OPTION_
bcf STATUS,RP0
sdelayloop:
clrf TMR0
scheckagain:
btfss INTCON,T0IF
goto scheckagain
bcf INTCON,T0IF
decfsz LOOPER,f
goto sdelayloop
bcf INTCON,INTF
goto start
mpy_s: ;8 bit multiply
clrf H_byte
clrf L_byte
movlw 8
movwf count
movf mulcnd,w
bcf STATUS,C
loop:
rrf mulplr,f
btfsc STATUS,C
addwf H_byte,f
rrf H_byte,f
rrf L_byte,f
decfsz count,f
goto loop
retlw 0
D_sub: ;Double precision add and subtract
call neg_A
D_add:
movf ACCaLO,w
addwf ACCbLO,f
btfsc STATUS,C
incf ACCbHI,f
movf ACCaHI,w
addwf ACCbHI,f
retlw 00
neg_A: ;negate ACCa
comf ACCaLO,f
incf ACCaLO,f
btfsc STATUS,Z
decf ACCaHI,f
comf ACCaHI,f
retlw 00
DIV_LMT: ;Divide by 16 and limit to 100 Decimal
BCF STATUS,C
RRF L_byte,f
BCF STATUS,C
RRF H_byte,f
BTFSC STATUS,C
BSF L_byte,7
BCF STATUS,C
RRF L_byte,f
BCF STATUS,C
RRF H_byte,f
BTFSC STATUS,C
BSF L_byte,7
BCF STATUS,C
RRF L_byte,f
BCF STATUS,C
RRF H_byte,f
BTFSC STATUS,C
BSF L_byte,7
BCF STATUS,C
RRF L_byte,f
BCF STATUS,C
RRF H_byte,f
BTFSC STATUS,C
BSF L_byte,7
LMT100:
MOVLW 1h
SUBWF H_byte,0
BTFSS STATUS,C
GOTO L8_E
MOVLW 64H
MOVWF L_byte
GOTO LMT_EXIT
L8_E:
MOVLW 64H
SUBWF L_byte,w
BTFSS STATUS,C
GOTO LMT_EXIT
movlw 64h
movwf L_byte
LMT_EXIT:
retlw 00
PIDTERM:
C_ERR: ;Calculating the PID terms
movf VOLTAGEA,w
sublw VOLTAGER
btfsc STATUS,C
goto PLS_ER
goto MNS_ER
PLS_ER:
MOVWF ERR
bcf FLAG,ER_SGN
goto CE_EXIT
MNS_ER:
movlw VOLTAGER
subwf VOLTAGEA,w
movwf ERR
bsf FLAG,ER_SGN
CE_EXIT:
clrf SUMLO
clrf SUMHI
C_PROP: ;Calculate the proportional term
movf ERR,w
movwf mulcnd
MOVLW KP
movwf mulplr
CALL mpy_s
call DIV_LMT
restorre_SGN:
btfss FLAG,ER_SGN
goto ADDPROP
comf L_byte,f
INCF L_byte,f
ADDPROP:
movf L_byte,w
addwf SUMLO,f
btfsc STATUS,C
incf SUMHI,f
movlw 0
Btfsc SUMLO,7
movlw 0ffH
addwf SUMHI,f
C_INT: ;calculate the integral term
movf ERR,w
btfsc STATUS,Z
goto ADDINT
btfsc FLAG,ER_SGN
goto MNS_1
PLS_1:
movlw KI
addwf ACCUM,f
goto LMTACM
MNS_1:
movlw KI
subwf ACCUM,f
LMTACM:
btfsc ACCUM,7
goto M_LMT
P_LMT:
MOVLW 9ch
addwf ACCUM,w
btfss STATUS,C
goto ADDINT
movlw 64h
movwf ACCUM
goto ADDINT
M_LMT:
movlw 9ch
subwf ACCUM,w
btfsc STATUS,C
goto ADDINT
movlw 9ch
movwf ACCUM
ADDINT:
movf ACCUM,w
addwf SUMLO,f
btfsc STATUS,C
incf SUMHI,f
movlw 0
btfsc ACCUM,7
comf W,w
addwf SUMHI,f
C_DIFF: ;Calculate the differential term
movf ERR,w
btfss FLAG,ER_SGN
goto LO_BYTE
comf ERR,1
incf ERR,w
comf ERR,f
LO_BYTE:
movwf ACCbLO
movlw 0
btfsc FLAG,ER_SGN
movlw 0ffH
movwf ACCbHI
movf ERR_O,w
btfss FLAG,OER_SGN
goto LO_BYTE0
comf ERR_O,f
incf ERR_O,w
LO_BYTE0:
movwf ACCaLO
movlw 0
btfsc FLAG,OER_SGN
movlw 0ffH
movwf ACCaHI
call D_sub
STRIP_SGN:
btfsc ACCbHI,7
goto NEG_ABS
goto POS_ABS
NEG_ABS:
bsf FLAG,DE_SGN
comf ACCbLO,f
incf ACCbLO,w
movwf ERR_O
goto MULT_KD
POS_ABS:
BCF FLAG,DE_SGN
movf ACCbLO,w
movwf ERR_O
MULT_KD:
movf ERR_O,w
movwf mulcnd
movlw KD
movwf mulplr
call mpy_s
call DIV_LMT
RE_SGN:
btfss FLAG,DE_SGN
goto SAVE_DIFF
comf L_byte,f
incf L_byte,f
SAVE_DIFF:
movf L_byte,w
btfsc STATUS,Z
goto ROLL_ER
movwf ERR_O
ADDDIF: ;Add the diff term into the summ
movlw 0
btfsc FLAG,DE_SGN
movlw 0ffH
movwf ACCbHI
movf ERR_O,W
movwf ACCbLO
movf SUMLO,w
movwf ACCaLO
movf SUMHI,w
movwf ACCaHI
call D_add
movf ACCbLO,w
movwf SUMLO
movf ACCbHI,w
movwf SUMHI
ROLL_ER:
Movf ERR,W
movwf ERR_O
bcf FLAG,OER_SGN
btfsc FLAG,ER_SGN
bsf FLAG,OER_SGN
movf HITIMES,w
movwf ACCaHI
movf HI_,w
movwf ACCaLO
movf SUMHI,w
movwf ACCbHI
movf SUMLO,w
movwf ACCbLO
call D_add
WaitNoIntt:
movf TMR0,W
sublw 0c8h
btfss STATUS,C
goto WaitNoIntt
movf ACCbHI,w
sublw 24h
movf ACCbHI,w
btfss STATUS,C
movlw 24h
btfsc STATUS,Z
movlw 1
movwf HITIMES
movwf ACCaHI
movf ACCbLO,w
movwf HI_
movf ACCbLO,w
movwf ACCaLO
movlw 27h
movwf ACCbHI
movlw 10h
movwf ACCbLO
call D_sub
movf ACCbHI,w
movwf LOTIMES
movf ACCbLO,w
movwf LO_
return
SLP:
btfsc PORTB,KEY ;Key press?
goto RUN ;No
incf KEYPRESS,f ;Yes,counter +1
btfss KEYPRESS,7 ;reach 128?
goto RUN1 ;No
bsf PORTA,EN3525 ;Yes,go to bed
bcf INTCON,T0IE ;Disable intuppter
bcf PORTB,LEDR ;Led OFF
bcf PORTB,LEDG
bcf PORTB,PWMA
bcf PORTB,PWMB
waitnopress:
btfss PORTB,KEY ;wait key up
goto waitnopress
movlw 100 ;delay 100 times
movwf LOOPER
delayloop:
clrf TMR0
checkagain:
btfss INTCON,T0IF
goto checkagain
bcf INTCON,T0IF
decfsz LOOPER,f
goto delayloop
bcf INTCON,RBIF ;Set RB int
bsf INTCON,RBIE
sleep ;sleep until RB7 press
bcf INTCON,RBIE
bcf INTCON,RBIF
waitnoprs:
btfss PORTB,KEY ;wait key up
goto waitnoprs
bcf PORTA,EN3525
bsf INTCON,T0IE
bsf PORTB,LEDG
RUN:
clrf KEYPRESS ;clear key counter
RUN1:
; incf COUNTER2,F
; bcf COUNTER,07h
return
ADC:
movlw ADCON0VAL
movwf ADCON0
WaitNoInt:
movf TMR0,W
sublw 0d0h
btfss STATUS,C
goto WaitNoInt
bsf ADCON0,GO
WaitAdc:
btfsc ADCON0,GO
goto WaitAdc
movf ADRES,W
movwf VOLTAGEA
return
;LIGHT
; btfss COUNTER1,4
; return
; movlw 0
; movwf COUNTER1
; btfss LEDREG,FLASHR
; goto NOFLASH1
; btfss PORTB,LEDR
; goto LEDRL
; goto LEDRH
;NOFLASH1
; btfsc LEDREG,LEDR
; goto LEDRH
;LEDRL
; bsf PORTB,LEDR
; goto LIGHTG
;LEDRH
; bcf PORTB,LEDR
;LIGHTG
; btfss LEDREG,FLASHG
; goto NOFLASH2
; btfss PORTB,LEDG
; goto LEDGL
; goto LEDGH
;NOFLASH2
; btfsc LEDREG,LEDG
; goto LEDGH
;LEDGL
; bsf PORTB,LEDG
; return
;LEDGH
; bcf PORTB,LEDG
; return
LOWDET:
movlw ADCON0V0
movwf ADCON0
WaitNoIntl:
movf TMR0,W
sublw 0d0h
btfss STATUS,C
goto WaitNoIntl
bsf ADCON0,GO
WaitAdcl:
btfsc ADCON0,GO
goto WaitAdcl
movf ADRES,W
sublw LOWVOLTAGE
btfss STATUS,C
goto lret1
incf LOWCOUNT,f
btfss LOWCOUNT,7
return
bcf PORTB,PWMA
bcf PORTB,PWMB
bsf PORTA,EN3525
bcf INTCON,T0IE
; bsf LEDREG,LEDR
; bcf LEDREG,FLASHR
; bcf LEDREG,FLASHG
; bcf LEDREG,LEDG
bcf PORTB,LEDG
bsf PORTB,LEDR
bcf INTCON,RBIF ;Set RB int
bsf INTCON,RBIE
sleep ;sleep until RB7 press
bcf INTCON,RBIE
bcf INTCON,RBIF
goto start
lret1:
clrf LOWCOUNT
return
OVERCUT:
movlw ADCON0V3
movwf ADCON0
WaitNoIntO:
movf TMR0,W
sublw 0d0h
btfss STATUS,C
goto WaitNoIntO
bsf ADCON0,GO
WaitAdcO:
btfsc ADCON0,GO
goto WaitAdcO
movf ADRES,W
sublw OVER150
btfsc STATUS,C
goto O125
incf count150,f
btfss count150,7
goto O1251
bsf PORTB,LEDR
bcf PORTB,LEDG
bcf PORTB,PWMA
bcf PORTB,PWMB
movlw 50 ;delay 100 times
movwf LOOPER
movlw 47h
bsf STATUS,RP0
movwf OPTION_
bcf STATUS,RP0
bcf INTCON,T0IE
delayloop1:
clrf TMR0
checkagain1:
btfss INTCON,T0IF
goto checkagain1
bcf INTCON,T0IF
decfsz LOOPER,f
goto delayloop1
goto start
O125:
clrf count150
O1251:
movf ADRES,W
sublw OVER125
btfsc STATUS,C
goto ORET
movf COUNTER1,w
btfsc STATUS,Z
incf count125,f
BTfss count125,4
return
bsf PORTB,LEDR
bcf PORTB,LEDG
bcf PORTB,PWMA
bcf PORTB,PWMB
movlw 50 ;delay 100 times
movwf LOOPER
movlw 47h
bsf STATUS,RP0
movwf OPTION_
bcf STATUS,RP0
bcf INTCON,T0IE
delayloop2:
clrf TMR0
checkagain2:
btfss INTCON,T0IF
goto checkagain2
bcf INTCON,T0IF
decfsz LOOPER,f
goto delayloop2
goto start
ORET:
clrf count125
return
start:
movlw PWMMAXVAL
movwf PWMMAX
movlw 0bh
movwf LOTIMES
movlw 71h
movwf LO_
movlw 1bh
movwf HITIMES
movlw 9fh
movwf HI_
bsf STATUS,RP0
movlw TRISAVAL
movwf TRISA
movlw TRISBVAL
movwf TRISB
bcf PORTB,PWMA
bcf PORTB,PWMB
movlw ADCON1VAL
movwf ADCON1
movlw OPTIONVAL
movwf OPTION_
bcf STATUS,RP0
clrf TMR0
movlw INTCONVAL
movwf INTCON
bsf PORTB,LEDG
bcf PORTB,LEDR
bcf PORTA,EN3525
Idle:
clrwdt
call SLP
btfss FLAG,INT
goto Idle
bcf FLAG,INT
; call ADC
; call PIDTERM
call LOWDET
call OVERCUT
; call LIGHT
goto Idle
end
Build completed successfully.