/Designs/Measuring_instruments/AWS01B/SW/PIC16F887/i2c_wind_sensor/main.c
4,12 → 4,6
#include "main.h"
#use i2c(SLAVE,Fast,sda=PIN_C4,scl=PIN_C3,force_hw,address=0xA2) // Motor 2
 
//#include <time.h> //standard C time library
//#include <rtctimer.c> //library for time.h that uses timer2 as time base
 
//#include <stdlib.h>
//#include <input.c> //needed for the rs232 input routines
 
const int8 buf_len=8;
 
int8 buffer[buf_len]; // I2C buffer
58,6 → 52,13
}
}
 
 
#int_TIMER0 //osetruje preteceni citace od anemometru (RA4)
void TIMER0_isr(void)
{
timer0_overflow_count++;
}
 
#int_TIMER1
void TIMER1_isr(void)
{
70,10 → 71,10
output_toggle(PIN_E0);
}
 
#int_TIMER0 //osetruje preteceni citace od anemometru (RA4)
void TIMER0_isr(void)
#int_TIMER2
void TIMER2_isr(void)
{
timer0_overflow_count++;
 
}
 
#INT_EXT
93,40 → 94,8
printf("check\r\n\r\n");
}
 
/*void InitTime(void)
{
struct_tm t;
//tm_year is years since 1900.
printf("\r\nYear (0-99): ");
t.tm_year = (int16)get_int() + (int16)100; //add 100 to put is into 2000
printf("\r\nMonth (1-12): ");
t.tm_mon = get_int() - 1;
printf("\r\nDay (1-31): ");
t.tm_mday = get_int() - 1;
printf("\r\nHour (0-23): ");
t.tm_hour = get_int();
printf("\r\nMinute (0-59): ");
t.tm_min = get_int();
SetTime(&t);
printf("\r\n\n");
}
*/
 
void main()
{
 
// char tString[32];
// unsigned int32 t;
// time_t tTime = 0;
 
 
setup_adc_ports(NO_ANALOGS|VSS_VDD);
// setup_adc(ADC_CLOCK_DIV_2);
setup_adc(ADC_OFF);
140,8 → 109,6
// setup_oscillator(OSC_8MHZ|OSC_INTRC);
 
 
// InitTime();
 
/* Setup timer 2
* On a 4 Mhz clock, this will trigger a timer2 interrupt every 1.0 ms
* For time.h to work properly, Timer2 must overflow every millisecond
148,7 → 115,7
* OverflowTime = 4 * (1/OscFrequency) * Prescale * Period * Postscale
* For 4 Mhz: .001 seconds = 4 * (1/4000000 seconds) * 4 * 250 * 1
*/
/* #if getenv("CLOCK")==4000000)
#if getenv("CLOCK")==4000000)
setup_timer_2(T2_DIV_BY_1,250,4);
#elif getenv("CLOCK")==20000000)
setup_timer_2(T2_DIV_BY_4,250,5);
156,14 → 123,9
#error Configure TIMER2 so it interrupts at a rate defined by CLOCKS_PER_SECOND
#endif
/* Enable the timer 2 interrupt, or it will not fire */
// enable_interrupts(INT_TIMER2);
/* Enable interrupts globally too, otherwise no interrupt will fire */
 
 
 
enable_interrupts(INT_SSP);
// enable_interrupts(INT_TIMER2);
enable_interrupts(INT_TIMER2);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_EXT);