1 |
#include "main.h" |
1 |
#include "main.h" |
- |
|
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 |
|
2 |
#int_RB |
11 |
#int_RB |
3 |
void RB_isr(void) |
12 |
void RB_isr(void) |
4 |
{ |
13 |
{ |
- |
|
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); |
5 |
|
25 |
|
6 |
} |
26 |
} |
7 |
|
27 |
|
- |
|
28 |
#int_RTCC |
- |
|
29 |
void RTCC_isr(void) // preruseni od pretekleho casovace |
- |
|
30 |
{ |
- |
|
31 |
time++; |
- |
|
32 |
} |
- |
|
33 |
|
8 |
#define LCD_ENABLE_PIN PIN_E0 |
34 |
#define LCD_ENABLE_PIN PIN_E0 |
9 |
#define LCD_RS_PIN PIN_E1 |
35 |
#define LCD_RS_PIN PIN_E1 |
10 |
#define LCD_RW_PIN PIN_E2 |
36 |
#define LCD_RW_PIN PIN_E2 |
11 |
#define LCD_DATA4 PIN_D4 |
37 |
#define LCD_DATA4 PIN_D4 |
12 |
#define LCD_DATA5 PIN_D5 |
38 |
#define LCD_DATA5 PIN_D5 |
13 |
#define LCD_DATA6 PIN_D6 |
39 |
#define LCD_DATA6 PIN_D6 |
14 |
#define LCD_DATA7 PIN_D7 |
40 |
#define LCD_DATA7 PIN_D7 |
15 |
|
41 |
|
16 |
#include <lcd.c> |
42 |
#include <lcd.c> |
17 |
|
43 |
|
- |
|
44 |
#define BUTTON1 PIN_D0 |
- |
|
45 |
#define BUTTON2 PIN_D1 |
18 |
//#define USB_CON_SENSE_PIN PIN_B2 |
46 |
#define BUTTON3 PIN_D2 |
- |
|
47 |
#define BUTTON4 PIN_D3 |
- |
|
48 |
|
- |
|
49 |
#define BEEPER PIN_C0 |
- |
|
50 |
|
- |
|
51 |
unsigned int32 run; |
19 |
|
52 |
|
20 |
// Includes all USB code and interrupts, as well as the CDC API |
53 |
// Includes all USB code and interrupts, as well as the CDC API |
21 |
#include <usb_cdc.h> |
54 |
#include <usb_cdc.h> |
22 |
|
55 |
|
- |
|
56 |
void beep(int16 period) |
- |
|
57 |
{ |
- |
|
58 |
while(period){ |
23 |
#rom int 0xf00000={1,2,3,4} |
59 |
output_toggle(BEEPER); |
- |
|
60 |
delay_us(800); |
- |
|
61 |
period--; |
- |
|
62 |
} |
- |
|
63 |
} |
- |
|
64 |
|
- |
|
65 |
void test_mode() |
- |
|
66 |
{ |
- |
|
67 |
lcd_gotoxy(1,1); |
- |
|
68 |
printf(lcd_putc,"TEST MODE"); |
- |
|
69 |
} |
24 |
|
70 |
|
25 |
void main() { |
71 |
void main() { |
26 |
int i, j, address, value; |
- |
|
27 |
|
72 |
|
28 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
73 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
- |
|
74 |
port_b_pullups(TRUE); |
29 |
setup_adc(ADC_OFF); |
75 |
setup_adc(ADC_OFF); |
30 |
setup_psp(PSP_DISABLED); |
76 |
setup_psp(PSP_DISABLED); |
31 |
setup_spi(SPI_SS_DISABLED); |
77 |
setup_spi(SPI_SS_DISABLED); |
32 |
setup_wdt(WDT_OFF); |
78 |
setup_wdt(WDT_OFF); |
33 |
setup_timer_0(RTCC_INTERNAL); |
79 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16); |
34 |
setup_timer_1(T1_DISABLED); |
80 |
setup_timer_1(T1_DISABLED); |
35 |
setup_timer_2(T2_DISABLED,0,1); |
81 |
setup_timer_2(T2_DISABLED,0,1); |
36 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
82 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
37 |
setup_comparator(NC_NC_NC_NC); |
83 |
setup_comparator(NC_NC_NC_NC); |
38 |
setup_vref(FALSE); |
84 |
setup_vref(FALSE); |
39 |
// enable_interrupts(INT_RB); |
- |
|
40 |
enable_interrupts(GLOBAL); |
85 |
enable_interrupts(GLOBAL); |
41 |
|
86 |
|
42 |
usb_init(); |
- |
|
43 |
lcd_init(); |
87 |
lcd_init(); |
- |
|
88 |
usb_init(); |
44 |
|
89 |
|
45 |
lcd_gotoxy(1,1); |
90 |
lcd_gotoxy(1,1); |
46 |
printf(lcd_putc, "\fReady...\n"); |
91 |
printf(lcd_putc,"STOPWATCH01A"); |
- |
|
92 |
lcd_gotoxy(1,2); |
- |
|
93 |
printf(lcd_putc," Kaklik 2010 "); |
47 |
|
94 |
delay_ms(1000); |
48 |
while(!usb_cdc_connected()); |
95 |
lcd_gotoxy(1,1); |
- |
|
96 |
printf(lcd_putc,"\n Waiting for PC... "); |
49 |
|
97 |
|
- |
|
98 |
while(!usb_cdc_connected()); |
50 |
do { |
99 |
lcd_gotoxy(1,1); |
51 |
printf(usb_cdc_putc, "\r\n\nEEPROM:\r\n"); // Display contents of the first 64 |
100 |
printf(lcd_putc,"PC connected..."); |
- |
|
101 |
beep(10); |
- |
|
102 |
|
52 |
for(i=0; i<=3; ++i) { // bytes of the data EEPROM in hex |
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++; |
53 |
for(j=0; j<=15; ++j) { |
115 |
lcd_gotoxy(3,1); |
54 |
printf(usb_cdc_putc, "%2x ", read_eeprom( i*16+j ) ); |
116 |
printf(lcd_putc,"START"); |
- |
|
117 |
|
- |
|
118 |
while(input(BUTTON2)); |
55 |
} |
119 |
time = 0; |
- |
|
120 |
set_timer0(0); |
- |
|
121 |
position = 0; |
- |
|
122 |
state = RUNNING; |
56 |
printf(usb_cdc_putc, "\n\r"); |
123 |
clear_interrupt(int_timer0); |
- |
|
124 |
clear_interrupt(int_RB); |
- |
|
125 |
enable_interrupts(INT_RTCC); |
- |
|
126 |
enable_interrupts(INT_RB); |
57 |
} |
127 |
|
58 |
printf(usb_cdc_putc, "\r\nLocation to change: "); |
- |
|
59 |
address = gethex_usb(); |
128 |
lcd_gotoxy(6,1); |
60 |
printf(usb_cdc_putc, "\r\nNew value: "); |
129 |
printf(lcd_putc,"STOP"); |
61 |
value = gethex_usb(); |
130 |
while(state==RUNNING); |
62 |
|
131 |
|
63 |
write_eeprom( address, value ); |
- |
|
64 |
|
132 |
|
- |
|
133 |
printf(usb_cdc_putc, "\n\r %ld %ld %ld %ld %ld", run, section[0], section[1], section[2], section[3]); |
65 |
} while (TRUE); |
134 |
} |
66 |
} |
135 |
} |