o: ActiveSupport::Cache::Entry :@compressedF: @value"Y"Y
main.c
1
#define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $"
1 2
#include "main.h"
3
#use i2c(SLAVE, Fast, sda=PIN_C4, scl=PIN_C3, force_hw, address=0xA2) 
2 4

  
3
#include <string.h>
5
//#include <string.h>
4 6

  
5 7
#define LED PIN_E1  
6 8
#define CE  PIN_E2
......
13 15

  
14 16
unsigned int32 count;
15 17

  
18
const int8 buf_len=8;
19
int8 buffer[buf_len];   // I2C buffer     
20
int8 address=0;
16 21

  
17
int8 buffer[0x10];   // I2C buffer     
18
int8 address;
19

  
20 22
unsigned int16 of=0; // count of overflow
21 23

  
22 24
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};
23 25

  
26

  
24 27
#INT_SSP
25 28
void ssp_interupt ()
26 29
{
27
   BYTE incoming, state;
30
BYTE incoming, state;
28 31

  
29 32
   state = i2c_isr_state();
30
   
31 33
   if(state < 0x80)                     //Master is sending data
32 34
   {
33 35
      incoming = i2c_read();
......
36 38
         address = incoming;
37 39
         if (incoming == 2)
38 40
         {
39
            buffer[0]=make8(count,0);
40
            buffer[1]=make8(count,1);
41
            buffer[2]=make8(count,2);
42
            buffer[3]=make8(count,3);
43
         }
41
/*            buffer[0]=make8(anemo,0);
42
            buffer[1]=make8(anemo,1);
43
            buffer[2]=make8(rain,0);
44
            buffer[3]=make8(rain,1);
45
*/         }
44 46
      }
45 47
      if(state == 2)                     //Second received byte is data
46 48
         buffer[address] = incoming;
47
         
48
      
49 49
   }
50 50
   if(state == 0x80)                     //Master is requesting data
51 51
   {
52
      i2c_write(buffer[address]);
52
      if(address <= buf_len) i2c_write(buffer[address]);
53
      else i2c_write(ID[address - buf_len]);
53 54
   }
54 55
}
55 56

  
56 57

  
57
#int_EXT  // Interrupt from 1PPS
58

  
59
/*#int_EXT  // Interrupt from 1PPS
58 60
void  EXT_isr(void) 
59 61
{
60 62
   unsigned int16 countH;
......
114 116
 
115 117
void main()
116 118
{
117
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
119
/*   setup_adc_ports(NO_ANALOGS|VSS_VDD);
118 120
   setup_adc(ADC_OFF);
119
   setup_spi(SPI_SS_DISABLED);
121
//   setup_spi(SPI_SS_DISABLED);
120 122
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
121 123
//   setup_wdt(WDT_144MS);
122 124
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
......
124 126
   setup_ccp1(CCP_OFF);
125 127
   setup_comparator(NC_NC_NC_NC);
126 128
   setup_vref(FALSE);
127
   
128
   delay_ms(1000);
129

  
130
*/
131

  
132
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
133
//   setup_adc(ADC_CLOCK_DIV_2);
134
   setup_adc(ADC_OFF);
135
//   setup_spi(SPI_SS_DISABLED);  //must not be set if I2C are in use! 
136
   setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
137
//   setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_144MS);
138
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
139
//   setup_timer_2(T2_DISABLED,0,1);
140
   setup_comparator(NC_NC_NC_NC);
141
   setup_vref(FALSE);
142
//   setup_oscillator(OSC_8MHZ|OSC_INTRC);
143

  
144
//   ext_int_edge( L_TO_H );       // set 1PPS active edge
145
//   enable_interrupts(INT_TIMER1);
146
//   enable_interrupts(INT_EXT);
147
   enable_interrupts(INT_SSP); 
148
//   enable_interrupts(INT_TIMER2);
149
   enable_interrupts(GLOBAL);    
150

  
151

  
152
/*   delay_ms(1000);
129 153
   int n;
130 154
   for (n=0;n<40;n++) putc(cmd[n]); // setup GPS
131 155

  
156
*/
157

  
132 158
   printf("cvak...\r\n");
133 159
   
134
   ext_int_edge( L_TO_H );       // set 1PPS active edge
135
   enable_interrupts(INT_TIMER1);
136
   enable_interrupts(INT_EXT);
137
   enable_interrupts(INT_SSP); 
138
//   enable_interrupts(INT_TIMER2);
139
   enable_interrupts(GLOBAL);    
140 160

  
161
buffer[2]=0;
162
buffer[3]=0;
163
buffer[4]=0;
164
buffer[5]=0;
165

  
141 166
   while(true)
142 167
   {      
143
/*     output_high(LED);
144
     delay_ms(999);
145
     output_low(LED);
146
     delay_ms(999);
168
//     output_high(LED);
169
     delay_ms(1000);
170
//     output_low(LED);
171
//     delay_ms(999);
147 172
     printf("%X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]);
148
*/
173

  
149 174
   }
150 175
}
:@created_atf1425171150.457818Lä:@expires_in0