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