1,6 → 1,8 |
#define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $" |
#include "main.h" |
#use i2c(SLAVE, Fast, sda=PIN_C4, scl=PIN_C3, force_hw, address=0xA2) |
|
#include <string.h> |
//#include <string.h> |
|
#define LED PIN_E1 |
#define CE PIN_E2 |
13,21 → 15,21 |
|
unsigned int32 count; |
|
const int8 buf_len=8; |
int8 buffer[buf_len]; // I2C buffer |
int8 address=0; |
|
int8 buffer[0x10]; // I2C buffer |
int8 address; |
|
unsigned int16 of=0; // count of overflow |
|
const char cmd[40]={0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x80, 0x84, 0x1E, 0x00, 0xE0, 0xC8, 0x10, 0x00, 0x40, 0x42, 0x0F, 0x00, 0xA0, 0x86, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7, 0x00, 0x00, 0x00, 0x12, 0x03}; |
|
|
#INT_SSP |
void ssp_interupt () |
{ |
BYTE incoming, state; |
BYTE incoming, state; |
|
state = i2c_isr_state(); |
|
if(state < 0x80) //Master is sending data |
{ |
incoming = i2c_read(); |
36,25 → 38,25 |
address = incoming; |
if (incoming == 2) |
{ |
buffer[0]=make8(count,0); |
buffer[1]=make8(count,1); |
buffer[2]=make8(count,2); |
buffer[3]=make8(count,3); |
} |
/* 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 |
buffer[address] = incoming; |
|
|
} |
if(state == 0x80) //Master is requesting data |
{ |
i2c_write(buffer[address]); |
if(address <= buf_len) i2c_write(buffer[address]); |
else i2c_write(ID[address - buf_len]); |
} |
} |
|
|
#int_EXT // Interrupt from 1PPS |
|
/*#int_EXT // Interrupt from 1PPS |
void EXT_isr(void) |
{ |
unsigned int16 countH; |
114,9 → 116,9 |
|
void main() |
{ |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
/* setup_adc_ports(NO_ANALOGS|VSS_VDD); |
setup_adc(ADC_OFF); |
setup_spi(SPI_SS_DISABLED); |
// setup_spi(SPI_SS_DISABLED); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
// setup_wdt(WDT_144MS); |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1); |
124,27 → 126,50 |
setup_ccp1(CCP_OFF); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
|
delay_ms(1000); |
|
*/ |
|
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
// setup_adc(ADC_CLOCK_DIV_2); |
setup_adc(ADC_OFF); |
// setup_spi(SPI_SS_DISABLED); //must not be set if I2C are in use! |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
// setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_144MS); |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT); |
// setup_timer_2(T2_DISABLED,0,1); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
// setup_oscillator(OSC_8MHZ|OSC_INTRC); |
|
// ext_int_edge( L_TO_H ); // set 1PPS active edge |
// enable_interrupts(INT_TIMER1); |
// enable_interrupts(INT_EXT); |
enable_interrupts(INT_SSP); |
// enable_interrupts(INT_TIMER2); |
enable_interrupts(GLOBAL); |
|
|
/* delay_ms(1000); |
int n; |
for (n=0;n<40;n++) putc(cmd[n]); // setup GPS |
|
*/ |
|
printf("cvak...\r\n"); |
|
ext_int_edge( L_TO_H ); // set 1PPS active edge |
enable_interrupts(INT_TIMER1); |
enable_interrupts(INT_EXT); |
enable_interrupts(INT_SSP); |
// enable_interrupts(INT_TIMER2); |
enable_interrupts(GLOBAL); |
|
buffer[2]=0; |
buffer[3]=0; |
buffer[4]=0; |
buffer[5]=0; |
|
while(true) |
{ |
/* output_high(LED); |
delay_ms(999); |
output_low(LED); |
delay_ms(999); |
// output_high(LED); |
delay_ms(1000); |
// output_low(LED); |
// delay_ms(999); |
printf("%X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]); |
*/ |
|
} |
} |