looking for that one ???
AlainCode:Making all these decisions and calculations was the hard bit (honest)... the easy bit is the programming... ' ' Program BatLo ' ============ ' Embedded Software Version 1.00 ' Target Processor PIC16F628-04/P ' Target PCB BB-001 ' Created 09/04/02 ' Last Updated 09/04/02 ' Written by Melanie Newman ' ' Melanies very complicated Battery Low Indicator ' ' ' Device Programming Options ' -------------------------- @ DEVICE pic16F628, INTRC_OSC_NOCLKOUT ' System Clock Options @ DEVICE pic16F628, WDT_ON ' Watchdog Timer @ DEVICE pic16F628, PWRT_ON ' Power-On Timer @ DEVICE pic16F628, MCLR_OFF ' Master Clear Options (Internal) @ DEVICE pic16F628, BOD_ON ' Brown-Out Detect @ DEVICE pic16F628, LVP_OFF ' Low-Voltage Programming @ DEVICE pic16F628, CPD_OFF ' Data Memory Code Protect @ DEVICE pic16F628, PROTECT_OFF ' Program Code Protection ' ' Hardware Assignments ' -------------------- BatVal var CMCON.7 ' Read Comparator 2 for Battery Low ' Port RA1 has +VBatt Input BatLoLED var PORTB.7 ' Port for Battery Low LED ' ' Start Program ' ============ ' ' Setup Hardware ' -------------- ' ' Comparator Control ' ------------------ CMCON=%00100101 ' CM7 C2OUT Comparator Output 2 (Read Only) ' CM6 C1OUT Comparator Output 1 (Read Only) ' CM5 C2INV Comparator 2 Output Inversion ' the way I'm driving my LED I need inversion ' so C2OUT goes Low when Battery is Low ' CM4 C1INV Comparator 1 Output Inversion ' CM3 Comparator Input Switch ' not relevant for Comparator Mode 101 ' CM2 ) refer to Datasheet figure 9-1 ' CM1 ) Mode 101 for Single Comparator C2 ' CM0 ) Comparator C1 Disabled ' ' Voltage Reference Control ' ------------------------- VRCON=%11101100 ' 7 VREN Voltage Reference Enable (1=on) ' 6 VRON VREF Output Enable ' 1=Connects output of VREF to RA2 ' This is real convenient so we'll use it ' 5 VRR VREF Range Selection (1=Low Range) ' 4 Unused (0) ' VR3 ) ' VR2 ) Set for Reference Voltage ' VR1 ) 1100 sets 2.5v in Low Range ' VR0 ) ' Pauseus 10 ' Delay to allow for VREF to settle ' see datasheet section 11-1 ' ' And the Usual Stuff ' ------------------- TRISA=%11111111 ' Set All Inputs TRISB=%00000000 ' Set All Outputs ' ' Actual Program ' -------------- BatLoLoop: BatLoLED=BatVal ' You better believe it... just ONE line of code! Goto BatLoLoop ' End




Bookmarks