| Line 1... |
Line 1... |
| 1 |
#include "main.h" |
1 |
#include "main.h" |
| 2 |
|
2 |
|
| 3 |
unsigned int position; |
3 |
unsigned int position; |
| 4 |
unsigned int32 section[4]; |
4 |
unsigned int32 section[4]; |
| 5 |
unsigned int32 time; // pocitadlo preteceni casovace |
5 |
unsigned int32 time; // pocitadlo preteceni casovace |
| 6 |
unsigned int state; |
- |
|
| 7 |
|
6 |
|
| 8 |
#define RUNNING 1 |
- |
|
| 9 |
#define STOPPED 0 |
7 |
#Define INORDER 1 |
| 10 |
|
- |
|
| 11 |
#int_RB |
- |
|
| 12 |
void RB_isr(void) |
- |
|
| 13 |
{ |
- |
|
| 14 |
section[position]= get_timer0(); |
- |
|
| 15 |
time=0; |
- |
|
| 16 |
set_timer0(0); |
- |
|
| 17 |
if(position < 3) position++; |
- |
|
| 18 |
else { |
- |
|
| 19 |
disable_interrupts(INT_RB); |
- |
|
| 20 |
state = STOPPED; |
- |
|
| 21 |
} |
- |
|
| 22 |
|
- |
|
| 23 |
time=0; |
- |
|
| 24 |
set_timer0(0); |
- |
|
| 25 |
|
- |
|
| 26 |
} |
- |
|
| 27 |
|
8 |
|
| 28 |
#int_RTCC |
9 |
#int_RTCC |
| 29 |
void RTCC_isr(void) // preruseni od pretekleho casovace |
10 |
void RTCC_isr(void) // preruseni od pretekleho casovace |
| 30 |
{ |
11 |
{ |
| 31 |
time++; |
12 |
time++; |
| Line 60... |
Line 41... |
| 60 |
delay_us(800); |
41 |
delay_us(800); |
| 61 |
period--; |
42 |
period--; |
| 62 |
} |
43 |
} |
| 63 |
} |
44 |
} |
| 64 |
|
45 |
|
| 65 |
void test_mode() |
46 |
void test_mode() //Testovaci mod stopek |
| 66 |
{ |
47 |
{ |
| - |
|
48 |
printf(lcd_putc,"\f TEST MODE"); |
| 67 |
lcd_gotoxy(1,1); |
49 |
lcd_gotoxy(1,2); |
| 68 |
printf(lcd_putc,"\f TEST MODE"); |
50 |
printf(lcd_putc,"ESC"); |
| - |
|
51 |
while(input(BUTTON1)) // testuje dokud nekdo nezmackne tlacitlo |
| - |
|
52 |
{ |
| - |
|
53 |
lcd_gotoxy(5,2); |
| - |
|
54 |
Output_toggle(PIN_A0); |
| - |
|
55 |
delay_ms(100); |
| - |
|
56 |
printf(lcd_putc,"%d %d %d %d",bit_test(input_b(),0), bit_test(input_b(),1), bit_test(input_b(),2), bit_test(input_b(),3)); |
| - |
|
57 |
} |
| - |
|
58 |
} |
| - |
|
59 |
void send_measuring() |
| - |
|
60 |
{ |
| - |
|
61 |
printf(usb_cdc_putc, "\n\r %5ld %5ld %5ld %5ld %5ld", run, section[0]*0.000010667, section[1]*0.000010667, section[2]*0.000010667, section[3]*0.000010667); |
| 69 |
} |
62 |
} |
| 70 |
|
63 |
|
| - |
|
64 |
void exeption_inorder() |
| - |
|
65 |
{ |
| - |
|
66 |
} |
| - |
|
67 |
|
| 71 |
void main() { |
68 |
void main() |
| - |
|
69 |
{ |
| - |
|
70 |
unsigned int8 last, input; |
| - |
|
71 |
unsigned int16 timer; |
| - |
|
72 |
int exception; |
| 72 |
|
73 |
|
| 73 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
74 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
| 74 |
port_b_pullups(TRUE); |
75 |
port_b_pullups(TRUE); |
| 75 |
setup_adc(ADC_OFF); |
76 |
setup_adc(ADC_OFF); |
| 76 |
setup_psp(PSP_DISABLED); |
77 |
setup_psp(PSP_DISABLED); |
| 77 |
setup_spi(SPI_SS_DISABLED); |
78 |
setup_spi(SPI_SS_DISABLED); |
| 78 |
setup_wdt(WDT_OFF); |
79 |
setup_wdt(WDT_OFF); |
| 79 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16); |
80 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); |
| 80 |
setup_timer_1(T1_DISABLED); |
81 |
setup_timer_1(T1_DISABLED); |
| 81 |
setup_timer_2(T2_DISABLED,0,1); |
82 |
setup_timer_2(T2_DISABLED,0,1); |
| 82 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
83 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
| 83 |
setup_comparator(NC_NC_NC_NC); |
84 |
setup_comparator(NC_NC_NC_NC); |
| 84 |
setup_vref(FALSE); |
85 |
setup_vref(FALSE); |
| 85 |
enable_interrupts(GLOBAL); |
86 |
enable_interrupts(INT_TIMER0); |
| 86 |
|
87 |
|
| 87 |
lcd_init(); |
88 |
lcd_init(); |
| 88 |
usb_init(); |
89 |
usb_init(); |
| 89 |
|
90 |
|
| 90 |
lcd_gotoxy(1,1); |
91 |
lcd_gotoxy(1,1); |
| 91 |
printf(lcd_putc,"\f STOPWATCH01A"); |
92 |
printf(lcd_putc,"\f STOPWATCH01A"); |
| 92 |
lcd_gotoxy(1,2); |
93 |
lcd_gotoxy(1,2); |
| 93 |
printf(lcd_putc," Kaklik 2010 "); |
94 |
printf(lcd_putc," Kaklik 2010"); |
| 94 |
delay_ms(1000); |
95 |
delay_ms(1000); |
| 95 |
lcd_gotoxy(1,1); |
96 |
lcd_gotoxy(1,1); |
| 96 |
printf(lcd_putc,"\f Waiting for PC... "); |
97 |
printf(lcd_putc,"\f Waiting for PC... "); |
| - |
|
98 |
lcd_gotoxy(1,2); |
| - |
|
99 |
printf(lcd_putc,"TEST"); |
| 97 |
|
100 |
|
| 98 |
while(!usb_cdc_connected()); |
101 |
while(!usb_cdc_connected()) if(!input(BUTTON1)) test_mode(); |
| - |
|
102 |
|
| 99 |
lcd_gotoxy(1,1); |
103 |
lcd_gotoxy(1,1); |
| 100 |
printf(lcd_putc,"\f PC connected..."); |
104 |
printf(lcd_putc,"\f PC connected..."); |
| 101 |
beep(10); |
105 |
beep(10); |
| 102 |
|
106 |
|
| 103 |
if(!input(BUTTON1)) test_mode(); |
- |
|
| 104 |
run=0; |
107 |
run=0; |
| 105 |
|
- |
|
| 106 |
section[0]=0; |
- |
|
| 107 |
section[1]=0; |
- |
|
| 108 |
section[2]=0; |
- |
|
| 109 |
section[3]=0; |
- |
|
| 110 |
|
- |
|
| 111 |
|
- |
|
| 112 |
while (TRUE) |
108 |
while (TRUE) |
| 113 |
{ |
109 |
{ |
| 114 |
run++; |
110 |
run++; |
| - |
|
111 |
printf(lcd_putc,"\f\nSTART"); |
| - |
|
112 |
section[0]=0; |
| - |
|
113 |
section[1]=0; |
| - |
|
114 |
section[2]=0; |
| 115 |
lcd_gotoxy(3,1); |
115 |
section[3]=0; |
| 116 |
printf(lcd_putc,"\f START"); |
116 |
last!=input_b(); |
| 117 |
|
117 |
|
| 118 |
while(input(BUTTON2)); |
118 |
while(input(BUTTON1)); |
| - |
|
119 |
printf(lcd_putc,"\f\n STOP"); |
| 119 |
time = 0; |
120 |
time = 0; |
| 120 |
set_timer0(0); |
121 |
set_timer0(0); |
| - |
|
122 |
enable_interrupts(GLOBAL); |
| 121 |
position = 0; |
123 |
position = 0; |
| 122 |
state = RUNNING; |
124 |
exception = 0; |
| - |
|
125 |
|
| - |
|
126 |
while((position < 4) && (input(BUTTON2))) // cekame na tlacitko stop nebo na preruseni vsech paprsku |
| - |
|
127 |
{ |
| - |
|
128 |
if(last!=(input=input_b())) // pri preruseni nektereho z paprsku zjistime ktery to byl |
| - |
|
129 |
{ |
| 123 |
clear_interrupt(int_timer0); |
130 |
timer=get_timer0(); |
| - |
|
131 |
if(bit_test(last ^ input, position))section[position] = (time << 16) + timer; // kontroluje, jestli jsou paprsky preruseny ve spravnem poradi. |
| 124 |
clear_interrupt(int_RB); |
132 |
else exception=INORDER; |
| - |
|
133 |
time=0; |
| 125 |
enable_interrupts(INT_RTCC); |
134 |
set_timer0(0); |
| 126 |
enable_interrupts(INT_RB); |
135 |
position++; |
| 127 |
|
136 |
} |
| 128 |
lcd_gotoxy(6,1); |
137 |
last=input_b(); |
| - |
|
138 |
} |
| 129 |
printf(lcd_putc,"\f STOP"); |
139 |
if (exception == INORDER) exeption_inorder(); |
| 130 |
while(state==RUNNING); |
140 |
else send_measuring(); |
| 131 |
|
- |
|
| 132 |
|
- |
|
| 133 |
printf(usb_cdc_putc, "\n\r %ld %ld %ld %ld %ld", run, section[0], section[1], section[2], section[3]); |
- |
|
| 134 |
} |
141 |
} |
| 135 |
} |
142 |
} |