1 |
#include "main.h" |
1 |
#include "main.h" |
2 |
|
2 |
|
3 |
unsigned int32 section[4]; |
3 |
unsigned int32 section[4]; |
4 |
unsigned int32 time; // pocitadlo preteceni casovace |
4 |
unsigned int32 time; // pocitadlo preteceni casovace |
5 |
|
5 |
|
6 |
#Define INORDER 1 |
6 |
#Define INORDER 1 |
7 |
|
7 |
|
8 |
#int_RTCC |
8 |
#int_RTCC |
9 |
void RTCC_isr(void) // preruseni od pretekleho casovace |
9 |
void RTCC_isr(void) // preruseni od pretekleho casovace |
10 |
{ |
10 |
{ |
11 |
time++; |
11 |
time++; |
12 |
} |
12 |
} |
13 |
|
13 |
|
14 |
#define LCD_ENABLE_PIN PIN_E0 |
14 |
#define LCD_ENABLE_PIN PIN_E0 |
15 |
#define LCD_RS_PIN PIN_E1 |
15 |
#define LCD_RS_PIN PIN_E1 |
16 |
#define LCD_RW_PIN PIN_E2 |
16 |
#define LCD_RW_PIN PIN_E2 |
17 |
#define LCD_DATA4 PIN_D4 |
17 |
#define LCD_DATA4 PIN_D4 |
18 |
#define LCD_DATA5 PIN_D5 |
18 |
#define LCD_DATA5 PIN_D5 |
19 |
#define LCD_DATA6 PIN_D6 |
19 |
#define LCD_DATA6 PIN_D6 |
20 |
#define LCD_DATA7 PIN_D7 |
20 |
#define LCD_DATA7 PIN_D7 |
21 |
|
21 |
|
22 |
#include <lcd.c> |
22 |
#include <lcd.c> |
23 |
|
23 |
|
24 |
#define BUTTON1 PIN_D0 |
24 |
#define BUTTON1 PIN_D0 |
25 |
#define BUTTON2 PIN_D1 |
25 |
#define BUTTON2 PIN_D1 |
26 |
#define BUTTON3 PIN_D2 |
26 |
#define BUTTON3 PIN_D2 |
27 |
#define BUTTON4 PIN_D3 |
27 |
#define BUTTON4 PIN_D3 |
28 |
|
28 |
|
29 |
#define START1 PIN_B0 |
29 |
#define START1 PIN_B0 |
30 |
#define STOP1 PIN_B1 |
30 |
#define STOP1 PIN_B1 |
31 |
#define START2 PIN_B2 |
31 |
#define START2 PIN_B2 |
32 |
#define STOP2 PIN_B3 |
32 |
#define STOP2 PIN_B3 |
33 |
#define START3 PIN_B4 |
33 |
#define START3 PIN_B4 |
34 |
#define STOP3 PIN_B5 |
34 |
#define STOP3 PIN_B5 |
35 |
#define START4 PIN_B6 |
35 |
#define START4 PIN_B6 |
36 |
#define STOP4 PIN_B7 |
36 |
#define STOP4 PIN_B7 |
37 |
|
37 |
|
38 |
#define BEEPER PIN_C0 |
38 |
#define BEEPER PIN_C0 |
39 |
|
39 |
|
40 |
unsigned int32 run; |
40 |
unsigned int32 run; |
41 |
|
41 |
|
42 |
// Includes all USB code and interrupts, as well as the CDC API |
42 |
// Includes all USB code and interrupts, as well as the CDC API |
43 |
#include <usb_cdc.h> |
43 |
#include <usb_cdc.h> |
44 |
|
44 |
|
45 |
void beep(int16 period) |
45 |
void beep(int16 period) |
46 |
{ |
46 |
{ |
47 |
while(period){ |
47 |
while(period){ |
48 |
output_toggle(BEEPER); |
48 |
output_toggle(BEEPER); |
49 |
delay_us(800); |
49 |
delay_us(800); |
50 |
period--; |
50 |
period--; |
51 |
} |
51 |
} |
52 |
} |
52 |
} |
53 |
|
53 |
|
54 |
void test_mode() //Testovaci mod stopek |
- |
|
55 |
{ |
- |
|
56 |
printf(lcd_putc,"\f TEST MODE"); |
- |
|
57 |
lcd_gotoxy(1,2); |
- |
|
58 |
printf(lcd_putc,"ESC"); |
- |
|
59 |
while(input(BUTTON1)) // testuje dokud nekdo nezmackne tlacitlo |
- |
|
60 |
{ |
- |
|
61 |
lcd_gotoxy(5,2); |
- |
|
62 |
delay_ms(100); |
- |
|
63 |
printf(lcd_putc,"%x ",input_b()); |
- |
|
64 |
} |
- |
|
65 |
} |
- |
|
66 |
void send_measuring() |
- |
|
67 |
{ |
- |
|
68 |
printf(usb_cdc_putc, "\n\r %5lu %5lu %5lu %5lu %5lu", run, section[0], section[1], section[2], section[3]); |
- |
|
69 |
} //*0.000010667 |
- |
|
70 |
|
- |
|
71 |
void main() |
54 |
void main() |
72 |
{ |
55 |
{ |
73 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
56 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
74 |
port_b_pullups(TRUE); |
57 |
port_b_pullups(TRUE); |
75 |
setup_adc(ADC_OFF); |
58 |
setup_adc(ADC_OFF); |
76 |
setup_psp(PSP_DISABLED); |
59 |
setup_psp(PSP_DISABLED); |
77 |
setup_spi(SPI_SS_DISABLED); |
60 |
setup_spi(SPI_SS_DISABLED); |
78 |
setup_wdt(WDT_OFF); |
61 |
setup_wdt(WDT_OFF); |
79 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); |
62 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); |
80 |
setup_timer_1(T1_DISABLED); |
63 |
setup_timer_1(T1_DISABLED); |
81 |
setup_timer_2(T2_DISABLED,0,1); |
64 |
setup_timer_2(T2_DISABLED,0,1); |
82 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
65 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
83 |
setup_comparator(NC_NC_NC_NC); |
66 |
setup_comparator(NC_NC_NC_NC); |
84 |
setup_vref(FALSE); |
67 |
setup_vref(FALSE); |
85 |
enable_interrupts(INT_TIMER0); |
68 |
enable_interrupts(INT_TIMER0); |
86 |
enable_interrupts(GLOBAL); |
69 |
enable_interrupts(GLOBAL); |
87 |
|
70 |
|
88 |
lcd_init(); |
71 |
lcd_init(); |
89 |
usb_init(); |
72 |
usb_init(); |
90 |
|
73 |
|
91 |
lcd_gotoxy(1,1); |
74 |
lcd_gotoxy(1,1); |
92 |
printf(lcd_putc,"\f STOPWATCH01A"); |
75 |
printf(lcd_putc,"\f STOPWATCH01A"); |
93 |
lcd_gotoxy(1,2); |
76 |
lcd_gotoxy(1,2); |
94 |
printf(lcd_putc," Kaklik 2010"); |
77 |
printf(lcd_putc," Kaklik 2010"); |
95 |
delay_ms(1000); |
78 |
delay_ms(1000); |
96 |
lcd_gotoxy(1,1); |
- |
|
97 |
printf(lcd_putc,"\f Waiting for PC... "); |
- |
|
98 |
lcd_gotoxy(1,2); |
- |
|
99 |
printf(lcd_putc,"TEST"); |
- |
|
100 |
|
79 |
|
- |
|
80 |
while (TRUE) |
- |
|
81 |
{ |
- |
|
82 |
|
- |
|
83 |
printf(lcd_putc,"\fWaiting for PC... "); |
- |
|
84 |
lcd_gotoxy(1,2); |
- |
|
85 |
printf(lcd_putc,"sensors:"); |
101 |
while(!usb_cdc_connected()) if(!input(BUTTON1)) test_mode(); // pockej nez se pripoji seriovy port PC |
86 |
while(!usb_cdc_connected()) // pockej nez se pripoji seriovy port PC |
102 |
|
87 |
{ |
103 |
lcd_gotoxy(1,1); |
88 |
lcd_gotoxy(10,2); |
- |
|
89 |
printf(lcd_putc," %x",input_b()); |
- |
|
90 |
delay_ms(100); |
- |
|
91 |
} |
104 |
printf(lcd_putc,"\f PC connected..."); |
92 |
printf(lcd_putc,"\f PC connected..."); |
105 |
beep(10); |
93 |
beep(10); |
106 |
|
94 |
|
107 |
run=0; |
95 |
run=0; |
108 |
section[0] = 0; |
96 |
section[0] = 0; |
109 |
section[1] = 0; |
97 |
section[1] = 0; |
110 |
section[2] = 0; |
98 |
section[2] = 0; |
111 |
section[3] = 0; |
99 |
section[3] = 0; |
112 |
|
100 |
|
113 |
while (TRUE) |
101 |
while(usb_cdc_connected()) // pockej nez se pripoji seriovy port PC |
114 |
{ |
102 |
{ |
115 |
run++; |
103 |
run++; |
116 |
printf(lcd_putc,"\f\nSTART"); |
104 |
printf(lcd_putc,"\f\nSTART"); |
117 |
|
105 |
|
118 |
while(input(BUTTON1)); // ceka na zmacknuti startovaciho tlacitka |
106 |
while(input(BUTTON1)); // ceka na zmacknuti startovaciho tlacitka |
119 |
printf(lcd_putc,"\f\n STOP"); // |
107 |
printf(lcd_putc,"\f\n STOP"); // |
120 |
|
108 |
|
121 |
while((!input(START1)) && (input(BUTTON2))); // cekame na tlacitko stop nebo na preruseni paprsku |
109 |
while((!input(START1)) && (input(BUTTON2))); // cekame na tlacitko stop nebo na preruseni paprsku |
122 |
time = 0; |
110 |
time = 0; |
123 |
set_timer0(0); |
111 |
set_timer0(0); |
124 |
while((input(STOP1)) && (input(BUTTON2))) |
112 |
while((input(STOP1)) && (input(BUTTON2))) |
125 |
section[0] = (time << 16) + get_timer0(); |
113 |
section[0] = (time << 16) + get_timer0(); |
126 |
|
- |
|
127 |
send_measuring(); |
114 |
// odesli namerene hodnoty |
- |
|
115 |
printf(usb_cdc_putc, "\n\r %5lu %5.0f %5lu %5lu %5lu", run, section[0]/15.625, section[1], section[2], section[3]); |
128 |
} |
116 |
} |
- |
|
117 |
} |
129 |
} |
118 |
} |