#include <16LF1825.h> #define use16F1825 #device adc=16 #use delay(internal=32MHz) #define debugRS232 #define LCDRS232 //#define CDlabo //#define altitude_reversed // ----------------------------------------------------------------- #define PCBVFull_1 // COMPACT EasyEDA alertPort to C2 altitudeMaxPort C4 //------------------------------------------------------------------ //#define PCBFullPlugable_1 // 17/11/2016 Full BMP180 in plugable alertPort moved to A2 for routing //#define PCBFullFullPlugable_1 //-------------------------------------------------------------------------------------------------------------- //#define PCBFullFullPlugable_2 // EASYEDA 22/11/2016 Full BMP180 in plugable alertPort moved to A2 for routing //-------------------------------------------------------------------------------------------------------------- #ifdef use18F13K22 #FUSES NOPCLKEN //Primary External Clock Disabled, Primary External Clock enabled in software #FUSES NOIESO //Internal External Switch Over mode disabled #FUSES PUT //Power Up Timer #FUSES NOBROWNOUT //No brownout reset #FUSES NOMCLR //Master Clear pin used for I/O #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O #FUSES NOXINST #endif #ifdef use16F1825 #FUSES NOMCLR //Master Clear pin used for I/O #FUSES PROTECT //Code protected from reads #FUSES NOBROWNOUT //No brownout reset #FUSES NOLVP #endif #ifdef PCBVFull_1 //#define YEL_LED PIN_A2 #define SCLPort PIN_C0 #define SDAPort PIN_C1 #define TXPort PIN_C3 #define RXPort PIN_C3 #define alertPort PIN_C2 #define altitudeMaxPort PIN_C4 #endif #ifdef PCBFullPlugable_1 // full-pulgable //#define YEL_LED PIN_C2 #define SCLPort PIN_C0 #define SDAPort PIN_C1 #define TXPort PIN_C3 #define RXPort PIN_C3 #define alertPort PIN_A2 #define altitudeMaxPort PIN_C4 #endif #ifdef PCBFullFullPlugable_1 // full-full-pulgable //#define YEL_LED PIN_C2 #define SCLPort PIN_C0 #define SDAPort PIN_C1 #define TXPort PIN_C3 #define RXPort PIN_C3 #define alertPort PIN_C4 #define altitudeMaxPort PIN_A2 #endif #ifdef PCBFullFullPlugable_2 // EasyEDA full-pulgable //#define YEL_LED PIN_C2 #define SCLPort PIN_C0 #define SDAPort PIN_C1 #define TXPort PIN_C3 #define RXPort PIN_C3 #define alertPort PIN_A2 #define altitudeMaxPort PIN_C4 #endif #ifdef debugRS232 #ifdef LCDRS232 #use rs232(baud=600, xmit=TXPort, rcv=TXPort, bits=8, parity=N, stop=1 ) #else #use rs232(ICD) #endif #endif #include "BMP180.h" #ifdef debugRS232 #ifdef LCDRS232 #include #endif #endif #ifndef altitude_reversed #define altitudeMax1 40 #define altitudeMax2 120 #else #define altitudeMax1 120 #define altitudeMax2 40 #endif //#ifdef PCBFullFullPlugable_1 // #define setAlert output_low( alertPort ) // #define noAlert output_high( alertPort ) //#else #define setAlert output_high( alertPort ) ; #define noAlert output_low( alertPort ) ; //#endif void alert() { setAlert delay_ms(150) ; noAlert delay_ms(650); } //---------------------------------------------- void main() //---------------------------------------------- { int8 i ; float T_Cent; float P_mBar, localMBar ; //int1 firstRead = true ; float altitude ; int8 altitudeMax = altitudeMax1 ; #ifdef PCBV1 port_c_pullups(0b010000) ; #endif #ifdef PCBV2 port_c_pullups(0b010000) ; #endif #ifdef PCBV3 port_c_pullups(0b010000) ; #endif #ifdef PCBVFull_1 port_c_pullups(0b010000) ; #endif #ifdef PCBFullPlugable_1 port_c_pullups(0b010000) ; #endif #ifdef PCBFullFullPlugable_1 port_a_pullups(0b00100) ; #endif #ifdef PCBFullFullPlugable_2 port_c_pullups(0b010000) ; #endif if ( !input( altitudeMaxPort ) ) altitudeMax = altitudeMax2 ; #ifdef debugRS232 #ifdef LCDRS232 startLcdRs232() ; //! delay_ms(100) ; //! printfstr( "U" ) ; // initialisation de la vitesse du port du LCD //! delay_ms(100) ; //! printf(LCDCLS) ; //! delay_ms(100) ; #endif #endif #ifdef debugRS232 printf("Buzzer") ; #endif #ifndef CDlabo //! for ( i = 0; i<4 ; i++ ) { //! alert(); //! } setAlert delay_ms(3000) ; noAlert //! for ( i = 0; i<4 ; i++ ) { //! alert(); //! } delay_ms(3000) ; setAlert delay_ms(3000) ; noAlert #endif #ifdef debugRS232 printf("wait....") ; #endif // calibration bmp085Calibration(); #ifdef debugRS232 delay_ms(100) ; #ifdef LCDRS232 printf(LCDCLS) ; delay_ms(100) ; #endif printf("Calib.ok") ; #endif // initialisation T_Cent = BMP085Temperature(); localMBar = BMP085Pressure(false); // skips required temp reading since already done above while(true) { T_Cent = BMP085Temperature(); P_mBar = BMP085Pressure(false); // skips required temp reading since already done above altitude = BMP085pressureToAltitude( localMBar, P_mBar ) ; #ifdef debugRS232 #ifdef LCDRS232 LCDL(1,0) ; #endif printf("%0.2g", P_mBar); #ifdef LCDRS232 LCDL(2,0) ; #endif printf("%3.2fm ", altitude); #endif altitudeMax = altitudeMax1 ; if ( !input( altitudeMaxPort ) ) altitudeMax = altitudeMax2 ; if ( altitude >= altitudeMax ) { setAlert } else { noAlert } delay_ms(100); } }