/Designs/Measuring_instruments/AWS01A/SW/PIC16F887/main.c/main.c
20,6 → 20,25
#define CSN_SPI PIN_C2 // preassure sensor connection
#include "..\MPL115A1.c"
 
unsigned int16 timer0_overflow_count=0;
float anemo=0;
 
 
#int_TIMER1
void TIMER1_isr(void)
{
output_toggle(PIN_D1);
anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF);
}
 
#int_TIMER0
void TIMER0_isr(void)
{
timer0_overflow_count++;
}
 
 
 
void welcome(void) // Welcome message
{
char REV[50]=ID; // Buffer for concatenate of a version string
45,14 → 64,20
 
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard
setup_oscillator(OSC_8MHZ);
setup_wdt(WDT_1152MS|WDT_DIV_16);
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);
output_high(CSN_SPI);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
 
 
delay_ms(100);
 
welcome();
95,6 → 120,8
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%5.1f \0", barometer_pressure);
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%3.1f \0", anemo);
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"*%X\r\n\0", check);
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); }
delay_us(SEND_DELAY);