Mercurial > public > hwos_code
comparison src/i2c.asm @ 467:6ca155fc1509
battery gauge handling
author | heinrichsweikamp |
---|---|
date | Sun, 20 Nov 2016 12:54:36 +0100 |
parents | 7f4c3b2e6bb7 |
children | e8351dd7bb90 |
comparison
equal
deleted
inserted
replaced
466:7f4c3b2e6bb7 | 467:6ca155fc1509 |
---|---|
640 | 640 |
641 global lt2942_init | 641 global lt2942_init |
642 lt2942_init: ; Setup Control register B | 642 lt2942_init: ; Setup Control register B |
643 clrf i2c_temp | 643 clrf i2c_temp |
644 movlw 0x01 ; Point to control reg B | 644 movlw 0x01 ; Point to control reg B |
645 call I2C_TX_GAUGE | 645 rcall I2C_TX_GAUGE |
646 movlw b'11111000' ; Automatic conversion every two seconds | 646 movlw b'11111000' ; Automatic conversion every two seconds |
647 movff WREG, SSP1BUF ; Data Byte | 647 movff WREG, SSP1BUF ; Data Byte |
648 rcall WaitMSSP | 648 rcall WaitMSSP |
649 rcall I2C_WaitforACK | 649 rcall I2C_WaitforACK |
650 bsf SSP1CON2,PEN ; Stop condition | 650 bsf SSP1CON2,PEN ; Stop condition |
651 rcall WaitMSSP | 651 bra WaitMSSP ; (And return) |
652 return | |
653 | 652 |
654 global lt2942_get_status | 653 global lt2942_get_status |
655 lt2942_get_status: ; Read status register | 654 lt2942_get_status: ; Read status register |
656 bcf battery_gauge_available ; Clear flag | 655 bcf battery_gauge_available ; Clear flag |
657 clrf i2c_temp | 656 clrf i2c_temp |
658 movlw 0x00 ; Point to Status reg | 657 movlw 0x00 ; Point to Status reg |
659 call I2C_TX_GAUGE | 658 rcall I2C_TX_GAUGE |
660 call I2C_RX_GAUGE | 659 rcall I2C_RX_GAUGE |
661 movff SSP1BUF,WREG | 660 movff SSP1BUF,WREG |
662 btfss WREG,7 ; 2942 found? | 661 btfss WREG,7 ; 2942 found? |
663 bsf battery_gauge_available ; Yes, set flag | 662 bsf battery_gauge_available ; Yes, set flag |
664 bsf SSP1CON2,PEN ; Stop condition | 663 bsf SSP1CON2,PEN ; Stop condition |
665 rcall WaitMSSP | 664 bra WaitMSSP ; (And return) |
666 return | |
667 | 665 |
668 | 666 |
669 global lt2942_get_voltage | 667 global lt2942_get_voltage |
670 lt2942_get_voltage: ; Read battery voltage registers | 668 lt2942_get_voltage: ; Read battery voltage registers |
671 clrf i2c_temp | 669 clrf i2c_temp |
761 | 759 |
762 global lt2942_get_accumulated_charge | 760 global lt2942_get_accumulated_charge |
763 lt2942_get_accumulated_charge: ; Read accumulated charge and compute percent | 761 lt2942_get_accumulated_charge: ; Read accumulated charge and compute percent |
764 clrf i2c_temp | 762 clrf i2c_temp |
765 movlw 0x00 ; Point to status register | 763 movlw 0x00 ; Point to status register |
766 call I2C_TX_GAUGE | 764 rcall I2C_TX_GAUGE |
767 call I2C_RX_GAUGE | 765 rcall I2C_RX_GAUGE |
768 bsf SSP1CON2,ACKEN ; Master acknowlegde | 766 bsf SSP1CON2,ACKEN ; Master acknowlegde |
769 rcall WaitMSSP | 767 rcall WaitMSSP |
770 movff SSP1BUF,gauge_status_byte | 768 movff SSP1BUF,gauge_status_byte |
771 | 769 |
772 bsf SSP1CON2, RCEN ; Enable recieve mode | 770 bsf SSP1CON2, RCEN ; Enable recieve mode |
773 rcall WaitMSSP ; Dummy read (Control byte) | 771 rcall WaitMSSP ; Dummy read (Control byte) |
772 movf SSP1BUF,W | |
773 bsf SSP1CON2,ACKEN ; Master acknowlegde | |
774 rcall WaitMSSP | |
774 | 775 |
775 bsf SSP1CON2, RCEN ; Enable recieve mode | 776 bsf SSP1CON2, RCEN ; Enable recieve mode |
776 rcall WaitMSSP | 777 rcall WaitMSSP |
777 movff SSP1BUF,sub_a+1 | 778 movff SSP1BUF,sub_a+1 |
779 bsf SSP1CON2,ACKEN ; Master acknowlegde | |
780 rcall WaitMSSP | |
778 | 781 |
779 bsf SSP1CON2, RCEN ; Enable recieve mode | 782 bsf SSP1CON2, RCEN ; Enable recieve mode |
780 rcall WaitMSSP | 783 rcall WaitMSSP |
781 movff SSP1BUF,sub_a+0 | 784 movff SSP1BUF,sub_a+0 |
782 bsf SSP1CON2,PEN ; Stop condition | 785 bsf SSP1CON2,PEN ; Stop condition |
852 rcall WaitMSSP | 855 rcall WaitMSSP |
853 movlw b'11001001' ; Address byte + Read bit | 856 movlw b'11001001' ; Address byte + Read bit |
854 movwf SSP1BUF ; control byte | 857 movwf SSP1BUF ; control byte |
855 rcall WaitMSSP | 858 rcall WaitMSSP |
856 rcall I2C_WaitforACK | 859 rcall I2C_WaitforACK |
857 bsf SSP1CON2, RCEN ; Enable recieve mode | 860 bsf SSP1CON2, RCEN ; Enable recieve mode |
858 bra WaitMSSP; (and return) | 861 bra WaitMSSP; (and return) |
859 | 862 |
860 END | 863 END |