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