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 |
- |
|
8 |
//#include <rtctimer.c> //library for time.h that uses timer2 as time base |
- |
|
9 |
|
- |
|
10 |
//#include <stdlib.h> |
- |
|
11 |
//#include <input.c> //needed for the rs232 input routines |
- |
|
12 |
|
- |
|
13 |
const int8 buf_len=8; |
7 |
const int8 buf_len=8; |
14 |
|
8 |
|
15 |
int8 buffer[buf_len]; // I2C buffer |
9 |
int8 buffer[buf_len]; // I2C buffer |
16 |
|
10 |
|
17 |
int8 address=0; |
11 |
int8 address=0; |
Line 56... |
Line 50... |
56 |
if(address <= buf_len) i2c_write(buffer[address]); |
50 |
if(address <= buf_len) i2c_write(buffer[address]); |
57 |
else i2c_write(ID[address - buf_len]); |
51 |
else i2c_write(ID[address - buf_len]); |
58 |
} |
52 |
} |
59 |
} |
53 |
} |
60 |
|
54 |
|
- |
|
55 |
|
- |
|
56 |
#int_TIMER0 //osetruje preteceni citace od anemometru (RA4) |
- |
|
57 |
void TIMER0_isr(void) |
- |
|
58 |
{ |
- |
|
59 |
timer0_overflow_count++; |
- |
|
60 |
} |
- |
|
61 |
|
61 |
#int_TIMER1 |
62 |
#int_TIMER1 |
62 |
void TIMER1_isr(void) |
63 |
void TIMER1_isr(void) |
63 |
{ |
64 |
{ |
64 |
// 32.768 kHz krystal pro timer1 oscilátor |
65 |
// 32.768 kHz krystal pro timer1 oscilátor |
65 |
anemo = ((timer0_overflow_count * 0xFF) + get_timer0()); // pocet pulzu za 1s |
66 |
anemo = ((timer0_overflow_count * 0xFF) + get_timer0()); // pocet pulzu za 1s |
Line 68... |
Line 69... |
68 |
set_timer0(0); |
69 |
set_timer0(0); |
69 |
set_timer1(0); |
70 |
set_timer1(0); |
70 |
output_toggle(PIN_E0); |
71 |
output_toggle(PIN_E0); |
71 |
} |
72 |
} |
72 |
|
73 |
|
73 |
#int_TIMER0 //osetruje preteceni citace od anemometru (RA4) |
74 |
#int_TIMER2 |
74 |
void TIMER0_isr(void) |
75 |
void TIMER2_isr(void) |
75 |
{ |
76 |
{ |
76 |
timer0_overflow_count++; |
- |
|
- |
|
77 |
|
77 |
} |
78 |
} |
78 |
|
79 |
|
79 |
#INT_EXT |
80 |
#INT_EXT |
80 |
void EXT_isr() //interrup from rain sensor clip. |
81 |
void EXT_isr() //interrup from rain sensor clip. |
81 |
{ |
82 |
{ |
Line 91... |
Line 92... |
91 |
printf("\r\n %s \r\n",ID);// Welcome message |
92 |
printf("\r\n %s \r\n",ID);// Welcome message |
92 |
printf("# ver poradi "); |
93 |
printf("# ver poradi "); |
93 |
printf("check\r\n\r\n"); |
94 |
printf("check\r\n\r\n"); |
94 |
} |
95 |
} |
95 |
|
96 |
|
96 |
/*void InitTime(void) |
- |
|
97 |
{ |
- |
|
98 |
struct_tm t; |
- |
|
99 |
|
- |
|
100 |
//tm_year is years since 1900. |
- |
|
101 |
printf("\r\nYear (0-99): "); |
- |
|
102 |
t.tm_year = (int16)get_int() + (int16)100; //add 100 to put is into 2000 |
- |
|
103 |
|
- |
|
104 |
printf("\r\nMonth (1-12): "); |
- |
|
105 |
t.tm_mon = get_int() - 1; |
- |
|
106 |
|
- |
|
107 |
printf("\r\nDay (1-31): "); |
- |
|
108 |
t.tm_mday = get_int() - 1; |
- |
|
109 |
|
- |
|
110 |
printf("\r\nHour (0-23): "); |
- |
|
111 |
t.tm_hour = get_int(); |
- |
|
112 |
|
- |
|
113 |
printf("\r\nMinute (0-59): "); |
- |
|
114 |
t.tm_min = get_int(); |
- |
|
115 |
|
- |
|
116 |
SetTime(&t); |
- |
|
117 |
|
- |
|
118 |
printf("\r\n\n"); |
- |
|
119 |
} |
- |
|
120 |
*/ |
- |
|
121 |
|
- |
|
122 |
void main() |
97 |
void main() |
123 |
{ |
98 |
{ |
124 |
|
- |
|
125 |
// char tString[32]; |
- |
|
126 |
// unsigned int32 t; |
- |
|
127 |
// time_t tTime = 0; |
- |
|
128 |
|
- |
|
129 |
|
- |
|
130 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
99 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
131 |
// setup_adc(ADC_CLOCK_DIV_2); |
100 |
// setup_adc(ADC_CLOCK_DIV_2); |
132 |
setup_adc(ADC_OFF); |
101 |
setup_adc(ADC_OFF); |
133 |
// setup_spi(SPI_SS_DISABLED); //must not be set if I2C are in use! |
102 |
// setup_spi(SPI_SS_DISABLED); //must not be set if I2C are in use! |
134 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
103 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
Line 138... |
Line 107... |
138 |
setup_comparator(NC_NC_NC_NC); |
107 |
setup_comparator(NC_NC_NC_NC); |
139 |
setup_vref(FALSE); |
108 |
setup_vref(FALSE); |
140 |
// setup_oscillator(OSC_8MHZ|OSC_INTRC); |
109 |
// setup_oscillator(OSC_8MHZ|OSC_INTRC); |
141 |
|
110 |
|
142 |
|
111 |
|
143 |
// InitTime(); |
- |
|
144 |
|
- |
|
145 |
/* Setup timer 2 |
112 |
/* Setup timer 2 |
146 |
* On a 4 Mhz clock, this will trigger a timer2 interrupt every 1.0 ms |
113 |
* 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 |
114 |
* For time.h to work properly, Timer2 must overflow every millisecond |
148 |
* OverflowTime = 4 * (1/OscFrequency) * Prescale * Period * Postscale |
115 |
* OverflowTime = 4 * (1/OscFrequency) * Prescale * Period * Postscale |
149 |
* For 4 Mhz: .001 seconds = 4 * (1/4000000 seconds) * 4 * 250 * 1 |
116 |
* For 4 Mhz: .001 seconds = 4 * (1/4000000 seconds) * 4 * 250 * 1 |
150 |
*/ |
117 |
*/ |
151 |
/* #if getenv("CLOCK")==4000000) |
118 |
#if getenv("CLOCK")==4000000) |
152 |
setup_timer_2(T2_DIV_BY_1,250,4); |
119 |
setup_timer_2(T2_DIV_BY_1,250,4); |
153 |
#elif getenv("CLOCK")==20000000) |
120 |
#elif getenv("CLOCK")==20000000) |
154 |
setup_timer_2(T2_DIV_BY_4,250,5); |
121 |
setup_timer_2(T2_DIV_BY_4,250,5); |
155 |
#else |
122 |
#else |
156 |
#error Configure TIMER2 so it interrupts at a rate defined by CLOCKS_PER_SECOND |
123 |
#error Configure TIMER2 so it interrupts at a rate defined by CLOCKS_PER_SECOND |
157 |
#endif |
124 |
#endif |
158 |
|
125 |
|
159 |
/* Enable the timer 2 interrupt, or it will not fire */ |
- |
|
160 |
// enable_interrupts(INT_TIMER2); |
- |
|
161 |
/* Enable interrupts globally too, otherwise no interrupt will fire */ |
- |
|
162 |
|
- |
|
163 |
|
- |
|
164 |
|
126 |
|
165 |
enable_interrupts(INT_SSP); |
127 |
enable_interrupts(INT_SSP); |
166 |
// enable_interrupts(INT_TIMER2); |
128 |
enable_interrupts(INT_TIMER2); |
167 |
enable_interrupts(INT_TIMER1); |
129 |
enable_interrupts(INT_TIMER1); |
168 |
enable_interrupts(INT_TIMER0); |
130 |
enable_interrupts(INT_TIMER0); |
169 |
enable_interrupts(INT_EXT); |
131 |
enable_interrupts(INT_EXT); |
170 |
enable_interrupts(GLOBAL); |
132 |
enable_interrupts(GLOBAL); |
171 |
|
133 |
|