Line 2... |
Line 2... |
2 |
#define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $" |
2 |
#define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $" |
3 |
|
3 |
|
4 |
#include "main.h" |
4 |
#include "main.h" |
5 |
#use i2c(SLAVE,Fast,sda=PIN_C4,scl=PIN_C3,force_hw,address=0xA2) // Motor 2 |
5 |
#use i2c(SLAVE,Fast,sda=PIN_C4,scl=PIN_C3,force_hw,address=0xA2) // Motor 2 |
6 |
|
6 |
|
7 |
#include <time.h> //standard C time library |
7 |
//#include <time.h> //standard C time library |
8 |
#include <rtctimer.c> //library for time.h that uses timer2 as time base |
8 |
//#include <rtctimer.c> //library for time.h that uses timer2 as time base |
9 |
|
9 |
|
10 |
#include <stdlib.h> |
10 |
//#include <stdlib.h> |
11 |
#include <input.c> //needed for the rs232 input routines |
11 |
//#include <input.c> //needed for the rs232 input routines |
12 |
|
12 |
|
13 |
|
13 |
|
14 |
int16 count=0xA5A5; |
14 |
int16 count=0xA5A5; |
15 |
const int8 buf_len=8; |
15 |
const int8 buf_len=8; |
16 |
|
16 |
|
Line 68... |
Line 68... |
68 |
set_timer0(0); |
68 |
set_timer0(0); |
69 |
set_timer1(0); |
69 |
set_timer1(0); |
70 |
output_toggle(PIN_E0); |
70 |
output_toggle(PIN_E0); |
71 |
} |
71 |
} |
72 |
|
72 |
|
73 |
#int_TIMER0 //pro preteceni \u010díta\u010de p\u016flz\u016f od anemometru (RA4) |
73 |
#int_TIMER0 //osetruje preteceni citace od anemometru (RA4) |
74 |
void TIMER0_isr(void) |
74 |
void TIMER0_isr(void) |
75 |
{ |
75 |
{ |
76 |
timer0_overflow_count++; |
76 |
timer0_overflow_count++; |
77 |
} |
77 |
} |
78 |
|
78 |
|
Line 91... |
Line 91... |
91 |
printf("\r\n %s \r\n",ID);// Welcome message |
91 |
printf("\r\n %s \r\n",ID);// Welcome message |
92 |
printf("# ver poradi "); |
92 |
printf("# ver poradi "); |
93 |
printf("check\r\n\r\n"); |
93 |
printf("check\r\n\r\n"); |
94 |
} |
94 |
} |
95 |
|
95 |
|
96 |
void InitTime(void) |
96 |
/*void InitTime(void) |
97 |
{ |
97 |
{ |
98 |
struct_tm t; |
98 |
struct_tm t; |
99 |
|
99 |
|
100 |
//tm_year is years since 1900. |
100 |
//tm_year is years since 1900. |
101 |
printf("\r\nYear (0-99): "); |
101 |
printf("\r\nYear (0-99): "); |
Line 115... |
Line 115... |
115 |
|
115 |
|
116 |
SetTime(&t); |
116 |
SetTime(&t); |
117 |
|
117 |
|
118 |
printf("\r\n\n"); |
118 |
printf("\r\n\n"); |
119 |
} |
119 |
} |
120 |
|
120 |
*/ |
121 |
|
121 |
|
122 |
void main() |
122 |
void main() |
123 |
{ |
123 |
{ |
124 |
|
124 |
|
125 |
char tString[32]; |
125 |
// char tString[32]; |
126 |
unsigned int32 t; |
126 |
// unsigned int32 t; |
127 |
time_t tTime = 0; |
127 |
// time_t tTime = 0; |
128 |
|
128 |
|
129 |
|
129 |
|
130 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
130 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
131 |
// setup_adc(ADC_CLOCK_DIV_2); |
131 |
// setup_adc(ADC_CLOCK_DIV_2); |
132 |
setup_adc(ADC_OFF); |
132 |
setup_adc(ADC_OFF); |
Line 138... |
Line 138... |
138 |
setup_comparator(NC_NC_NC_NC); |
138 |
setup_comparator(NC_NC_NC_NC); |
139 |
setup_vref(FALSE); |
139 |
setup_vref(FALSE); |
140 |
// setup_oscillator(OSC_8MHZ|OSC_INTRC); |
140 |
// setup_oscillator(OSC_8MHZ|OSC_INTRC); |
141 |
|
141 |
|
142 |
|
142 |
|
143 |
InitTime(); |
143 |
// InitTime(); |
144 |
|
144 |
|
145 |
/* Setup timer 2 |
145 |
/* Setup timer 2 |
146 |
* On a 4 Mhz clock, this will trigger a timer2 interrupt every 1.0 ms |
146 |
* On a 4 Mhz clock, this will trigger a timer2 interrupt every 1.0 ms |
147 |
* For time.h to work properly, Timer2 must overflow every millisecond |
147 |
* For time.h to work properly, Timer2 must overflow every millisecond |
148 |
* OverflowTime = 4 * (1/OscFrequency) * Prescale * Period * Postscale |
148 |
* OverflowTime = 4 * (1/OscFrequency) * Prescale * Period * Postscale |
149 |
* For 4 Mhz: .001 seconds = 4 * (1/4000000 seconds) * 4 * 250 * 1 |
149 |
* For 4 Mhz: .001 seconds = 4 * (1/4000000 seconds) * 4 * 250 * 1 |
150 |
*/ |
150 |
*/ |
151 |
#if getenv("CLOCK")==4000000) |
151 |
/* #if getenv("CLOCK")==4000000) |
152 |
setup_timer_2(T2_DIV_BY_1,250,4); |
152 |
setup_timer_2(T2_DIV_BY_1,250,4); |
153 |
#elif getenv("CLOCK")==20000000) |
153 |
#elif getenv("CLOCK")==20000000) |
154 |
setup_timer_2(T2_DIV_BY_4,250,5); |
154 |
setup_timer_2(T2_DIV_BY_4,250,5); |
155 |
#else |
155 |
#else |
156 |
#error Configure TIMER2 so it interrupts at a rate defined by CLOCKS_PER_SECOND |
156 |
#error Configure TIMER2 so it interrupts at a rate defined by CLOCKS_PER_SECOND |
157 |
#endif |
157 |
#endif |
158 |
|
158 |
|
159 |
/* Enable the timer 2 interrupt, or it will not fire */ |
159 |
/* Enable the timer 2 interrupt, or it will not fire */ |
160 |
enable_interrupts(INT_TIMER2); |
160 |
// enable_interrupts(INT_TIMER2); |
161 |
/* Enable interrupts globally too, otherwise no interrupt will fire */ |
161 |
/* Enable interrupts globally too, otherwise no interrupt will fire */ |
162 |
|
162 |
|
163 |
|
163 |
|
164 |
|
164 |
|
165 |
enable_interrupts(INT_SSP); |
165 |
enable_interrupts(INT_SSP); |
Line 184... |
Line 184... |
184 |
welcome(); |
184 |
welcome(); |
185 |
|
185 |
|
186 |
set_timer1(0); |
186 |
set_timer1(0); |
187 |
|
187 |
|
188 |
while(true) |
188 |
while(true) |
189 |
{ |
- |
|
190 |
|
189 |
{ |
191 |
set_timer1(0); |
- |
|
192 |
delay_ms(999); |
- |
|
193 |
delay_us(966); |
- |
|
194 |
// count=get_timer1(); |
- |
|
195 |
// Get the time |
- |
|
196 |
tTime = time(NULL); |
- |
|
197 |
// Get the string representation of the time */ |
- |
|
198 |
|
- |
|
199 |
ctime(&tTime, tString); |
- |
|
200 |
|
- |
|
201 |
|
- |
|
202 |
/* Print the time to RS-232 */ |
- |
|
203 |
printf("Time: %s\n\r", tString); |
- |
|
204 |
|
- |
|
205 |
printf("count: %Lu %X %X %X %X\r\n",count, buffer[0],buffer[1],buffer[2],buffer[3]); |
190 |
printf("count: %X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]); |
206 |
printf("%6.1f %u \n\r", anemo, rain); |
191 |
printf("%6.1f %u \n\r", anemo, rain); |
207 |
|
192 |
|
208 |
delay_ms(1000); |
193 |
delay_ms(1000); |
209 |
|
194 |
|
210 |
} |
195 |
} |