3,28 → 3,9 |
unsigned int position; |
unsigned int32 section[4]; |
unsigned int32 time; // pocitadlo preteceni casovace |
unsigned int state; |
|
#define RUNNING 1 |
#define STOPPED 0 |
#Define INORDER 1 |
|
#int_RB |
void RB_isr(void) |
{ |
section[position]= get_timer0(); |
time=0; |
set_timer0(0); |
if(position < 3) position++; |
else { |
disable_interrupts(INT_RB); |
state = STOPPED; |
} |
|
time=0; |
set_timer0(0); |
|
} |
|
#int_RTCC |
void RTCC_isr(void) // preruseni od pretekleho casovace |
{ |
62,14 → 43,34 |
} |
} |
|
void test_mode() |
void test_mode() //Testovaci mod stopek |
{ |
lcd_gotoxy(1,1); |
printf(lcd_putc,"\f TEST MODE"); |
lcd_gotoxy(1,2); |
printf(lcd_putc,"ESC"); |
while(input(BUTTON1)) // testuje dokud nekdo nezmackne tlacitlo |
{ |
lcd_gotoxy(5,2); |
Output_toggle(PIN_A0); |
delay_ms(100); |
printf(lcd_putc,"%d %d %d %d",bit_test(input_b(),0), bit_test(input_b(),1), bit_test(input_b(),2), bit_test(input_b(),3)); |
} |
} |
void send_measuring() |
{ |
printf(usb_cdc_putc, "\n\r %5ld %5ld %5ld %5ld %5ld", run, section[0]*0.000010667, section[1]*0.000010667, section[2]*0.000010667, section[3]*0.000010667); |
} |
|
void main() { |
void exeption_inorder() |
{ |
} |
|
void main() |
{ |
unsigned int8 last, input; |
unsigned int16 timer; |
int exception; |
|
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
port_b_pullups(TRUE); |
setup_adc(ADC_OFF); |
76,13 → 77,13 |
setup_psp(PSP_DISABLED); |
setup_spi(SPI_SS_DISABLED); |
setup_wdt(WDT_OFF); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); |
setup_timer_1(T1_DISABLED); |
setup_timer_2(T2_DISABLED,0,1); |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
enable_interrupts(GLOBAL); |
enable_interrupts(INT_TIMER0); |
|
lcd_init(); |
usb_init(); |
94,42 → 95,48 |
delay_ms(1000); |
lcd_gotoxy(1,1); |
printf(lcd_putc,"\f Waiting for PC... "); |
lcd_gotoxy(1,2); |
printf(lcd_putc,"TEST"); |
|
while(!usb_cdc_connected()); |
while(!usb_cdc_connected()) if(!input(BUTTON1)) test_mode(); |
|
lcd_gotoxy(1,1); |
printf(lcd_putc,"\f PC connected..."); |
beep(10); |
|
if(!input(BUTTON1)) test_mode(); |
run=0; |
|
while (TRUE) |
{ |
run++; |
printf(lcd_putc,"\f\nSTART"); |
section[0]=0; |
section[1]=0; |
section[2]=0; |
section[3]=0; |
last!=input_b(); |
|
while(input(BUTTON1)); |
printf(lcd_putc,"\f\n STOP"); |
time = 0; |
set_timer0(0); |
enable_interrupts(GLOBAL); |
position = 0; |
exception = 0; |
|
while (TRUE) |
while((position < 4) && (input(BUTTON2))) // cekame na tlacitko stop nebo na preruseni vsech paprsku |
{ |
run++; |
lcd_gotoxy(3,1); |
printf(lcd_putc,"\f START"); |
|
while(input(BUTTON2)); |
if(last!=(input=input_b())) // pri preruseni nektereho z paprsku zjistime ktery to byl |
{ |
timer=get_timer0(); |
if(bit_test(last ^ input, position))section[position] = (time << 16) + timer; // kontroluje, jestli jsou paprsky preruseny ve spravnem poradi. |
else exception=INORDER; |
time = 0; |
set_timer0(0); |
position = 0; |
state = RUNNING; |
clear_interrupt(int_timer0); |
clear_interrupt(int_RB); |
enable_interrupts(INT_RTCC); |
enable_interrupts(INT_RB); |
|
lcd_gotoxy(6,1); |
printf(lcd_putc,"\f STOP"); |
while(state==RUNNING); |
|
|
printf(usb_cdc_putc, "\n\r %ld %ld %ld %ld %ld", run, section[0], section[1], section[2], section[3]); |
position++; |
} |
last=input_b(); |
} |
if (exception == INORDER) exeption_inorder(); |
else send_measuring(); |
} |
} |