/Designs/Measuring_instruments/AWS01B/SW/PIC16F887/i2c_wind_sensor/main.c
10,8 → 10,6
//#include <stdlib.h>
//#include <input.c> //needed for the rs232 input routines
 
 
int16 count=0xA5A5;
const int8 buf_len=8;
 
int8 buffer[buf_len]; // I2C buffer
21,8 → 19,8
#include "..\common\dbloader.h"
 
unsigned int16 timer0_overflow_count;
float anemo=0;
unsigned int8 rain;
unsigned int16 anemo=0;
unsigned int16 rain=0;
 
//we are using the rtctimer.c library, in which a counter is incremented
//every time the timer2 interrupt occurs (timer2 overflow). the time math
44,8 → 42,10
address = incoming;
if (incoming == 2)
{
buffer[0]=make8(count,0);
buffer[1]=make8(count,1);
buffer[0]=make8(anemo,0);
buffer[1]=make8(anemo,1);
buffer[2]=make8(rain,0);
buffer[3]=make8(rain,1);
}
}
if(state == 2) //Second received byte is data
62,7 → 62,7
void TIMER1_isr(void)
{
// 32.768 kHz krystal pro timer1 oscilátor
anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(0xFFFF/32768.0); // pocet pulzu za 1s
anemo = ((timer0_overflow_count * 0xFF) + get_timer0()); // pocet pulzu za 1s
 
timer0_overflow_count=0; //nulovani
set_timer0(0);
173,7 → 173,6
set_timer0(0);
set_timer1(0);
timer0_overflow_count=0;
rain=0;
 
buffer[2]=0;
buffer[3]=0;
180,15 → 179,12
buffer[4]=0;
buffer[5]=0;
 
 
welcome();
 
set_timer1(0);
 
while(true)
{
printf("count: %X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]);
printf("%6.1f %u \n\r", anemo, rain);
printf("%Lu %Lu \n\r", anemo, rain);
delay_ms(1000);
 
/Designs/Measuring_instruments/AWS01B/SW/PIC16F887/i2c_wind_sensor/main.h
1,8 → 1,6
#include <16F887.h>
#device adc=8
 
 
 
//#FUSES WDT // Watch Dog Timer
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //external crystal oscillator
20,8 → 18,5
 
#use delay(clock=20000000)
 
//set I2C
//#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3)
 
//set RS232
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)