Rev Author Line No. Line
1383 kaklik 1 #include "main.h"
1423 kaklik 2  
3 unsigned int position;
4 unsigned int32 section[4];
5 unsigned int32 time; // pocitadlo preteceni casovace
6 unsigned int state;
7  
8 #define RUNNING 1
9 #define STOPPED 0
10  
1383 kaklik 11 #int_RB
12 void RB_isr(void)
13 {
1423 kaklik 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);
1383 kaklik 25  
26 }
27  
1423 kaklik 28 #int_RTCC
29 void RTCC_isr(void) // preruseni od pretekleho casovace
30 {
31 time++;
32 }
33  
1383 kaklik 34 #define LCD_ENABLE_PIN PIN_E0
35 #define LCD_RS_PIN PIN_E1
36 #define LCD_RW_PIN PIN_E2
37 #define LCD_DATA4 PIN_D4
38 #define LCD_DATA5 PIN_D5
39 #define LCD_DATA6 PIN_D6
40 #define LCD_DATA7 PIN_D7
41  
42 #include <lcd.c>
43  
1423 kaklik 44 #define BUTTON1 PIN_D0
45 #define BUTTON2 PIN_D1
46 #define BUTTON3 PIN_D2
47 #define BUTTON4 PIN_D3
1383 kaklik 48  
1423 kaklik 49 #define BEEPER PIN_C0
50  
51 unsigned int32 run;
52  
1383 kaklik 53 // Includes all USB code and interrupts, as well as the CDC API
54 #include <usb_cdc.h>
55  
1423 kaklik 56 void beep(int16 period)
57 {
58 while(period){
59 output_toggle(BEEPER);
60 delay_us(800);
61 period--;
62 }
63 }
1383 kaklik 64  
1423 kaklik 65 void test_mode()
66 {
67 lcd_gotoxy(1,1);
1424 kaklik 68 printf(lcd_putc,"\f TEST MODE");
1423 kaklik 69 }
70  
1383 kaklik 71 void main() {
72  
73 setup_adc_ports(NO_ANALOGS|VSS_VDD);
1423 kaklik 74 port_b_pullups(TRUE);
1383 kaklik 75 setup_adc(ADC_OFF);
76 setup_psp(PSP_DISABLED);
77 setup_spi(SPI_SS_DISABLED);
78 setup_wdt(WDT_OFF);
1423 kaklik 79 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
1383 kaklik 80 setup_timer_1(T1_DISABLED);
81 setup_timer_2(T2_DISABLED,0,1);
82 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
83 setup_comparator(NC_NC_NC_NC);
84 setup_vref(FALSE);
85 enable_interrupts(GLOBAL);
86  
1423 kaklik 87 lcd_init();
1383 kaklik 88 usb_init();
89  
90 lcd_gotoxy(1,1);
1424 kaklik 91 printf(lcd_putc,"\f STOPWATCH01A");
1423 kaklik 92 lcd_gotoxy(1,2);
93 printf(lcd_putc," Kaklik 2010 ");
94 delay_ms(1000);
95 lcd_gotoxy(1,1);
1424 kaklik 96 printf(lcd_putc,"\f Waiting for PC... ");
1423 kaklik 97  
98 while(!usb_cdc_connected());
99 lcd_gotoxy(1,1);
1424 kaklik 100 printf(lcd_putc,"\f PC connected...");
1423 kaklik 101 beep(10);
1383 kaklik 102  
1423 kaklik 103 if(!input(BUTTON1)) test_mode();
104 run=0;
105  
106 section[0]=0;
107 section[1]=0;
108 section[2]=0;
109 section[3]=0;
110  
111  
112 while (TRUE)
113 {
114 run++;
115 lcd_gotoxy(3,1);
1424 kaklik 116 printf(lcd_putc,"\f START");
1383 kaklik 117  
1423 kaklik 118 while(input(BUTTON2));
119 time = 0;
120 set_timer0(0);
121 position = 0;
122 state = RUNNING;
123 clear_interrupt(int_timer0);
124 clear_interrupt(int_RB);
125 enable_interrupts(INT_RTCC);
126 enable_interrupts(INT_RB);
127  
128 lcd_gotoxy(6,1);
1424 kaklik 129 printf(lcd_putc,"\f STOP");
1423 kaklik 130 while(state==RUNNING);
1383 kaklik 131  
132  
1423 kaklik 133 printf(usb_cdc_putc, "\n\r %ld %ld %ld %ld %ld", run, section[0], section[1], section[2], section[3]);
134 }
1383 kaklik 135 }