Mercurial > public > hwos_code
comparison src/adc_lightsensor.asm @ 474:2880aa1264f5
Fix new battery menu on Power-on reset
author | heinrichsweikamp |
---|---|
date | Wed, 04 Jan 2017 15:04:42 +0100 |
parents | 4fdf6886004b |
children | 237afdfb4918 |
comparison
equal
deleted
inserted
replaced
473:c6f36c55b4f6 | 474:2880aa1264f5 |
---|---|
547 movwf ADCON2 | 547 movwf ADCON2 |
548 ; movlw b'00000000' ; Vref+ = Vdd | 548 ; movlw b'00000000' ; Vref+ = Vdd |
549 clrf ADCON1 | 549 clrf ADCON1 |
550 movlw b'00100101' ; power on ADC, select AN9 | 550 movlw b'00100101' ; power on ADC, select AN9 |
551 rcall wait_adc | 551 rcall wait_adc |
552 movff ADRESH,analog_sw2 | 552 banksel analog_counter |
553 movff ADRESH,WREG | |
554 addwf analog_sw2_raw+0 | |
555 movlw .0 | |
556 addwfc analog_sw2_raw+1 | |
557 decfsz analog_counter,F ; continue averaging? | |
558 bra get_analog_switches2a ; Yes | |
559 ; Done. Compute average | |
560 bcf STATUS,C | |
561 rrcf analog_sw2_raw+1 | |
562 rrcf analog_sw2_raw+0 ; /2 | |
563 bcf STATUS,C | |
564 rrcf analog_sw2_raw+1 | |
565 rrcf analog_sw2_raw+0 ; /4 | |
566 bcf STATUS,C | |
567 rrcf analog_sw2_raw+1 | |
568 rrcf analog_sw2_raw+0 ; /8 | |
569 bcf STATUS,C | |
570 rrcf analog_sw2_raw+1 | |
571 rrcf analog_sw2_raw+0 ; /16 | |
572 movff analog_sw2_raw+0, analog_sw2 | |
573 clrf analog_sw2_raw+1 | |
574 clrf analog_sw2_raw+0 ; Reset average registers | |
575 ; movlw .16 | |
576 ; movwf analog_counter ; only once... | |
577 get_analog_switches2a: | |
578 banksel common | |
553 bcf analog_sw2_pressed | 579 bcf analog_sw2_pressed |
554 movff opt_cR_button_left,WREG ;20-100 | 580 movff opt_cR_button_left,WREG ;20-100 |
555 bcf STATUS,C | 581 bcf STATUS,C |
556 rrcf WREG ;/2 -> 10-50 | 582 rrcf WREG ;/2 -> 10-50 |
557 bcf STATUS,C | 583 bcf STATUS,C |
558 rrcf WREG ;/2 -> 5-25 | 584 rrcf WREG ;/2 -> 5-25 |
559 addlw .126 ;131-151 | 585 decf WREG,W ;-1 |
586 decf WREG,W ;-1 | |
587 decf WREG,W ;-1 -> 2-22 | |
588 banksel analog_sw2 | |
589 addwf analog_sw2,W ; average (~128) | |
590 banksel common | |
560 cpfsgt ADRESH | 591 cpfsgt ADRESH |
561 bra get_analog_sw1 | 592 bra get_analog_sw1 |
562 sw2_pressed: | |
563 bsf analog_sw2_pressed | 593 bsf analog_sw2_pressed |
564 get_analog_sw1: | 594 get_analog_sw1: |
565 movlw b'00101001' ; power on ADC, select AN10 | 595 movlw b'00101001' ; power on ADC, select AN10 |
566 rcall wait_adc | 596 rcall wait_adc |
567 movff ADRESH,analog_sw1 | 597 banksel analog_counter |
598 movff ADRESH,WREG | |
599 addwf analog_sw1_raw+0 | |
600 movlw .0 | |
601 addwfc analog_sw1_raw+1 | |
602 tstfsz analog_counter ; continue averaging? | |
603 bra get_analog_switches1a ; Yes | |
604 ; Done. Compute average | |
605 bcf STATUS,C | |
606 rrcf analog_sw1_raw+1 | |
607 rrcf analog_sw1_raw+0 ; /2 | |
608 bcf STATUS,C | |
609 rrcf analog_sw1_raw+1 | |
610 rrcf analog_sw1_raw+0 ; /4 | |
611 bcf STATUS,C | |
612 rrcf analog_sw1_raw+1 | |
613 rrcf analog_sw1_raw+0 ; /8 | |
614 bcf STATUS,C | |
615 rrcf analog_sw1_raw+1 | |
616 rrcf analog_sw1_raw+0 ; /16 | |
617 movff analog_sw1_raw+0, analog_sw1 | |
618 clrf analog_sw1_raw+1 | |
619 clrf analog_sw1_raw+0 ; Reset average registers | |
620 movlw .16 | |
621 movwf analog_counter ; only once... | |
622 get_analog_switches1a: | |
623 banksel common | |
568 bcf analog_sw1_pressed | 624 bcf analog_sw1_pressed |
625 movff opt_cR_button_right,WREG ;20-100 | |
569 bcf STATUS,C | 626 bcf STATUS,C |
570 rrcf WREG ;/2 -> 10-50 | 627 rrcf WREG ;/2 -> 10-50 |
571 bcf STATUS,C | 628 bcf STATUS,C |
572 rrcf WREG ;/2 -> 5-25 | 629 rrcf WREG ;/2 -> 5-25 |
573 addlw .126 ;131-151 | 630 decf WREG,W ;-1 |
631 decf WREG,W ;-1 | |
632 decf WREG,W ;-1 -> 2-22 | |
633 banksel analog_sw1 | |
634 addwf analog_sw1,W ; average (~128) | |
635 banksel common | |
574 cpfsgt ADRESH | 636 cpfsgt ADRESH |
575 bra get_analog_sw_done | 637 bra get_analog_sw_done |
576 sw1_pressed: | |
577 bsf analog_sw1_pressed | 638 bsf analog_sw1_pressed |
578 get_analog_sw_done: | 639 get_analog_sw_done: |
579 movlw b'10001101' ; Restore to right justified | 640 movlw b'10001101' ; Restore to right justified |
580 movwf ADCON2 | 641 movwf ADCON2 |
581 btfsc analog_sw1_pressed | 642 btfsc analog_sw1_pressed |