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 |
|
6 |
|
7 |
#Define INORDER 1 |
7 |
#Define INORDER 1 |
8 |
|
8 |
|
9 |
#int_RTCC |
9 |
#int_RTCC |
10 |
void RTCC_isr(void) // preruseni od pretekleho casovace |
10 |
void RTCC_isr(void) // preruseni od pretekleho casovace |
11 |
{ |
11 |
{ |
12 |
time++; |
12 |
time++; |
13 |
} |
13 |
} |
14 |
|
14 |
|
15 |
#define LCD_ENABLE_PIN PIN_E0 |
15 |
#define LCD_ENABLE_PIN PIN_E0 |
16 |
#define LCD_RS_PIN PIN_E1 |
16 |
#define LCD_RS_PIN PIN_E1 |
17 |
#define LCD_RW_PIN PIN_E2 |
17 |
#define LCD_RW_PIN PIN_E2 |
18 |
#define LCD_DATA4 PIN_D4 |
18 |
#define LCD_DATA4 PIN_D4 |
19 |
#define LCD_DATA5 PIN_D5 |
19 |
#define LCD_DATA5 PIN_D5 |
20 |
#define LCD_DATA6 PIN_D6 |
20 |
#define LCD_DATA6 PIN_D6 |
21 |
#define LCD_DATA7 PIN_D7 |
21 |
#define LCD_DATA7 PIN_D7 |
22 |
|
22 |
|
23 |
#include <lcd.c> |
23 |
#include <lcd.c> |
24 |
|
24 |
|
25 |
#define BUTTON1 PIN_D0 |
25 |
#define BUTTON1 PIN_D0 |
26 |
#define BUTTON2 PIN_D1 |
26 |
#define BUTTON2 PIN_D1 |
27 |
#define BUTTON3 PIN_D2 |
27 |
#define BUTTON3 PIN_D2 |
28 |
#define BUTTON4 PIN_D3 |
28 |
#define BUTTON4 PIN_D3 |
29 |
|
29 |
|
30 |
#define BEEPER PIN_C0 |
30 |
#define BEEPER PIN_C0 |
31 |
|
31 |
|
32 |
unsigned int32 run; |
32 |
unsigned int32 run; |
33 |
|
33 |
|
34 |
// Includes all USB code and interrupts, as well as the CDC API |
34 |
// Includes all USB code and interrupts, as well as the CDC API |
35 |
#include <usb_cdc.h> |
35 |
#include <usb_cdc.h> |
36 |
|
36 |
|
37 |
void beep(int16 period) |
37 |
void beep(int16 period) |
38 |
{ |
38 |
{ |
39 |
while(period){ |
39 |
while(period){ |
40 |
output_toggle(BEEPER); |
40 |
output_toggle(BEEPER); |
41 |
delay_us(800); |
41 |
delay_us(800); |
42 |
period--; |
42 |
period--; |
43 |
} |
43 |
} |
44 |
} |
44 |
} |
45 |
|
45 |
|
46 |
void test_mode() //Testovaci mod stopek |
46 |
void test_mode() //Testovaci mod stopek |
47 |
{ |
47 |
{ |
48 |
printf(lcd_putc,"\f TEST MODE"); |
48 |
printf(lcd_putc,"\f TEST MODE"); |
49 |
lcd_gotoxy(1,2); |
49 |
lcd_gotoxy(1,2); |
50 |
printf(lcd_putc,"ESC"); |
50 |
printf(lcd_putc,"ESC"); |
51 |
while(input(BUTTON1)) // testuje dokud nekdo nezmackne tlacitlo |
51 |
while(input(BUTTON1)) // testuje dokud nekdo nezmackne tlacitlo |
52 |
{ |
52 |
{ |
53 |
lcd_gotoxy(5,2); |
53 |
lcd_gotoxy(5,2); |
54 |
Output_toggle(PIN_A0); |
54 |
Output_toggle(PIN_A0); |
55 |
delay_ms(100); |
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)); |
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 |
} |
57 |
} |
58 |
} |
58 |
} |
59 |
void send_measuring() |
59 |
void send_measuring() |
60 |
{ |
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); |
61 |
printf(usb_cdc_putc, "\n\r %5u %5u %5u %5u %5u", run, section[0], section[1], section[2], section[3]); |
62 |
} |
- |
|
63 |
|
- |
|
64 |
void exeption_inorder() |
62 |
} //*0.000010667 |
65 |
{ |
- |
|
66 |
} |
- |
|
67 |
|
63 |
|
68 |
void main() |
64 |
void main() |
69 |
{ |
65 |
{ |
70 |
unsigned int8 last, input; |
66 |
unsigned int8 last, input; |
71 |
unsigned int16 timer; |
67 |
unsigned int16 timer; |
72 |
int exception; |
68 |
int exception; |
73 |
|
69 |
|
74 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
70 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
75 |
port_b_pullups(TRUE); |
71 |
port_b_pullups(TRUE); |
76 |
setup_adc(ADC_OFF); |
72 |
setup_adc(ADC_OFF); |
77 |
setup_psp(PSP_DISABLED); |
73 |
setup_psp(PSP_DISABLED); |
78 |
setup_spi(SPI_SS_DISABLED); |
74 |
setup_spi(SPI_SS_DISABLED); |
79 |
setup_wdt(WDT_OFF); |
75 |
setup_wdt(WDT_OFF); |
80 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); |
76 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); |
81 |
setup_timer_1(T1_DISABLED); |
77 |
setup_timer_1(T1_DISABLED); |
82 |
setup_timer_2(T2_DISABLED,0,1); |
78 |
setup_timer_2(T2_DISABLED,0,1); |
83 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
79 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
84 |
setup_comparator(NC_NC_NC_NC); |
80 |
setup_comparator(NC_NC_NC_NC); |
85 |
setup_vref(FALSE); |
81 |
setup_vref(FALSE); |
86 |
enable_interrupts(INT_TIMER0); |
82 |
enable_interrupts(INT_TIMER0); |
- |
|
83 |
enable_interrupts(GLOBAL); |
87 |
|
84 |
|
88 |
lcd_init(); |
85 |
lcd_init(); |
89 |
usb_init(); |
86 |
usb_init(); |
90 |
|
87 |
|
91 |
lcd_gotoxy(1,1); |
88 |
lcd_gotoxy(1,1); |
92 |
printf(lcd_putc,"\f STOPWATCH01A"); |
89 |
printf(lcd_putc,"\f STOPWATCH01A"); |
93 |
lcd_gotoxy(1,2); |
90 |
lcd_gotoxy(1,2); |
94 |
printf(lcd_putc," Kaklik 2010"); |
91 |
printf(lcd_putc," Kaklik 2010"); |
95 |
delay_ms(1000); |
92 |
delay_ms(1000); |
96 |
lcd_gotoxy(1,1); |
93 |
lcd_gotoxy(1,1); |
97 |
printf(lcd_putc,"\f Waiting for PC... "); |
94 |
printf(lcd_putc,"\f Waiting for PC... "); |
98 |
lcd_gotoxy(1,2); |
95 |
lcd_gotoxy(1,2); |
99 |
printf(lcd_putc,"TEST"); |
96 |
printf(lcd_putc,"TEST"); |
100 |
|
97 |
|
101 |
while(!usb_cdc_connected()) if(!input(BUTTON1)) test_mode(); |
98 |
while(!usb_cdc_connected()) if(!input(BUTTON1)) test_mode(); |
102 |
|
99 |
|
103 |
lcd_gotoxy(1,1); |
100 |
lcd_gotoxy(1,1); |
104 |
printf(lcd_putc,"\f PC connected..."); |
101 |
printf(lcd_putc,"\f PC connected..."); |
105 |
beep(10); |
102 |
beep(10); |
106 |
|
103 |
|
107 |
run=0; |
104 |
run=0; |
108 |
while (TRUE) |
105 |
while (TRUE) |
109 |
{ |
106 |
{ |
110 |
run++; |
107 |
run++; |
111 |
printf(lcd_putc,"\f\nSTART"); |
108 |
printf(lcd_putc,"\f\nSTART"); |
112 |
section[0]=0; |
109 |
section[0]=0; |
113 |
section[1]=0; |
110 |
section[1]=0; |
114 |
section[2]=0; |
111 |
section[2]=0; |
115 |
section[3]=0; |
112 |
section[3]=0; |
116 |
last!=input_b(); |
113 |
last!=input_b(); |
117 |
|
114 |
|
118 |
while(input(BUTTON1)); |
115 |
while(input(BUTTON1)); |
119 |
printf(lcd_putc,"\f\n STOP"); |
116 |
printf(lcd_putc,"\f\n STOP"); |
120 |
time = 0; |
117 |
time = 0; |
121 |
set_timer0(0); |
118 |
set_timer0(0); |
122 |
enable_interrupts(GLOBAL); |
- |
|
123 |
position = 0; |
119 |
position = 0; |
124 |
exception = 0; |
120 |
exception = 0; |
125 |
|
121 |
|
126 |
while((position < 4) && (input(BUTTON2))) // cekame na tlacitko stop nebo na preruseni vsech paprsku |
122 |
while((position < 4) && (input(BUTTON2))) // cekame na tlacitko stop nebo na preruseni vsech paprsku |
127 |
{ |
123 |
{ |
128 |
if(last!=(input=input_b())) // pri preruseni nektereho z paprsku zjistime ktery to byl |
124 |
if(last!=(input=input_b())) // pri preruseni nektereho z paprsku zjistime ktery to byl |
129 |
{ |
125 |
{ |
130 |
timer=get_timer0(); |
126 |
timer=get_timer0(); |
131 |
if(bit_test(last ^ input, position))section[position] = (time << 16) + timer; // kontroluje, jestli jsou paprsky preruseny ve spravnem poradi. |
127 |
if(bit_test(last ^ input, position))section[position] = (time << 16) + timer; // kontroluje, jestli jsou paprsky preruseny ve spravnem poradi. |
132 |
else exception=INORDER; |
128 |
else exception=INORDER; |
133 |
time=0; |
129 |
time=0; |
134 |
set_timer0(0); |
130 |
set_timer0(0); |
135 |
position++; |
131 |
position++; |
136 |
} |
132 |
} |
137 |
last=input_b(); |
133 |
last=input_b(); |
138 |
} |
134 |
} |
139 |
if (exception == INORDER) exeption_inorder(); |
135 |
if (exception == INORDER) |
- |
|
136 |
{ |
- |
|
137 |
printf(lcd_putc,"\fInorder! Send?"); |
- |
|
138 |
lcd_gotoxy(1,2); |
- |
|
139 |
printf(lcd_putc,"YES NO"); |
- |
|
140 |
While(input(BUTTON1) && input(BUTTON4)); |
- |
|
141 |
if(!input(BUTTON1)) send_measuring(); |
- |
|
142 |
if(!input(BUTTON4)) continue; |
- |
|
143 |
} |
140 |
else send_measuring(); |
144 |
else send_measuring(); |
141 |
} |
145 |
} |
142 |
} |
146 |
} |