/Designs/Measuring_instruments/RMDS02C/SW/PIC16F887/main.c
22,19 → 22,24
 
unsigned int32 count; // count per second
 
int1 fire_setup; // flag for sending setup to GPS
 
#define BUF_LEN 4
int8 buffer[BUF_LEN]; // I2C buffer
int8 address=0;
 
unsigned int16 of=0; // count of overflow
 
// 1x 100 us per 10 s UTC synchronised; 40 configuration bytes
char cmd[50]={40, 0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x80, 0x96, 0x98, 0x00, 0xE0, 0xC8, 0x10, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0xC6, 0x51};
 
// configure GPS
void setup_GPS()
{
// 1x 100 us per 10 s UTC synchronised
const char cmd[40]={0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x80, 0x96, 0x98, 0x00, 0xE0, 0xC8, 0x10, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0xC6, 0x51};
int n;
for (n=0;n<40;n++) putc(cmd[n]);
int len;
len=cmd[0];
for (n=1;n<=len;n++) putc(cmd[n]);
}
 
#INT_SSP
52,6 → 57,18
{
address = incoming;
}
 
if(state == 2) //Thid received byte are configuration data
{
if ((address==0)&&(incoming==0))
{
fire_setup = 1; // Write configuration to the GPS if configuration data length is 0
}
else
{
cmd[address] = incoming; // Store byte to configuration sentence
}
}
}
if(state == 0x80) //Master is requesting data
{
64,9 → 81,12
buffer[2]=make8(count,2);
buffer[3]=make8(count,3);
}
if(address <= BUF_LEN) i2c_write(buffer[address]); // Prepare one byte to SSP buffer
else
if(address <= BUF_LEN)
{
i2c_write(buffer[address]); // Prepare one byte to SSP buffer
}
else
{
i2c_write(0x00); // There is nothing to prepare, so zero
}
}
81,9 → 101,7
}
if(state == 0x83) //Master is requesting data
{
i2c_write(buffer[3]); // Prepare next byte to SSP buffer
setup_GPS();
i2c_write(buffer[3]); // Prepare next byte to SSP buffer
}
 
if(state > 0x83) //Master is requesting data
163,13 → 181,20
buffer[2]=0x0;
buffer[3]=0x0;
 
printf("\r\ncvak...\r\n");
//printf("\r\ncvak...\r\n");
fire_setup = 0;
 
while(true)
{
restart_wdt();
delay_ms(1500);
// printf("%X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]);
printf("%010Lu\r\n", count);
delay_ms(1000);
if (fire_setup)
{
setup_GPS(); // Write configuration to the GPS
fire_setup = 0;
}
//printf("%X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]);
//printf("%010Lu\r\n", count);
}
}