Rev 3458 Rev 3462
Line 1... Line 1...
1 #include "main.h" 1 #include "main.h"
2   2  
-   3 #include <string.h>
3   4  
4 #define LED PIN_E1 5 #define LED PIN_E1
5 #define CE PIN_E2 6 #define CE PIN_E2
6   7  
-   8 #define SEL0 PIN_E0 // external counter division ratio
-   9 #define SEL1 PIN_E1 // external counter division ratio
-   10 #define MR PIN_E2 // external counter master reset
-   11 #define CLKI PIN_C0 // internal counter input
-   12 #define BEEP PIN_C3 // buzzer
-   13  
7 int16 count; 14 unsigned int32 count;
8   15  
9 int8 rcv_buf[0x10]; // I2C receive buffer -  
10 int8 snd_buf[0x10]; // I2C send buffer -  
11   16  
12 int8 buffer[0x10]; // I2C buffer 17 int8 buffer[0x10]; // I2C buffer
13 int8 address; 18 int8 address;
14   19  
-   20 unsigned int16 of=0; // count of overflow
-   21  
15 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}; 22 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};
16   23  
17 #INT_SSP 24 #INT_SSP
18 void ssp_interupt () 25 void ssp_interupt ()
19 { 26 {
Line 29... Line 36...
29 address = incoming; 36 address = incoming;
30 if (incoming == 2) 37 if (incoming == 2)
31 { 38 {
32 buffer[0]=make8(count,0); 39 buffer[0]=make8(count,0);
33 buffer[1]=make8(count,1); 40 buffer[1]=make8(count,1);
-   41 buffer[2]=make8(count,2);
-   42 buffer[3]=make8(count,3);
34 } 43 }
35 } 44 }
36 if(state == 2) //Second received byte is data 45 if(state == 2) //Second received byte is data
37 buffer[address] = incoming; 46 buffer[address] = incoming;
38 47
Line 43... Line 52...
43 i2c_write(buffer[address]); 52 i2c_write(buffer[address]);
44 } 53 }
45 } 54 }
46   55  
47   56  
-   57 #int_EXT // Interrupt from 1PPS
-   58 void EXT_isr(void)
-   59 {
-   60 unsigned int16 countH;
-   61 unsigned int8 countL;
-   62 char countS[10], a[4], b[4], c[4]; // strings for printing results
-   63
-   64 countL=0;
-   65 countH=get_timer1(); // read internal counter
-   66 output_low(SEL0);
-   67 output_low(SEL1);
-   68 countL=input(CLKI); // read bit 0 of external counter
-   69 output_high(SEL0);
-   70 output_low(SEL1);
-   71 countL|=input(CLKI)<<1; // read bit 1 of external counter
-   72 output_low(SEL0);
-   73 output_high(SEL1);
-   74 countL|=input(CLKI)<<2; // read bit 2 of external counter
-   75 output_high(SEL0);
-   76 output_high(SEL1);
-   77 countL|=input(CLKI)<<3; // read bit 3 of external counter
-   78  
-   79 output_low(MR); // External counter Master Reset
-   80 output_high(MR);
-   81
-   82 set_timer1(0); // Internal counter reset
-   83
-   84 count=((unsigned int32)of<<20)+((unsigned int32)countH<<4)+(unsigned int32)countL; // concatenate
-   85  
-   86 sprintf(countS,"%09Lu", count); // engeneering values conversion
-   87 strncpy(a, countS, 3); a[3]='\0';
-   88 strncpy(b, &countS[3], 3); b[3]='\0';
-   89 strncpy(c, &countS[6], 3); c[3]='\0';
-   90
-   91 printf("%s\r\n", countS); // output to RS232
-   92  
-   93 output_toggle(BEEP); // cvak...
-   94  
-   95 of=0; // reset overflow counter
-   96 }
-   97  
-   98 #int_TIMER1 // Interrupf from overflow
-   99 void TIMER1_isr(void)
-   100 {
-   101 of++;
-   102 }
-   103  
-   104  
48 #int_TIMER2 // every 10 ms 105 /*#int_TIMER2 // every 10 ms
49 void TIMER2_isr(void) 106 void TIMER2_isr(void)
50 { 107 {
51 output_low(CE); 108 output_low(CE);
52 count=get_timer1(); 109 count=get_timer1();
53 set_timer1(0); 110 set_timer1(0);
54 output_high(CE); 111 output_high(CE);
55 } 112 }*/
56   113  
57 114
58 void main() 115 void main()
59 { 116 {
60 setup_adc_ports(NO_ANALOGS|VSS_VDD); 117 setup_adc_ports(NO_ANALOGS|VSS_VDD);
61 setup_adc(ADC_OFF); 118 setup_adc(ADC_OFF);
62 // setup_spi(SPI_SS_DISABLED); 119 setup_spi(SPI_SS_DISABLED);
63 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); 120 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
64 // setup_wdt(WDT_144MS); 121 // setup_wdt(WDT_144MS);
65 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1); 122 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
66 setup_timer_2(T2_DIV_BY_16,196,16); 123 setup_timer_2(T2_DIV_BY_16,196,16);
67 setup_ccp1(CCP_OFF); 124 setup_ccp1(CCP_OFF);
68 setup_comparator(NC_NC_NC_NC); 125 setup_comparator(NC_NC_NC_NC);
69 setup_vref(FALSE); 126 setup_vref(FALSE);
70 127
71 delay_ms(1000); 128 delay_ms(1000);
72 int n; 129 int n;
73 for (n=0;n<40;n++) 130 for (n=0;n<40;n++) putc(cmd[n]); // setup GPS
74 { -  
75 putc(cmd[n]); -  
76 } -  
77   131  
78 printf("cvak...\r\n"); 132 printf("cvak...\r\n");
79 // snd_buf[2]=0x55; -  
80 // snd_buf[3]=0xAA; -  
81 133
-   134 ext_int_edge( L_TO_H ); // set 1PPS active edge
-   135 enable_interrupts(INT_TIMER1);
82 set_timer1(0); 136 enable_interrupts(INT_EXT);
83 enable_interrupts(INT_SSP); 137 enable_interrupts(INT_SSP);
84 // enable_interrupts(INT_TIMER2); 138 // enable_interrupts(INT_TIMER2);
85 enable_interrupts(GLOBAL); 139 enable_interrupts(GLOBAL);
86   140  
87 while(true) 141 while(true)
88 { 142 {
89 -  
90 output_high(LED); 143 /* output_high(LED);
-   144 delay_ms(999);
91 output_low(LED); 145 output_low(LED);
92 set_timer1(0); -  
93 output_high(CE); -  
94 delay_ms(999); 146 delay_ms(999);
95 delay_us(966); -  
96 output_low(CE); -  
97 count=get_timer1(); -  
98 -  
99 printf("count: %Lu %X %X %X %X\r\n",count, buffer[0],buffer[1],buffer[2],buffer[3]); 147 printf("%X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]);
-   148 */
100 } 149 }
101 } 150 }